@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
@@ -0,0 +1,25 @@
1
+ export interface ChatOptions {
2
+ webhookUrl: string;
3
+ webhookConfig?: {
4
+ method?: 'GET' | 'POST';
5
+ headers?: Record<string, string>;
6
+ };
7
+ target?: string | Element;
8
+ mode?: 'window' | 'fullscreen';
9
+ showWelcomeScreen?: boolean;
10
+ loadPreviousSession?: boolean;
11
+ chatInputKey?: string;
12
+ chatSessionKey?: string;
13
+ defaultLanguage?: 'en';
14
+ initialMessages?: string[];
15
+ metadata?: Record<string, unknown>;
16
+ i18n: Record<string, {
17
+ title: string;
18
+ subtitle: string;
19
+ footer: string;
20
+ getStarted: string;
21
+ inputPlaceholder: string;
22
+ [message: string]: string;
23
+ }>;
24
+ theme?: {};
25
+ }
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,8 @@
1
+ declare const _default: import("vue").DefineComponent<Readonly<import("vue").ComponentPropsOptions<{
2
+ [x: string]: unknown;
3
+ }>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, readonly string[] | Readonly<import("vue").ExtractPropTypes<Readonly<import("vue").ComponentObjectPropsOptions<{
4
+ [x: string]: unknown;
5
+ }>>>>, {
6
+ readonly [x: number]: string;
7
+ } | {}, {}>;
8
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import type { StoryObj } from '@storybook/vue3';
2
+ import type { ChatOptions } from '../types';
3
+ declare const meta: {
4
+ title: string;
5
+ render: (args: Partial<ChatOptions>) => {
6
+ setup(): {};
7
+ template: string;
8
+ };
9
+ parameters: {
10
+ layout: string;
11
+ };
12
+ tags: string[];
13
+ };
14
+ export default meta;
15
+ type Story = StoryObj<typeof meta>;
16
+ export declare const Fullscreen: Story;
17
+ export declare const Windowed: Story;
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1,5 @@
1
+ import { createChat } from '../../index';
2
+ export declare function createTestChat(options?: Parameters<typeof createChat>[0]): {
3
+ unmount: () => void;
4
+ container: Element;
5
+ };
@@ -0,0 +1,4 @@
1
+ import type { LoadPreviousSessionResponse, SendMessageResponse } from '../../types';
2
+ export declare function createFetchResponse<T>(data: T): () => Promise<Response>;
3
+ export declare const createGetLatestMessagesResponse: (data?: LoadPreviousSessionResponse['data']) => LoadPreviousSessionResponse;
4
+ export declare const createSendMessageResponse: (output: SendMessageResponse['output']) => SendMessageResponse;
@@ -0,0 +1,3 @@
1
+ export * from './create';
2
+ export * from './fetch';
3
+ export * from './selectors';
@@ -0,0 +1,12 @@
1
+ export declare function getMountingTarget(target?: string): Element | null;
2
+ export declare function getChatWindowWrapper(): Element | null;
3
+ export declare function getChatWindowToggle(): Element | null;
4
+ export declare function getChatWrapper(): Element | null;
5
+ export declare function getChatMessages(): NodeListOf<Element>;
6
+ export declare function getChatMessage(index: number): Element;
7
+ export declare function getChatMessageByText(text: string): HTMLElement | null;
8
+ export declare function getChatMessageTyping(): Element | null;
9
+ export declare function getGetStartedButton(): Element | null;
10
+ export declare function getChatInput(): Element | null;
11
+ export declare function getChatInputTextarea(): Element | null;
12
+ export declare function getChatInputSendButton(): Element | null;
@@ -0,0 +1,6 @@
1
+ export declare function authenticatedFetch<T>(...args: Parameters<typeof fetch>): Promise<T>;
2
+ export declare function get<T>(url: string, query?: object, options?: RequestInit): Promise<T>;
3
+ export declare function post<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
4
+ export declare function put<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
5
+ export declare function patch<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
6
+ export declare function del<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
@@ -0,0 +1,2 @@
1
+ export * from './generic';
2
+ export * from './message';
@@ -0,0 +1,3 @@
1
+ import type { ChatOptions, LoadPreviousSessionResponse, SendMessageResponse } from '../types';
2
+ export declare function loadPreviousSession(sessionId: string, options: ChatOptions): Promise<LoadPreviousSessionResponse>;
3
+ export declare function sendMessage(message: string, sessionId: string, options: ChatOptions): Promise<SendMessageResponse>;
@@ -0,0 +1,9 @@
1
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
2
+ default?(_: {}): any;
3
+ }>;
4
+ export default _default;
5
+ type __VLS_WithTemplateSlots<T, S> = T & {
6
+ new (): {
7
+ $slots: S;
8
+ };
9
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
2
+ header?(_: {}): any;
3
+ default?(_: {}): any;
4
+ footer?(_: {}): any;
5
+ }>;
6
+ export default _default;
7
+ type __VLS_WithTemplateSlots<T, S> = T & {
8
+ new (): {
9
+ $slots: S;
10
+ };
11
+ };
@@ -0,0 +1,21 @@
1
+ import type { ChatMessage } from '../types';
2
+ import type { PropType } from 'vue';
3
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
4
+ message: {
5
+ type: PropType<ChatMessage>;
6
+ required: true;
7
+ };
8
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
9
+ message: {
10
+ type: PropType<ChatMessage>;
11
+ required: true;
12
+ };
13
+ }>>, {}, {}>, {
14
+ default?(_: {}): any;
15
+ }>;
16
+ export default _default;
17
+ type __VLS_WithTemplateSlots<T, S> = T & {
18
+ new (): {
19
+ $slots: S;
20
+ };
21
+ };
@@ -0,0 +1,15 @@
1
+ import type { PropType } from 'vue';
2
+ declare const _default: import("vue").DefineComponent<{
3
+ animation: {
4
+ type: PropType<"bouncing" | "scaling">;
5
+ default: string;
6
+ };
7
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
8
+ animation: {
9
+ type: PropType<"bouncing" | "scaling">;
10
+ default: string;
11
+ };
12
+ }>>, {
13
+ animation: "bouncing" | "scaling";
14
+ }, {}>;
15
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import type { PropType } from 'vue';
2
+ import type { ChatMessage } from '../types';
3
+ declare const _default: import("vue").DefineComponent<{
4
+ messages: {
5
+ type: PropType<ChatMessage[]>;
6
+ required: true;
7
+ };
8
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
9
+ messages: {
10
+ type: PropType<ChatMessage[]>;
11
+ required: true;
12
+ };
13
+ }>>, {}, {}>;
14
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ export { default as Button } from './Button.vue';
2
+ export { default as Chat } from './Chat.vue';
3
+ export { default as ChatWindow } from './ChatWindow.vue';
4
+ export { default as GetStarted } from './GetStarted.vue';
5
+ export { default as GetStartedFooter } from './GetStartedFooter.vue';
6
+ export { default as Input } from './Input.vue';
7
+ export { default as Layout } from './Layout.vue';
8
+ export { default as Message } from './Message.vue';
9
+ export { default as MessagesList } from './MessagesList.vue';
10
+ export { default as PoweredBy } from './PoweredBy.vue';
@@ -0,0 +1,3 @@
1
+ export * from './useChat';
2
+ export * from './useI18n';
3
+ export * from './useOptions';
@@ -0,0 +1,2 @@
1
+ import type { Chat } from '../types';
2
+ export declare function useChat(): Chat;
@@ -0,0 +1,4 @@
1
+ export declare function useI18n(): {
2
+ t: (key: string) => string;
3
+ te: (key: string) => boolean;
4
+ };
@@ -0,0 +1,4 @@
1
+ import type { ChatOptions } from '../types';
2
+ export declare function useOptions(): {
3
+ options: ChatOptions;
4
+ };
@@ -0,0 +1,3 @@
1
+ import type { ChatOptions } from '../types';
2
+ export declare const defaultOptions: ChatOptions;
3
+ export declare const defaultMountingTarget = "#n8n-chat";
@@ -0,0 +1,3 @@
1
+ export * from './defaults';
2
+ export * from './localStorage';
3
+ export * from './symbols';
@@ -0,0 +1,2 @@
1
+ export declare const localStorageNamespace = "n8n-chat";
2
+ export declare const localStorageSessionIdKey = "n8n-chat/sessionId";
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'vue';
2
+ import type { Chat, ChatOptions } from '../types';
3
+ export declare const ChatSymbol: InjectionKey<Chat>;
4
+ export declare const ChatOptionsSymbol: InjectionKey<ChatOptions>;
@@ -0,0 +1 @@
1
+ export declare const chatEventBus: import('../utils').EventBus;
@@ -0,0 +1 @@
1
+ export * from './chatEventBus';
@@ -0,0 +1,2 @@
1
+ import type { ChatOptions } from './types';
2
+ export declare function createChat(options?: Partial<ChatOptions>): import("vue").App<Element>;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vue';
2
+ import type { ChatOptions } from '../types';
3
+ export declare const ChatPlugin: Plugin<ChatOptions>;
@@ -0,0 +1 @@
1
+ export * from './chat';
@@ -0,0 +1,11 @@
1
+ import type { ChatMessage } from '../types/messages';
2
+ import type { Ref } from 'vue';
3
+ export interface Chat {
4
+ initialMessages: Ref<ChatMessage[]>;
5
+ messages: Ref<ChatMessage[]>;
6
+ currentSessionId: Ref<string | null>;
7
+ waitingForResponse: Ref<boolean>;
8
+ loadPreviousSession: () => Promise<string | undefined>;
9
+ startNewSession: () => Promise<void>;
10
+ sendMessage: (text: string) => Promise<void>;
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from './chat';
2
+ export * from './messages';
3
+ export * from './options';
4
+ export * from './webhook';
@@ -0,0 +1,6 @@
1
+ export interface ChatMessage {
2
+ id: string;
3
+ text: string;
4
+ createdAt: string;
5
+ sender: 'user' | 'bot';
6
+ }
@@ -0,0 +1,25 @@
1
+ export interface ChatOptions {
2
+ webhookUrl: string;
3
+ webhookConfig?: {
4
+ method?: 'GET' | 'POST';
5
+ headers?: Record<string, string>;
6
+ };
7
+ target?: string | Element;
8
+ mode?: 'window' | 'fullscreen';
9
+ showWelcomeScreen?: boolean;
10
+ loadPreviousSession?: boolean;
11
+ chatInputKey?: string;
12
+ chatSessionKey?: string;
13
+ defaultLanguage?: 'en';
14
+ initialMessages?: string[];
15
+ metadata?: Record<string, unknown>;
16
+ i18n: Record<string, {
17
+ title: string;
18
+ subtitle: string;
19
+ footer: string;
20
+ getStarted: string;
21
+ inputPlaceholder: string;
22
+ [message: string]: string;
23
+ }>;
24
+ theme?: {};
25
+ }
@@ -0,0 +1,15 @@
1
+ export interface LoadPreviousSessionResponseItem {
2
+ id: string[];
3
+ kwargs: {
4
+ content: string;
5
+ additional_kwargs: Record<string, unknown>;
6
+ };
7
+ lc: number;
8
+ type: string;
9
+ }
10
+ export interface LoadPreviousSessionResponse {
11
+ data: LoadPreviousSessionResponseItem[];
12
+ }
13
+ export interface SendMessageResponse {
14
+ output: string;
15
+ }
@@ -0,0 +1,8 @@
1
+ export type CallbackFn = Function;
2
+ export type UnregisterFn = () => void;
3
+ export interface EventBus {
4
+ on: (eventName: string, fn: CallbackFn) => UnregisterFn;
5
+ off: (eventName: string, fn: CallbackFn) => void;
6
+ emit: <T = Event>(eventName: string, event?: T) => void;
7
+ }
8
+ export declare function createEventBus(): EventBus;
@@ -0,0 +1,2 @@
1
+ export * from './event-bus';
2
+ export * from './mount';
@@ -0,0 +1 @@
1
+ export declare function createDefaultMountingTarget(mountingTarget: string): void;
@@ -0,0 +1,15 @@
1
+ export interface LoadPreviousSessionResponseItem {
2
+ id: string[];
3
+ kwargs: {
4
+ content: string;
5
+ additional_kwargs: Record<string, unknown>;
6
+ };
7
+ lc: number;
8
+ type: string;
9
+ }
10
+ export interface LoadPreviousSessionResponse {
11
+ data: LoadPreviousSessionResponseItem[];
12
+ }
13
+ export interface SendMessageResponse {
14
+ output: string;
15
+ }
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,8 @@
1
+ export type CallbackFn = Function;
2
+ export type UnregisterFn = () => void;
3
+ export interface EventBus {
4
+ on: (eventName: string, fn: CallbackFn) => UnregisterFn;
5
+ off: (eventName: string, fn: CallbackFn) => void;
6
+ emit: <T = Event>(eventName: string, event?: T) => void;
7
+ }
8
+ export declare function createEventBus(): EventBus;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEventBus = createEventBus;
7
+ function createEventBus() {
8
+ const handlers = /* @__PURE__ */new Map();
9
+ function off(eventName, fn) {
10
+ const eventFns = handlers.get(eventName);
11
+ if (eventFns) {
12
+ eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
13
+ }
14
+ }
15
+ function on(eventName, fn) {
16
+ let eventFns = handlers.get(eventName);
17
+ if (!eventFns) {
18
+ eventFns = [fn];
19
+ } else {
20
+ eventFns.push(fn);
21
+ }
22
+ handlers.set(eventName, eventFns);
23
+ return () => off(eventName, fn);
24
+ }
25
+ function emit(eventName, event) {
26
+ const eventFns = handlers.get(eventName);
27
+ if (eventFns) {
28
+ eventFns.slice().forEach(async handler => {
29
+ await handler(event);
30
+ });
31
+ }
32
+ }
33
+ return {
34
+ on,
35
+ off,
36
+ emit
37
+ };
38
+ }
@@ -0,0 +1,32 @@
1
+ export function createEventBus() {
2
+ const handlers = /* @__PURE__ */ new Map();
3
+ function off(eventName, fn) {
4
+ const eventFns = handlers.get(eventName);
5
+ if (eventFns) {
6
+ eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
7
+ }
8
+ }
9
+ function on(eventName, fn) {
10
+ let eventFns = handlers.get(eventName);
11
+ if (!eventFns) {
12
+ eventFns = [fn];
13
+ } else {
14
+ eventFns.push(fn);
15
+ }
16
+ handlers.set(eventName, eventFns);
17
+ return () => off(eventName, fn);
18
+ }
19
+ function emit(eventName, event) {
20
+ const eventFns = handlers.get(eventName);
21
+ if (eventFns) {
22
+ eventFns.slice().forEach(async (handler) => {
23
+ await handler(event);
24
+ });
25
+ }
26
+ }
27
+ return {
28
+ on,
29
+ off,
30
+ emit
31
+ };
32
+ }
@@ -0,0 +1,2 @@
1
+ export * from './event-bus';
2
+ export * from './mount';
package/utils/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _eventBus = require("./event-bus");
7
+ Object.keys(_eventBus).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _eventBus[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _eventBus[key];
14
+ }
15
+ });
16
+ });
17
+ var _mount = require("./mount");
18
+ Object.keys(_mount).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _mount[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _mount[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./event-bus.mjs";
2
+ export * from "./mount.mjs";
@@ -0,0 +1 @@
1
+ export declare function createDefaultMountingTarget(mountingTarget: string): void;
package/utils/mount.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createDefaultMountingTarget = createDefaultMountingTarget;
7
+ function createDefaultMountingTarget(mountingTarget) {
8
+ const mountingTargetNode = document.querySelector(mountingTarget);
9
+ if (!mountingTargetNode) {
10
+ const generatedMountingTargetNode = document.createElement("div");
11
+ if (mountingTarget.startsWith("#")) {
12
+ generatedMountingTargetNode.id = mountingTarget.replace("#", "");
13
+ }
14
+ if (mountingTarget.startsWith(".")) {
15
+ generatedMountingTargetNode.classList.add(mountingTarget.replace(".", ""));
16
+ }
17
+ document.body.appendChild(generatedMountingTargetNode);
18
+ }
19
+ }
@@ -0,0 +1,13 @@
1
+ export function createDefaultMountingTarget(mountingTarget) {
2
+ const mountingTargetNode = document.querySelector(mountingTarget);
3
+ if (!mountingTargetNode) {
4
+ const generatedMountingTargetNode = document.createElement("div");
5
+ if (mountingTarget.startsWith("#")) {
6
+ generatedMountingTargetNode.id = mountingTarget.replace("#", "");
7
+ }
8
+ if (mountingTarget.startsWith(".")) {
9
+ generatedMountingTargetNode.classList.add(mountingTarget.replace(".", ""));
10
+ }
11
+ document.body.appendChild(generatedMountingTargetNode);
12
+ }
13
+ }