@n8n/chat 0.6.0 → 0.7.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 (41) hide show
  1. package/.eslintrc.cjs +0 -41
  2. package/README.md +27 -4
  3. package/build.config.js +21 -0
  4. package/package.json +8 -4
  5. package/resources/images/fullscreen.png +0 -0
  6. package/resources/images/windowed.png +0 -0
  7. package/resources/workflow-manual.json +238 -0
  8. package/resources/workflow.json +38 -212
  9. package/scripts/postbuild.js +20 -0
  10. package/src/App.vue +2 -2
  11. package/src/__stories__/App.stories.ts +3 -3
  12. package/src/__tests__/index.spec.ts +12 -17
  13. package/src/__tests__/utils/create.ts +1 -1
  14. package/src/__tests__/utils/fetch.ts +1 -1
  15. package/src/__tests__/utils/selectors.ts +1 -1
  16. package/src/api/generic.ts +5 -6
  17. package/src/api/message.ts +11 -5
  18. package/src/components/Chat.vue +19 -15
  19. package/src/components/ChatWindow.vue +3 -3
  20. package/src/components/GetStarted.vue +2 -2
  21. package/src/components/GetStartedFooter.vue +2 -2
  22. package/src/components/Input.vue +1 -1
  23. package/src/components/Layout.vue +2 -2
  24. package/src/components/Message.vue +6 -6
  25. package/src/components/MessageTyping.vue +2 -2
  26. package/src/components/MessagesList.vue +4 -4
  27. package/src/composables/useChat.ts +2 -2
  28. package/src/composables/useI18n.ts +1 -1
  29. package/src/composables/useOptions.ts +2 -2
  30. package/src/constants/defaults.ts +5 -1
  31. package/src/constants/symbols.ts +1 -1
  32. package/src/css/_tokens.scss +36 -0
  33. package/src/css/index.scss +1 -0
  34. package/src/event-buses/chatEventBus.ts +1 -1
  35. package/src/index.ts +4 -4
  36. package/src/main.scss +1 -36
  37. package/src/plugins/chat.ts +8 -4
  38. package/src/types/chat.ts +2 -2
  39. package/src/types/options.ts +5 -0
  40. package/tsconfig.json +1 -1
  41. package/vite.config.ts +3 -1
package/.eslintrc.cjs CHANGED
@@ -7,45 +7,4 @@ module.exports = {
7
7
  extends: ['@n8n_io/eslint-config/frontend'],
8
8
 
9
9
  ...sharedOptions(__dirname, 'frontend'),
10
-
11
- rules: {
12
- 'n8n-local-rules/dangerously-use-html-string-missing': 'off',
13
-
14
- // TODO: Remove these
15
- 'id-denylist': 'warn',
16
- 'import/extensions': 'warn',
17
- 'import/no-default-export': 'warn',
18
- 'import/order': 'off',
19
- 'import/no-cycle': 'warn',
20
- 'import/no-duplicates': 'warn',
21
- '@typescript-eslint/ban-types': 'warn',
22
- '@typescript-eslint/dot-notation': 'warn',
23
- '@typescript-eslint/lines-between-class-members': 'warn',
24
- '@typescript-eslint/member-delimiter-style': 'warn',
25
- '@typescript-eslint/naming-convention': 'warn',
26
- '@typescript-eslint/no-empty-interface': 'warn',
27
- '@typescript-eslint/no-for-in-array': 'warn',
28
- '@typescript-eslint/no-loop-func': 'warn',
29
- '@typescript-eslint/no-non-null-assertion': 'warn',
30
- '@typescript-eslint/no-shadow': 'warn',
31
- '@typescript-eslint/no-this-alias': 'warn',
32
- '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
33
- '@typescript-eslint/no-unnecessary-type-assertion': 'warn',
34
- '@typescript-eslint/no-unsafe-argument': 'warn',
35
- '@typescript-eslint/no-unsafe-call': 'warn',
36
- '@typescript-eslint/no-unsafe-return': 'warn',
37
- '@typescript-eslint/no-unused-expressions': 'warn',
38
- '@typescript-eslint/no-unused-vars': 'warn',
39
- '@typescript-eslint/no-use-before-define': 'warn',
40
- '@typescript-eslint/no-var-requires': 'warn',
41
- '@typescript-eslint/prefer-nullish-coalescing': 'warn',
42
- '@typescript-eslint/prefer-optional-chain': 'warn',
43
- '@typescript-eslint/restrict-plus-operands': 'warn',
44
- '@typescript-eslint/unbound-method': 'warn',
45
- '@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
46
- '@typescript-eslint/no-redundant-type-constituents': 'warn',
47
- '@typescript-eslint/no-base-to-string': 'warn',
48
- '@typescript-eslint/no-explicit-any': 'warn',
49
- '@typescript-eslint/no-unsafe-enum-comparison': 'warn',
50
- },
51
10
  };
