@inploi/plugin-chatbot 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/cdn/index.js +56 -0
  2. package/package.json +14 -3
  3. package/.env +0 -2
  4. package/.env.example +0 -2
  5. package/.env.test +0 -2
  6. package/.eslintrc.cjs +0 -10
  7. package/CHANGELOG.md +0 -91
  8. package/bunfig.toml +0 -2
  9. package/happydom.ts +0 -10
  10. package/index.html +0 -29
  11. package/playwright.config.ts +0 -82
  12. package/postcss.config.cjs +0 -7
  13. package/src/chatbot.api.ts +0 -46
  14. package/src/chatbot.constants.ts +0 -9
  15. package/src/chatbot.css +0 -93
  16. package/src/chatbot.dom.ts +0 -28
  17. package/src/chatbot.idb.ts +0 -17
  18. package/src/chatbot.state.ts +0 -114
  19. package/src/chatbot.ts +0 -59
  20. package/src/chatbot.utils.ts +0 -56
  21. package/src/index.cdn.ts +0 -12
  22. package/src/index.dev.ts +0 -31
  23. package/src/index.ts +0 -1
  24. package/src/interpreter/interpreter.test.ts +0 -69
  25. package/src/interpreter/interpreter.ts +0 -249
  26. package/src/mocks/browser.ts +0 -5
  27. package/src/mocks/example.flows.ts +0 -801
  28. package/src/mocks/handlers.ts +0 -57
  29. package/src/style/palette.test.ts +0 -20
  30. package/src/style/palette.ts +0 -69
  31. package/src/ui/chat-bubble.tsx +0 -51
  32. package/src/ui/chat-input/chat-input.boolean.tsx +0 -62
  33. package/src/ui/chat-input/chat-input.file.tsx +0 -213
  34. package/src/ui/chat-input/chat-input.multiple-choice.tsx +0 -117
  35. package/src/ui/chat-input/chat-input.text.tsx +0 -111
  36. package/src/ui/chat-input/chat-input.tsx +0 -81
  37. package/src/ui/chatbot-header.tsx +0 -95
  38. package/src/ui/chatbot.tsx +0 -94
  39. package/src/ui/input-error.tsx +0 -33
  40. package/src/ui/job-application-content.tsx +0 -144
  41. package/src/ui/job-application-messages.tsx +0 -64
  42. package/src/ui/loading-indicator.tsx +0 -37
  43. package/src/ui/send-button.tsx +0 -27
  44. package/src/ui/transition.tsx +0 -1
  45. package/src/ui/typing-indicator.tsx +0 -12
  46. package/src/ui/useChatService.ts +0 -67
  47. package/src/ui/useFocus.ts +0 -10
  48. package/src/vite-env.d.ts +0 -1
  49. package/tailwind.config.ts +0 -119
  50. package/tests/integration.spec.ts +0 -19
  51. package/tests/test.ts +0 -22
  52. package/tsconfig.json +0 -33
  53. package/tsconfig.node.json +0 -10
  54. package/types.d.ts +0 -2
  55. package/vite.config.ts +0 -18
  56. /package/{public → cdn}/mockServiceWorker.js +0 -0
