@n8n/chat 0.5.1 → 0.5.2

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 (158) hide show
  1. package/App.vue +23 -0
  2. package/__stories__/App.stories.d.ts +16 -0
  3. package/__stories__/App.stories.js +38 -0
  4. package/__stories__/App.stories.mjs +32 -0
  5. package/__tests__/index.spec.d.ts +1 -0
  6. package/__tests__/index.spec.js +146 -0
  7. package/__tests__/index.spec.mjs +172 -0
  8. package/__tests__/setup.d.ts +1 -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.d.ts +3 -0
  18. package/__tests__/utils/index.js +38 -0
  19. package/__tests__/utils/index.mjs +3 -0
  20. package/__tests__/utils/selectors.d.ts +12 -0
  21. package/__tests__/utils/selectors.js +58 -0
  22. package/__tests__/utils/selectors.mjs +41 -0
  23. package/api/generic.d.ts +6 -0
  24. package/api/generic.js +68 -0
  25. package/api/generic.mjs +54 -0
  26. package/api/index.d.ts +2 -0
  27. package/api/index.js +27 -0
  28. package/api/index.mjs +2 -0
  29. package/api/message.d.ts +3 -0
  30. package/api/message.js +33 -0
  31. package/api/message.mjs +30 -0
  32. package/components/Button.vue +34 -0
  33. package/components/Chat.vue +52 -0
  34. package/components/ChatWindow.vue +104 -0
  35. package/components/GetStarted.vue +24 -0
  36. package/components/GetStartedFooter.vue +20 -0
  37. package/components/Input.vue +88 -0
  38. package/components/Layout.vue +66 -0
  39. package/components/Message.vue +94 -0
  40. package/components/MessageTyping.vue +101 -0
  41. package/components/MessagesList.vue +37 -0
  42. package/components/PoweredBy.vue +16 -0
  43. package/components/index.d.ts +10 -0
  44. package/components/index.js +76 -0
  45. package/components/index.mjs +10 -0
  46. package/composables/index.d.ts +3 -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.d.ts +3 -0
  62. package/constants/index.js +38 -0
  63. package/constants/index.mjs +3 -0
  64. package/constants/localStorage.d.ts +2 -0
  65. package/constants/localStorage.js +8 -0
  66. package/constants/localStorage.mjs +2 -0
  67. package/constants/symbols.d.ts +3 -0
  68. package/constants/symbols.js +8 -0
  69. package/constants/symbols.mjs +2 -0
  70. package/css/index.css +31 -0
  71. package/event-buses/chatEventBus.d.ts +1 -0
  72. package/event-buses/chatEventBus.js +8 -0
  73. package/event-buses/chatEventBus.mjs +2 -0
  74. package/event-buses/index.d.ts +1 -0
  75. package/event-buses/index.js +16 -0
  76. package/event-buses/index.mjs +1 -0
  77. package/index.d.ts +3 -0
  78. package/index.js +43 -0
  79. package/index.mjs +36 -0
  80. package/main.css +151 -0
  81. package/package.json +9 -2
  82. package/plugins/chat.d.ts +3 -0
  83. package/plugins/chat.js +85 -0
  84. package/plugins/chat.mjs +83 -0
  85. package/plugins/index.d.ts +1 -0
  86. package/plugins/index.js +16 -0
  87. package/plugins/index.mjs +1 -0
  88. package/shims.d.ts +6 -0
  89. package/types/chat.d.ts +11 -0
  90. package/types/chat.js +1 -0
  91. package/types/chat.mjs +0 -0
  92. package/types/index.d.ts +4 -2
  93. package/types/index.js +49 -0
  94. package/types/index.mjs +4 -0
  95. package/types/messages.d.ts +6 -0
  96. package/types/messages.js +1 -0
  97. package/types/messages.mjs +0 -0
  98. package/types/options.d.ts +25 -0
  99. package/types/options.js +1 -0
  100. package/types/options.mjs +0 -0
  101. package/types/src/App.vue.d.ts +8 -0
  102. package/types/src/__stories__/App.stories.d.ts +17 -0
  103. package/types/src/__tests__/index.spec.d.ts +1 -0
  104. package/types/src/__tests__/setup.d.ts +0 -0
  105. package/types/src/__tests__/utils/create.d.ts +5 -0
  106. package/types/src/__tests__/utils/fetch.d.ts +4 -0
  107. package/types/src/__tests__/utils/index.d.ts +3 -0
  108. package/types/src/__tests__/utils/selectors.d.ts +12 -0
  109. package/types/src/api/generic.d.ts +6 -0
  110. package/types/src/api/index.d.ts +2 -0
  111. package/types/src/api/message.d.ts +3 -0
  112. package/types/src/components/Button.vue.d.ts +9 -0
  113. package/types/src/components/Chat.vue.d.ts +2 -0
  114. package/types/src/components/ChatWindow.vue.d.ts +2 -0
  115. package/types/src/components/GetStarted.vue.d.ts +2 -0
  116. package/types/src/components/GetStartedFooter.vue.d.ts +2 -0
  117. package/types/src/components/Input.vue.d.ts +2 -0
  118. package/types/src/components/Layout.vue.d.ts +11 -0
  119. package/types/src/components/Message.vue.d.ts +21 -0
  120. package/types/src/components/MessageTyping.vue.d.ts +15 -0
  121. package/types/src/components/MessagesList.vue.d.ts +14 -0
  122. package/types/src/components/PoweredBy.vue.d.ts +2 -0
  123. package/types/src/components/index.d.ts +10 -0
  124. package/types/src/composables/index.d.ts +3 -0
  125. package/types/src/composables/useChat.d.ts +2 -0
  126. package/types/src/composables/useI18n.d.ts +4 -0
  127. package/types/src/composables/useOptions.d.ts +4 -0
  128. package/types/src/constants/defaults.d.ts +3 -0
  129. package/types/src/constants/index.d.ts +3 -0
  130. package/types/src/constants/localStorage.d.ts +2 -0
  131. package/types/src/constants/symbols.d.ts +4 -0
  132. package/types/src/event-buses/chatEventBus.d.ts +1 -0
  133. package/types/src/event-buses/index.d.ts +1 -0
  134. package/types/src/index.d.ts +2 -0
  135. package/types/src/plugins/chat.d.ts +3 -0
  136. package/types/src/plugins/index.d.ts +1 -0
  137. package/types/src/types/chat.d.ts +11 -0
  138. package/types/src/types/index.d.ts +4 -0
  139. package/types/src/types/messages.d.ts +6 -0
  140. package/types/src/types/options.d.ts +25 -0
  141. package/types/src/types/webhook.d.ts +15 -0
  142. package/types/src/utils/event-bus.d.ts +8 -0
  143. package/types/src/utils/index.d.ts +2 -0
  144. package/types/src/utils/mount.d.ts +1 -0
  145. package/types/webhook.d.ts +15 -0
  146. package/types/webhook.js +1 -0
  147. package/types/webhook.mjs +0 -0
  148. package/utils/event-bus.d.ts +8 -0
  149. package/utils/event-bus.js +38 -0
  150. package/utils/event-bus.mjs +32 -0
  151. package/utils/index.d.ts +2 -0
  152. package/utils/index.js +27 -0
  153. package/utils/index.mjs +2 -0
  154. package/utils/mount.d.ts +1 -0
  155. package/utils/mount.js +19 -0
  156. package/utils/mount.mjs +13 -0
  157. package/chat.es.js +0 -6870
  158. package/chat.umd.js +0 -18