package/README.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # n8n Chat
2
2
  This is an embeddable Chat widget for n8n. It allows the execution of AI-Powered Workflows through a Chat window.
3
3
 
4
+ **Windowed Example**
5
+ ![n8n Chat Windowed](https://raw.githubusercontent.com/n8n-io/n8n/master/packages/%40n8n/chat/resources/images/windowed.png)
6
+
7
+ **Fullscreen Example**
8
+ ![n8n Chat Fullscreen](https://raw.githubusercontent.com/n8n-io/n8n/master/packages/%40n8n/chat/resources/images/fullscreen.png)
9
+
4
10
  ## Prerequisites
5
- Create a n8n workflow which you want to execute via chat. The workflow has to be triggered using a **Webhook** node and return data using the **Respond to Webhook** node.
11
+ Create a n8n workflow which you want to execute via chat. The workflow has to be triggered using a **Chat Trigger** node.
6
12
 
7
- Open the **Webhook** node and add your domain to the **Domain Allowlist** field. This makes sure that only requests from your domain are accepted.
13
+ Open the **Chat Trigger** node and add your domain to the **Allowed Origins (CORS)** field. This makes sure that only requests from your domain are accepted.
8
14
 
9
15
  [See example workflow](https://github.com/n8n-io/n8n/blob/master/packages/%40n8n/chat/resources/workflow.json)
10
16
 
@@ -17,8 +23,6 @@ Each request is accompanied by an `action` query parameter, where `action` can b
17
23
  - `loadPreviousSession` - When the user opens the Chatbot again and the previous chat session should be loaded
18
24
  - `sendMessage` - When the user sends a message
19
25
 
20
- We use the `Switch` node to handle the different actions.
21
-
22
26
  ## Installation
23
27
 
24
28
  Open the **Webhook** node and replace `YOUR_PRODUCTION_WEBHOOK_URL` with your production URL. This is the URL that the Chat widget will use to send requests to.
@@ -106,6 +110,10 @@ createChat({
106
110
  },
107
111
  target: '#n8n-chat',
108
112
  mode: 'window',
113
+ chatInputKey: 'chatInput',
114
+ chatSessionKey: 'sessionId',
115
+ metadata: {},
116
+ showWelcomeScreen: false,
109
117
  defaultLanguage: 'en',
110
118
  initialMessages: [
111
119
  'Hi there! 👋',
@@ -148,6 +156,21 @@ createChat({
148
156
  - In `window` mode, the Chat window will be embedded in the target element as a chat toggle button and a fixed size chat window.
149
157
  - In `fullscreen` mode, the Chat will take up the entire width and height of its target container.
150
158
 
159
+ ### `showWelcomeScreen`
160
+ - **Type**: `boolean`
161
+ - **Default**: `false`
162
+ - **Description**: Whether to show the welcome screen when the Chat window is opened.
163
+
164
+ ### `chatSessionKey`
165
+ - **Type**: `string`
166
+ - **Default**: `'sessionId'`
167
+ - **Description**: The key to use for sending the chat history session ID for the AI Memory node.
168
+
169
+ ### `chatInputKey`
170
+ - **Type**: `string`
171
+ - **Default**: `'chatInput'`
172
+ - **Description**: The key to use for sending the chat input for the AI Agent node.
173
+
151
174
  ### `defaultLanguage`
152
175
  - **Type**: `string`
153
176
  - **Default**: `'en'`
@@ -0,0 +1,21 @@
1
+ import { defineBuildConfig } from 'unbuild';
2
+
3
+ export default defineBuildConfig({
4
+ entries: [
5
+ {
6
+ builder: 'mkdist',
7
+ format: 'esm',
8
+ input: './src',
9
+ outDir: './tmp/lib',
10
+ },
11
+ {
12
+ builder: 'mkdist',
13
+ format: 'cjs',
14
+ input: './src',
15
+ outDir: './tmp/cjs',
16
+ },
17
+ ],
18
+ clean: true,
19
+ declaration: true,
20
+ failOnWarn: false,
21
+ });
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "@n8n/chat",
3
- "version": "0.6.0",
4
- "main": "./chat.umd.cjs",
3
+ "version": "0.7.0",
4
+ "main": "./chat.umd.js",
5
5
  "module": "./chat.es.js",
6
6
  "types": "./types/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./chat.es.js",
10
- "require": "./chat.umd.cjs"
9
+ "import": "./index.mjs",
10
+ "require": "./index.js"
11
11
  },
12
12
  "./style.css": {
13
13
  "import": "./style.css",
14
14
  "require": "./style.css"
15
+ },
16
+ "./*": {
17
+ "import": "./*",
18
+ "require": "./*"
15
19
  }
16
20
  },
17
21
  "repository": {
Binary file
Binary file
@@ -0,0 +1,238 @@
1
+ {
2
+ "name": "Hosted n8n AI Chat Manual",
3
+ "nodes": [
4
+ {
5
+ "parameters": {
6
+ "options": {}
7
+ },
8
+ "id": "e6043748-44fc-4019-9301-5690fe26c614",
9
+ "name": "OpenAI Chat Model",
10
+ "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
11
+ "typeVersion": 1,
12
+ "position": [
13
+ 860,
14
+ 540
15
+ ],
16
+ "credentials": {
17
+ "openAiApi": {
18
+ "id": "cIIkOhl7tUX1KsL6",
19
+ "name": "OpenAi account"
20
+ }
21
+ }
22
+ },
23
+ {
24
+ "parameters": {
25
+ "sessionKey": "={{ $json.sessionId }}"
26
+ },
27
+ "id": "0a68a59a-8ab6-4fa5-a1ea-b7f99a93109b",
28
+ "name": "Window Buffer Memory",
29
+ "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
30
+ "typeVersion": 1,
31
+ "position": [
32
+ 640,
33
+ 540
34
+ ]
35
+ },
36
+ {
37
+ "parameters": {
38
+ "text": "={{ $json.chatInput }}",
39
+ "options": {}
40
+ },
41
+ "id": "3d4e0fbf-d761-4569-b02e-f5c1eeb830c8",
42
+ "name": "AI Agent",
43
+ "type": "@n8n/n8n-nodes-langchain.agent",
44
+ "typeVersion": 1.1,
45
+ "position": [
46
+ 840,
47
+ 300
48
+ ]
49
+ },
50
+ {
51
+ "parameters": {
52
+ "dataType": "string",
53
+ "value1": "={{ $json.action }}",
54
+ "rules": {
55
+ "rules": [
56
+ {
57
+ "value2": "loadPreviousSession",
58
+ "outputKey": "loadPreviousSession"
59
+ },
60
+ {
61
+ "value2": "sendMessage",
62
+ "outputKey": "sendMessage"
63
+ }
64
+ ]
65
+ }
66
+ },
67
+ "id": "84213c7b-abc7-4f40-9567-cd3484a4ae6b",
68
+ "name": "Switch",
69
+ "type": "n8n-nodes-base.switch",
70
+ "typeVersion": 2,
71
+ "position": [
72
+ 300,
73
+ 280
74
+ ]
75
+ },
76
+ {
77
+ "parameters": {
78
+ "simplifyOutput": false
79
+ },
80
+ "id": "3be7f076-98ed-472a-80b6-bf8d9538ac87",
81
+ "name": "Chat Messages Retriever",
82
+ "type": "@n8n/n8n-nodes-langchain.memoryChatRetriever",
83
+ "typeVersion": 1,
84
+ "position": [
85
+ 620,
86
+ 140
87
+ ]
88
+ },
89
+ {
90
+ "parameters": {
91
+ "options": {}
92
+ },
93
+ "id": "3417c644-8a91-4524-974a-45b4a46d0e2e",
94
+ "name": "Respond to Webhook",
95
+ "type": "n8n-nodes-base.respondToWebhook",
96
+ "typeVersion": 1,
97
+ "position": [
98
+ 1240,
99
+ 140
100
+ ]
101
+ },
102
+ {
103
+ "parameters": {
104
+ "public": true,
105
+ "authentication": "n8nUserAuth",
106
+ "options": {
107
+ "loadPreviousSession": "manually",
108
+ "responseMode": "responseNode"
109
+ }
110
+ },
111
+ "id": "1b30c239-a819-45b4-b0ae-bdd5b92a5424",
112
+ "name": "Chat Trigger",
113
+ "type": "@n8n/n8n-nodes-langchain.chatTrigger",
114
+ "typeVersion": 1,
115
+ "position": [
116
+ 80,
117
+ 280
118
+ ],
119
+ "webhookId": "ed3dea26-7d68-42b3-9032-98fe967d441d"
120
+ },
121
+ {
122
+ "parameters": {
123
+ "aggregate": "aggregateAllItemData",
124
+ "options": {}
125
+ },
126
+ "id": "79672cf0-686b-41eb-90ae-fd31b6da837d",
127
+ "name": "Aggregate",
128
+ "type": "n8n-nodes-base.aggregate",
129
+ "typeVersion": 1,
130
+ "position": [
131
+ 1000,
132
+ 140
133
+ ]
134
+ }
135
+ ],
136
+ "pinData": {},
137
+ "connections": {
138
+ "OpenAI Chat Model": {
139
+ "ai_languageModel": [
140
+ [
141
+ {
142
+ "node": "AI Agent",
143
+ "type": "ai_languageModel",
144
+ "index": 0
145
+ }
146
+ ]
147
+ ]
148
+ },
149
+ "Window Buffer Memory": {
150
+ "ai_memory": [
151
+ [
152
+ {
153
+ "node": "AI Agent",
154
+ "type": "ai_memory",
155
+ "index": 0
156
+ },
157
+ {
158
+ "node": "Chat Messages Retriever",
159
+ "type": "ai_memory",
160
+ "index": 0
161
+ }
162
+ ]
163
+ ]
164
+ },
165
+ "Switch": {
166
+ "main": [
167
+ [
168
+ {
169
+ "node": "Chat Messages Retriever",
170
+ "type": "main",
171
+ "index": 0
172
+ }
173
+ ],
174
+ [
175
+ {
176
+ "node": "AI Agent",
177
+ "type": "main",
178
+ "index": 0
179
+ }
180
+ ]
181
+ ]
182
+ },
183
+ "Chat Messages Retriever": {
184
+ "main": [
185
+ [
186
+ {
187
+ "node": "Aggregate",
188
+ "type": "main",
189
+ "index": 0
190
+ }
191
+ ]
192
+ ]
193
+ },
194
+ "AI Agent": {
195
+ "main": [
196
+ [
197
+ {
198
+ "node": "Respond to Webhook",
199
+ "type": "main",
200
+ "index": 0
201
+ }
202
+ ]
203
+ ]
204
+ },
205
+ "Chat Trigger": {
206
+ "main": [
207
+ [
208
+ {
209
+ "node": "Switch",
210
+ "type": "main",
211
+ "index": 0
212
+ }
213
+ ]
214
+ ]
215
+ },
216
+ "Aggregate": {
217
+ "main": [
218
+ [
219
+ {
220
+ "node": "Respond to Webhook",
221
+ "type": "main",
222
+ "index": 0
223
+ }
224
+ ]
225
+ ]
226
+ }
227
+ },
228
+ "active": true,
229
+ "settings": {
230
+ "executionOrder": "v1"
231
+ },
232
+ "versionId": "425c0efe-3aa0-4e0e-8c06-abe12234b1fd",
233
+ "id": "1569HF92Y02EUtsU",
234
+ "meta": {
235
+ "instanceId": "374b43d8b8d6299cc777811a4ad220fc688ee2d54a308cfb0de4450a5233ca9e"
236
+ },
237
+ "tags": []
238
+ }