@@ -1,27 +0,0 @@
1
- import clsx from 'clsx';
2
- import { ComponentProps } from 'preact';
3
-
4
- export const SendButton = ({ class: className, ...props }: ComponentProps<'button'>) => (
5
- <button
6
- class={clsx(
7
- 'p-2 flex-shrink-0 bg-accent-7 active:bg-accent-10 active:text-accent-4 rounded-full text-lowest pointer-coarse:touch-hitbox disabled:opacity-50 disabled:cursor-not-allowed',
8
- className,
9
- )}
10
- {...props}
11
- >
12
- <svg
13
- class="block"
14
- width="16"
15
- height="16"
16
- viewBox="0 0 16 16"
17
- fill="transparent"
18
- stroke="currentColor"
19
- stroke-linecap="round"
20
- stroke-width="2"
21
- >
22
- <title>Send</title>
23
- <path d="M3.5 7.5L8 3L12.5 7.5" />
24
- <path d="M8 4V13" />
25
- </svg>
26
- </button>
27
- );
@@ -1 +0,0 @@
1
- export type TransitionState = 'entering' | 'entered' | 'exiting' | 'exited';
@@ -1,12 +0,0 @@
1
- import clsx from 'clsx';
2
- import { ComponentProps } from 'react';
3
-
4
- export const TypingIndicator = ({ className, ...props }: ComponentProps<'div'>) => {
5
- return (
6
- <div class={clsx('flex gap-1 p-4', className)} {...props}>
7
- {Array.from({ length: 3 }, (_, i) => (
8
- <div class="h-1.5 w-1.5 rounded-full bg-accent-7 animate-bounce" style={{ animationDelay: `${-i * 200}ms` }} />
9
- ))}
10
- </div>
11
- );
12
- };
@@ -1,67 +0,0 @@
1
- import { useMemo, useRef, useState } from 'preact/hooks';
2
- import { match } from 'ts-pattern';
3
- import { application } from '~/chatbot.state';
4
- import { AbortedError } from '~/chatbot.utils';
5
- import { ChatService } from '~/interpreter/interpreter';
6
-
7
- import { SubmitSuccessFn } from './chat-input/chat-input';
8
-
9
- const TYPING_SPEED_MS_PER_CHARACTER = 25;
10
-
11
- export const useChatService = () => {
12
- const chatRef = useRef<HTMLDivElement>(null);
13
- const [isBotTyping, setIsBotTyping] = useState(false);
14
- const [onSubmitSuccessFn, setOnSubmitSuccessFn] = useState<SubmitSuccessFn>(() => () => {});
15
- const scrollToEnd = useMemo(
16
- () => (options?: Omit<ScrollToOptions, 'top'>) =>
17
- chatRef.current?.scrollTo({ top: chatRef.current.scrollHeight, ...options }),
18
- [chatRef],
19
- );
20
-
21
- const chatService = useMemo(() => {
22
- const chatService: ChatService = {
23
- send: async ({ message, signal, groupId }) => {
24
- await match(message)
25
- /** Delay sending and add typing indicator if bot is sending a message */
26
- .with({ author: 'bot', type: 'text' }, async message => {
27
- if (signal?.aborted) throw new AbortedError();
28
- setIsBotTyping(true);
29
- const typingTime = Math.max(20, message.text.length) * TYPING_SPEED_MS_PER_CHARACTER;
30
- await new Promise(resolve => {
31
- return setTimeout(resolve, typingTime, { signal });
32
- });
33
- setIsBotTyping(false);
34
- })
35
- .otherwise(async () => void 0);
36
-
37
- /** The signal could have been aborted while typing */
38
- if (signal?.aborted) throw new AbortedError();
39
- application.addMessage(message, groupId);
40
- },
41
- input: async ({ input, signal }) => {
42
- if (signal?.aborted) throw new AbortedError();
43
- application.setInput(input);
44
-
45
- return await new Promise(resolve => {
46
- const submitFunction: SubmitSuccessFn = submission => {
47
- if (signal?.aborted) throw new AbortedError();
48
- application.setInput(undefined);
49
- application.setSubmission(input.key, submission);
50
- resolve(submission as any);
51
- };
52
- setOnSubmitSuccessFn(() => submitFunction);
53
- });
54
- },
55
- };
56
-
57
- return chatService;
58
- }, []);
59
-
60
- return {
61
- chatRef,
62
- chatService,
63
- isBotTyping,
64
- onSubmitSuccessFn,
65
- scrollToEnd,
66
- };
67
- };
@@ -1,10 +0,0 @@
1
- import { useEffect, useRef } from 'preact/hooks';
2
-
3
- export const useFocusOnMount = () => {
4
- const focusRef = useRef<any>(null);
5
- useEffect(() => {
6
- focusRef.current?.focus();
7
- }, []);
8
-
9
- return focusRef;
10
- };
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
@@ -1,119 +0,0 @@
1
- // @ts-expect-error - there aren't any typings for this
2
- import touchPlugin from 'tailwindcss-touch';
3
- import plugin from 'tailwindcss/plugin';
4
- import { Config } from 'tailwindcss/types/config';
5
-
6
- const config: Config = {
7
- content: ['./**/*.{tsx,ts}'],
8
- theme: {
9
- colors: {
10
- transparent: 'transparent',
11
- lowest: 'hsl(var(--i-lowest) / <alpha-value>)',
12
- neutral: {
13
- 1: 'hsl(var(--i-n-1) / <alpha-value>)',
14
- 2: 'hsl(var(--i-n-2) / <alpha-value>)',
15
- 3: 'hsl(var(--i-n-3) / <alpha-value>)',
16
- 4: 'hsl(var(--i-n-4) / <alpha-value>)',
17
- 5: 'hsl(var(--i-n-5) / <alpha-value>)',
18
- 6: 'hsl(var(--i-n-6) / <alpha-value>)',
19
- 7: 'hsl(var(--i-n-7) / <alpha-value>)',
20
- 8: 'hsl(var(--i-n-8) / <alpha-value>)',
21
- 9: 'hsl(var(--i-n-9) / <alpha-value>)',
22
- 10: 'hsl(var(--i-n-10) / <alpha-value>)',
23
- 11: 'hsl(var(--i-n-11) / <alpha-value>)',
24
- 12: 'hsl(var(--i-n-12) / <alpha-value>)',
25
- },
26
-
27
- accent: {
28
- 1: 'hsl(var(--i-a-1) / <alpha-value>)',
29
- 2: 'hsl(var(--i-a-2) / <alpha-value>)',
30
- 3: 'hsl(var(--i-a-3) / <alpha-value>)',
31
- 4: 'hsl(var(--i-a-4) / <alpha-value>)',
32
- 5: 'hsl(var(--i-a-5) / <alpha-value>)',
33
- 6: 'hsl(var(--i-a-6) / <alpha-value>)',
34
- 7: 'hsl(var(--i-a-7) / <alpha-value>)',
35
- 8: 'hsl(var(--i-a-8) / <alpha-value>)',
36
- 9: 'hsl(var(--i-a-9) / <alpha-value>)',
37
- 10: 'hsl(var(--i-a-10) / <alpha-value>)',
38
- 11: 'hsl(var(--i-a-11) / <alpha-value>)',
39
- 12: 'hsl(var(--i-a-12) / <alpha-value>)',
40
- },
41
-
42
- error: {
43
- 1: 'hsl(var(--i-e-1) / <alpha-value>)',
44
- 2: 'hsl(var(--i-e-2) / <alpha-value>)',
45
- 3: 'hsl(var(--i-e-3) / <alpha-value>)',
46
- 4: 'hsl(var(--i-e-4) / <alpha-value>)',
47
- 5: 'hsl(var(--i-e-5) / <alpha-value>)',
48
- 6: 'hsl(var(--i-e-6) / <alpha-value>)',
49
- 7: 'hsl(var(--i-e-7) / <alpha-value>)',
50
- 8: 'hsl(var(--i-e-8) / <alpha-value>)',
51
- 9: 'hsl(var(--i-e-9) / <alpha-value>)',
52
- 10: 'hsl(var(--i-e-10) / <alpha-value>)',
53
- 11: 'hsl(var(--i-e-11) / <alpha-value>)',
54
- 12: 'hsl(var(--i-e-12) / <alpha-value>)',
55
- },
56
- },
57
-
58
- extend: {
59
- boxShadow: {
60
- 'surface-sm': '0px 3px 3px 0px hsl(var(--i-a-12) / 0.03), 0px 4px 4px 0px hsl(var(--i-a-12) / 0.02)',
61
- 'surface-md':
62
- '0px 3px 3px 0px hsl(var(--i-a-12) / 0.03), 0px 6px 4px 0px hsl(var(--i-a-12) / 0.02), 0px 6px 4px 0px hsl(var(--i-a-12) / 0.01)',
63
- 'surface-lg':
64
- '0px 3px 3px 0px hsl(var(--i-a-12) / 0.03), 0px 6px 4px 0px hsl(var(--i-a-12) / 0.02), 0px 11px 4px 0px hsl(var(--i-a-12) / 0.01), 0px 32px 24px -12px hsl(var(--i-a-12) / 0.06)',
65
- },
66
-
67
- keyframes: {
68
- overlayShow: {
69
- from: { opacity: '0' },
70
- to: { opacity: '1' },
71
- },
72
- },
73
- transitionTimingFunction: {
74
- 'expo-out': 'cubic-bezier(0.16, 1, 0.3, 1)',
75
- },
76
- animation: {
77
- overlayShow: 'overlayShow 150ms cubic-bezier(0.16, 1, 0.3, 1)',
78
- },
79
- },
80
- },
81
- corePlugins: {
82
- preflight: false,
83
- },
84
-
85
- plugins: [
86
- touchPlugin(),
87
- plugin(({ addUtilities }) => {
88
- addUtilities({
89
- '.gutter-stable': {
90
- 'scrollbar-gutter': 'stable',
91
- },
92
- '.hide-scrollbars': {
93
- '&::-webkit-scrollbar': {
94
- display: 'none',
95
- },
96
- scrollbarWidth: 'none',
97
- '-ms-overflow-style': 'none',
98
- },
99
- '.touch-hitbox': {
100
- '&::before': {
101
- content: "''",
102
- position: 'absolute',
103
- display: 'block',
104
- top: '50%',
105
- left: '50%',
106
- transform: 'translate(-50%, -50%)',
107
- width: '100%',
108
- height: '100%',
109
- minHeight: '44px',
110
- minWidth: '44px',
111
- zIndex: '9999',
112
- },
113
- },
114
- });
115
- }),
116
- ],
117
- };
118
-
119
- export default config;
@@ -1,19 +0,0 @@
1
- import { flowHandler } from '~/mocks/handlers';
2
-
3
- import { expect, test } from './test';
4
-
5
- test('when backend responds with correct data, can start application', async ({ page, worker }) => {
6
- await worker.use(flowHandler.success);
7
- await page.goto('/', { waitUntil: 'domcontentloaded' });
8
-
9
- await page.getByRole('button', { name: 'Apply for job Test flow' }).click();
10
- await expect(page.getByText('Text node')).toBeVisible();
11
- });
12
-
13
- test('when backend responds with malformed data, user sees error message', async ({ page, worker }) => {
14
- await worker.use(flowHandler.invalid_payload);
15
- await page.goto('/', { waitUntil: 'domcontentloaded' });
16
-
17
- await page.getByRole('button', { name: 'Apply for job Test flow' }).click();
18
- await expect(page.getByText('Text node')).toBeVisible();
19
- });
package/tests/test.ts DELETED
@@ -1,22 +0,0 @@
1
- import { test as base, expect } from '@playwright/test';
2
- import { http } from 'msw';
3
- import type { Config, MockServiceWorker } from 'playwright-msw';
4
- import { createWorkerFixture } from 'playwright-msw';
5
-
6
- const testFactory = (config?: Config) =>
7
- base.extend<{
8
- worker: MockServiceWorker;
9
- http: typeof http;
10
- }>({
11
- worker: createWorkerFixture(
12
- [
13
- // default handlers go here
14
- ],
15
- config,
16
- ),
17
- http,
18
- });
19
-
20
- const test = testFactory();
21
-
22
- export { test, expect };
package/tsconfig.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
-
9
- /* Bundler mode */
10
- "moduleResolution": "bundler",
11
- "allowImportingTsExtensions": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "noEmit": true,
15
- "jsx": "react-jsx",
16
- "jsxImportSource": "preact",
17
-
18
- /* Linting */
19
- "strict": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "noUncheckedIndexedAccess": true,
22
- "types": ["bun-types"],
23
-
24
- "baseUrl": ".",
25
- "paths": {
26
- "react": ["./node_modules/preact/compat/"],
27
- "react-dom": ["./node_modules/preact/compat/"],
28
- "~/*": ["./src/*"]
29
- }
30
- },
31
- "include": ["src", "tests", "playwright.config.ts", ".eslintrc.cjs", "tailwind.config.ts", "vite.config.ts"],
32
- "references": [{ "path": "./tsconfig.node.json" }]
33
- }
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "skipLibCheck": true,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "allowSyntheticDefaultImports": true
8
- },
9
- "include": ["vite.config.ts"]
10
- }
package/types.d.ts DELETED
@@ -1,2 +0,0 @@
1
- /// <reference lib="dom" />
2
- /// <reference lib="dom.iterable" />
package/vite.config.ts DELETED
@@ -1,18 +0,0 @@
1
- import preact from '@preact/preset-vite';
2
- import { resolve } from 'path';
3
- import { visualizer } from 'rollup-plugin-visualizer';
4
- import { defineConfig } from 'vite';
5
- import tsconfigPaths from 'vite-tsconfig-paths';
6
-
7
- // https://vitejs.dev/config/
8
- export default defineConfig({
9
- build: {
10
- lib: {
11
- formats: ['es'],
12
- entry: resolve(__dirname, 'src/index.cdn.ts'),
13
- name: 'inploi.chatbotPlugin',
14
- },
15
- rollupOptions: {},
16
- },
17
- plugins: [preact(), visualizer(), tsconfigPaths()],
18
- });
File without changes