package/css/index.css ADDED
@@ -0,0 +1,31 @@
1
+ :root {
2
+ --chat--color-primary: #e74266;
3
+ --chat--color-primary-shade-50: #db4061;
4
+ --chat--color-primary-shade-100: #cf3c5c;
5
+ --chat--color-secondary: #20b69e;
6
+ --chat--color-secondary-shade-50: #1ca08a;
7
+ --chat--color-white: #ffffff;
8
+ --chat--color-light: #f2f4f8;
9
+ --chat--color-light-shade-50: #e6e9f1;
10
+ --chat--color-light-shade-100: #c2c5cc;
11
+ --chat--color-medium: #d2d4d9;
12
+ --chat--color-dark: #101330;
13
+ --chat--color-disabled: #777980;
14
+ --chat--color-typing: #404040;
15
+ --chat--spacing: 1rem;
16
+ --chat--border-radius: 0.25rem;
17
+ --chat--transition-duration: 0.15s;
18
+ --chat--window--width: 400px;
19
+ --chat--window--height: 600px;
20
+ --chat--textarea--height: 50px;
21
+ --chat--message--bot--background: var(--chat--color-white);
22
+ --chat--message--bot--color: var(--chat--color-dark);
23
+ --chat--message--user--background: var(--chat--color-secondary);
24
+ --chat--message--user--color: var(--chat--color-white);
25
+ --chat--message--pre--background: rgba(0, 0, 0, 0.05);
26
+ --chat--toggle--background: var(--chat--color-primary);
27
+ --chat--toggle--hover--background: var(--chat--color-primary-shade-50);
28
+ --chat--toggle--active--background: var(--chat--color-primary-shade-100);
29
+ --chat--toggle--color: var(--chat--color-white);
30
+ --chat--toggle--size: 64px;
31
+ }
@@ -0,0 +1 @@
1
+ export declare const chatEventBus: any;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.chatEventBus = void 0;
7
+ var _utils = require("@n8n/chat/utils");
8
+ const chatEventBus = exports.chatEventBus = (0, _utils.createEventBus)();
@@ -0,0 +1,2 @@
1
+ import { createEventBus } from "@n8n/chat/utils";
2
+ export const chatEventBus = createEventBus();
@@ -0,0 +1 @@
1
+ export * from './chatEventBus';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _chatEventBus = require("./chatEventBus");
7
+ Object.keys(_chatEventBus).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _chatEventBus[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _chatEventBus[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ export * from "./chatEventBus.mjs";
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import './main.scss';
2
+ import type { ChatOptions } from '@n8n/chat/types';
3
+ export declare function createChat(options?: Partial<ChatOptions>): import("vue").App<Element>;
package/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createChat = createChat;
7
+ require("./main.scss");
8
+ var _vue = require("vue");
9
+ var _App = _interopRequireDefault(require("./App.vue"));
10
+ var _constants = require("@n8n/chat/constants");
11
+ var _utils = require("@n8n/chat/utils");
12
+ var _plugins = require("@n8n/chat/plugins");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function createChat(options) {
15
+ const resolvedOptions = {
16
+ ..._constants.defaultOptions,
17
+ ...options,
18
+ webhookConfig: {
19
+ ..._constants.defaultOptions.webhookConfig,
20
+ ...options?.webhookConfig
21
+ },
22
+ i18n: {
23
+ ..._constants.defaultOptions.i18n,
24
+ ...options?.i18n,
25
+ en: {
26
+ ..._constants.defaultOptions.i18n?.en,
27
+ ...options?.i18n?.en
28
+ }
29
+ },
30
+ theme: {
31
+ ..._constants.defaultOptions.theme,
32
+ ...options?.theme
33
+ }
34
+ };
35
+ const mountingTarget = resolvedOptions.target ?? _constants.defaultMountingTarget;
36
+ if (typeof mountingTarget === "string") {
37
+ (0, _utils.createDefaultMountingTarget)(mountingTarget);
38
+ }
39
+ const app = (0, _vue.createApp)(_App.default);
40
+ app.use(_plugins.ChatPlugin, resolvedOptions);
41
+ app.mount(mountingTarget);
42
+ return app;
43
+ }
package/index.mjs ADDED
@@ -0,0 +1,36 @@
1
+ import "./main.scss";
2
+ import { createApp } from "vue";
3
+ import App from "./App.vue";
4
+ import { defaultMountingTarget, defaultOptions } from "@n8n/chat/constants";
5
+ import { createDefaultMountingTarget } from "@n8n/chat/utils";
6
+ import { ChatPlugin } from "@n8n/chat/plugins";
7
+ export function createChat(options) {
8
+ const resolvedOptions = {
9
+ ...defaultOptions,
10
+ ...options,
11
+ webhookConfig: {
12
+ ...defaultOptions.webhookConfig,
13
+ ...options?.webhookConfig
14
+ },
15
+ i18n: {
16
+ ...defaultOptions.i18n,
17
+ ...options?.i18n,
18
+ en: {
19
+ ...defaultOptions.i18n?.en,
20
+ ...options?.i18n?.en
21
+ }
22
+ },
23
+ theme: {
24
+ ...defaultOptions.theme,
25
+ ...options?.theme
26
+ }
27
+ };
28
+ const mountingTarget = resolvedOptions.target ?? defaultMountingTarget;
29
+ if (typeof mountingTarget === "string") {
30
+ createDefaultMountingTarget(mountingTarget);
31
+ }
32
+ const app = createApp(App);
33
+ app.use(ChatPlugin, resolvedOptions);
34
+ app.mount(mountingTarget);
35
+ return app;
36
+ }
package/main.css ADDED
@@ -0,0 +1,151 @@
1
+ .n8n-chat {
2
+ /*!
3
+ Theme: GitHub
4
+ Description: Light theme as seen on github.com
5
+ Author: github.com
6
+ Maintainer: @Hirse
7
+ Updated: 2021-05-15
8
+
9
+ Outdated base version: https://github.com/primer/github-syntax-light
10
+ Current colors taken from GitHub's CSS
11
+ */
12
+ }
13
+ .n8n-chat pre code.hljs {
14
+ display: block;
15
+ overflow-x: auto;
16
+ padding: 1em;
17
+ }
18
+ .n8n-chat code.hljs {
19
+ padding: 3px 5px;
20
+ }
21
+ .n8n-chat .hljs {
22
+ color: #24292e;
23
+ background: #ffffff;
24
+ }
25
+ .n8n-chat .hljs-doctag,
26
+ .n8n-chat .hljs-keyword,
27
+ .n8n-chat .hljs-meta .hljs-keyword,
28
+ .n8n-chat .hljs-template-tag,
29
+ .n8n-chat .hljs-template-variable,
30
+ .n8n-chat .hljs-type,
31
+ .n8n-chat .hljs-variable.language_ {
32
+ /* prettylights-syntax-keyword */
33
+ color: #d73a49;
34
+ }
35
+ .n8n-chat .hljs-title,
36
+ .n8n-chat .hljs-title.class_,
37
+ .n8n-chat .hljs-title.class_.inherited__,
38
+ .n8n-chat .hljs-title.function_ {
39
+ /* prettylights-syntax-entity */
40
+ color: #6f42c1;
41
+ }
42
+ .n8n-chat .hljs-attr,
43
+ .n8n-chat .hljs-attribute,
44
+ .n8n-chat .hljs-literal,
45
+ .n8n-chat .hljs-meta,
46
+ .n8n-chat .hljs-number,
47
+ .n8n-chat .hljs-operator,
48
+ .n8n-chat .hljs-variable,
49
+ .n8n-chat .hljs-selector-attr,
50
+ .n8n-chat .hljs-selector-class,
51
+ .n8n-chat .hljs-selector-id {
52
+ /* prettylights-syntax-constant */
53
+ color: #005cc5;
54
+ }
55
+ .n8n-chat .hljs-regexp,
56
+ .n8n-chat .hljs-string,
57
+ .n8n-chat .hljs-meta .hljs-string {
58
+ /* prettylights-syntax-string */
59
+ color: #032f62;
60
+ }
61
+ .n8n-chat .hljs-built_in,
62
+ .n8n-chat .hljs-symbol {
63
+ /* prettylights-syntax-variable */
64
+ color: #e36209;
65
+ }
66
+ .n8n-chat .hljs-comment,
67
+ .n8n-chat .hljs-code,
68
+ .n8n-chat .hljs-formula {
69
+ /* prettylights-syntax-comment */
70
+ color: #6a737d;
71
+ }
72
+ .n8n-chat .hljs-name,
73
+ .n8n-chat .hljs-quote,
74
+ .n8n-chat .hljs-selector-tag,
75
+ .n8n-chat .hljs-selector-pseudo {
76
+ /* prettylights-syntax-entity-tag */
77
+ color: #22863a;
78
+ }
79
+ .n8n-chat .hljs-subst {
80
+ /* prettylights-syntax-storage-modifier-import */
81
+ color: #24292e;
82
+ }
83
+ .n8n-chat .hljs-section {
84
+ /* prettylights-syntax-markup-heading */
85
+ color: #005cc5;
86
+ font-weight: bold;
87
+ }
88
+ .n8n-chat .hljs-bullet {
89
+ /* prettylights-syntax-markup-list */
90
+ color: #735c0f;
91
+ }
92
+ .n8n-chat .hljs-emphasis {
93
+ /* prettylights-syntax-markup-italic */
94
+ color: #24292e;
95
+ font-style: italic;
96
+ }
97
+ .n8n-chat .hljs-strong {
98
+ /* prettylights-syntax-markup-bold */
99
+ color: #24292e;
100
+ font-weight: bold;
101
+ }
102
+ .n8n-chat .hljs-addition {
103
+ /* prettylights-syntax-markup-inserted */
104
+ color: #22863a;
105
+ background-color: #f0fff4;
106
+ }
107
+ .n8n-chat .hljs-deletion {
108
+ /* prettylights-syntax-markup-deleted */
109
+ color: #b31d28;
110
+ background-color: #ffeef0;
111
+ }
112
+ .n8n-chat .hljs-char.escape_,
113
+ .n8n-chat .hljs-link,
114
+ .n8n-chat .hljs-params,
115
+ .n8n-chat .hljs-property,
116
+ .n8n-chat .hljs-punctuation,
117
+ .n8n-chat .hljs-tag {
118
+ /* purposely ignored */
119
+ }
120
+
121
+ :root {
122
+ --chat--color-primary: #e74266;
123
+ --chat--color-primary-shade-50: #db4061;
124
+ --chat--color-primary-shade-100: #cf3c5c;
125
+ --chat--color-secondary: #20b69e;
126
+ --chat--color-secondary-shade-50: #1ca08a;
127
+ --chat--color-white: #ffffff;
128
+ --chat--color-light: #f2f4f8;
129
+ --chat--color-light-shade-50: #e6e9f1;
130
+ --chat--color-light-shade-100: #c2c5cc;
131
+ --chat--color-medium: #d2d4d9;
132
+ --chat--color-dark: #101330;
133
+ --chat--color-disabled: #777980;
134
+ --chat--color-typing: #404040;
135
+ --chat--spacing: 1rem;
136
+ --chat--border-radius: 0.25rem;
137
+ --chat--transition-duration: 0.15s;
138
+ --chat--window--width: 400px;
139
+ --chat--window--height: 600px;
140
+ --chat--textarea--height: 50px;
141
+ --chat--message--bot--background: var(--chat--color-white);
142
+ --chat--message--bot--color: var(--chat--color-dark);
143
+ --chat--message--user--background: var(--chat--color-secondary);
144
+ --chat--message--user--color: var(--chat--color-white);
145
+ --chat--message--pre--background: rgba(0, 0, 0, 0.05);
146
+ --chat--toggle--background: var(--chat--color-primary);
147
+ --chat--toggle--hover--background: var(--chat--color-primary-shade-50);
148
+ --chat--toggle--active--background: var(--chat--color-primary-shade-100);
149
+ --chat--toggle--color: var(--chat--color-white);
150
+ --chat--toggle--size: 64px;
151
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n8n/chat",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "main": "./chat.umd.cjs",
5
5
  "module": "./chat.es.js",
6
6
  "types": "./types/index.d.ts",
@@ -12,6 +12,10 @@
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
  "dependencies": {
@@ -43,6 +47,7 @@
43
47
  "@vue/tsconfig": "^0.4.0",
44
48
  "eslint": "^8.45.0",
45
49
  "eslint-plugin-vue": "^9.15.1",
50
+ "fast-glob": "^3.3.2",
46
51
  "jsdom": "^22.1.0",
47
52
  "npm-run-all": "^4.1.5",
48
53
  "prettier": "^3.0.0",
@@ -51,6 +56,7 @@
51
56
  "shelljs": "^0.8.5",
52
57
  "storybook": "^7.4.0",
53
58
  "typescript": "~5.1.6",
59
+ "unbuild": "^2.0.0",
54
60
  "unplugin-icons": "^0.17.0",
55
61
  "vite": "^4.4.6",
56
62
  "vite-plugin-dts": "^3.6.0",
@@ -65,9 +71,10 @@
65
71
  "homepage": "https://n8n.io",
66
72
  "scripts": {
67
73
  "dev": "pnpm run storybook",
68
- "build": "run-p type-check build:vite && npm run build:prepare",
74
+ "build": "run-p type-check build:vite:full && pnpm run build:individual && npm run build:prepare",
69
75
  "build:vite": "vite build && npm run build:vite:full",
70
76
  "build:vite:full": "INCLUDE_VUE=true vite build",
77
+ "build:individual": "unbuild",
71
78
  "build:prepare": "node scripts/postbuild.js",
72
79
  "build:pack": "node scripts/pack.js",
73
80
  "preview": "vite preview",
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vue';
2
+ import type { ChatOptions } from '@n8n/chat/types';
3
+ export declare const ChatPlugin: Plugin<ChatOptions>;
@@ -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 @@
1
+ export * from './chat';
@@ -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/shims.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ declare module '*.vue' {
2
+ import { defineComponent } from 'vue';
3
+
4
+ const component: ReturnType<typeof defineComponent>;
5
+ export default component;
6
+ }
@@ -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
package/types/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- import type { ChatOptions } from './types';
2
- export declare function createChat(options?: Partial<ChatOptions>): import("vue").App<Element>;
1
+ export * from './chat';
2
+ export * from './messages';
3
+ export * from './options';
4
+ export * from './webhook';
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