app-tutor-ai-consumer 1.32.2 → 1.33.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.
- package/CHANGELOG.md +8 -0
- package/config/vitest/__mocks__/sparkie.tsx +1 -1
- package/package.json +2 -2
- package/src/@types/index.d.ts +3 -2
- package/src/config/tanstack/query-provider.tsx +7 -3
- package/src/index.backup.tsx +61 -0
- package/src/index.tsx +64 -11
- package/src/lib/components/markdownrenderer/markdownrenderer.tsx +1 -1
- package/src/lib/hooks/use-response-timeout/index.ts +1 -0
- package/src/lib/hooks/use-response-timeout/use-response-timeout.tsx +42 -0
- package/src/modules/global-providers/global-providers.tsx +1 -6
- package/src/modules/messages/__tests__/imessage-with-sender-data.builder.ts +1 -1
- package/src/modules/messages/hooks/use-subscribe-message-received-event/use-subscribe-message-received-event.tsx +119 -54
- package/src/modules/messages/service.direct.ts +1 -1
- package/src/modules/messages/service.ts +3 -2
- package/src/modules/messages/types.ts +1 -1
- package/src/modules/messages/utils/set-messages-cache/utils.ts +1 -1
- package/src/modules/sparkie/hooks/use-init-sparkie/use-init-sparkie.tsx +20 -6
- package/src/modules/sparkie/service.ts +2 -3
- package/src/modules/sparkie/store/index.ts +1 -0
- package/src/modules/sparkie/store/sparkie-state.atom.ts +13 -0
- package/src/modules/widget/components/chat-page/chat-page.tsx +63 -15
- package/src/modules/widget/components/constants.tsx +3 -1
- package/src/modules/widget/components/container/container.tsx +0 -14
- package/src/modules/widget/components/error-page/error-page.spec.tsx +17 -0
- package/src/modules/widget/components/error-page/error-page.tsx +10 -0
- package/src/modules/widget/components/error-page/index.ts +1 -0
- package/src/modules/widget/components/starter-page/starter-page-actions/index.ts +1 -0
- package/src/modules/widget/components/starter-page/starter-page-actions/starter-page-actions.spec.tsx +68 -0
- package/src/modules/widget/components/starter-page/starter-page-actions/starter-page-actions.tsx +33 -0
- package/src/modules/widget/components/starter-page/starter-page-content/index.ts +1 -0
- package/src/modules/widget/components/starter-page/starter-page-content/starter-page-content.spec.tsx +62 -0
- package/src/modules/widget/components/starter-page/starter-page-content/starter-page-content.tsx +57 -0
- package/src/modules/widget/components/starter-page/starter-page-header/index.ts +1 -0
- package/src/modules/widget/components/starter-page/starter-page-header/starter-page-header.spec.tsx +41 -0
- package/src/modules/widget/components/starter-page/starter-page-header/starter-page-header.tsx +34 -0
- package/src/modules/widget/components/starter-page/starter-page.tsx +27 -49
- package/src/modules/widget/store/widget-tabs.atom.ts +31 -1
- package/src/types.ts +9 -0
- package/src/wrapper.tsx +32 -0
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { atom, useAtom, useAtomValue } from 'jotai'
|
|
2
|
+
import { atomWithDefault } from 'jotai/utils'
|
|
2
3
|
|
|
4
|
+
import { sparkieStateAtom } from '../../sparkie/store'
|
|
3
5
|
import type { CurrentTabKey } from '../components'
|
|
4
6
|
|
|
7
|
+
import { widgetSettingsConfigAgentParentAtom } from './widget-settings-config.atom'
|
|
8
|
+
|
|
5
9
|
export type WidgetTabsProps = {
|
|
6
10
|
currentTab: CurrentTabKey
|
|
7
11
|
history: Set<CurrentTabKey>
|
|
@@ -12,7 +16,33 @@ const INITIAL_PROPS: WidgetTabsProps = {
|
|
|
12
16
|
history: new Set(['starter'])
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
export const widgetTabsAtom =
|
|
19
|
+
export const widgetTabsAtom = atomWithDefault<WidgetTabsProps>((get) => {
|
|
20
|
+
const sparkieState = get(sparkieStateAtom)
|
|
21
|
+
const isAgentMode = get(widgetSettingsConfigAgentParentAtom)
|
|
22
|
+
|
|
23
|
+
if (!isAgentMode) return INITIAL_PROPS
|
|
24
|
+
|
|
25
|
+
switch (sparkieState) {
|
|
26
|
+
case 'idle':
|
|
27
|
+
case 'initializing':
|
|
28
|
+
return {
|
|
29
|
+
currentTab: 'loading',
|
|
30
|
+
history: new Set(['loading'])
|
|
31
|
+
}
|
|
32
|
+
case 'initialized':
|
|
33
|
+
return {
|
|
34
|
+
currentTab: 'chat',
|
|
35
|
+
history: new Set(['chat'])
|
|
36
|
+
}
|
|
37
|
+
case 'failed':
|
|
38
|
+
return {
|
|
39
|
+
currentTab: 'error',
|
|
40
|
+
history: new Set(['error'])
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
return INITIAL_PROPS
|
|
44
|
+
}
|
|
45
|
+
})
|
|
16
46
|
|
|
17
47
|
export const setWidgetTabsAtom = atom(
|
|
18
48
|
(get) => get(widgetTabsAtom),
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import type { Root } from 'react-dom/client'
|
|
3
|
+
|
|
1
4
|
import type { ILanguages } from './config/i18n'
|
|
2
5
|
|
|
3
6
|
export type StartTutorWidgetProps = {
|
|
@@ -68,3 +71,9 @@ export interface ICustomEvent<T = object> {
|
|
|
68
71
|
handler: (listener: EventListenerOrEventListenerObject) => () => void | Promise<void>
|
|
69
72
|
dispatch: <D = unknown>(detail?: D) => void
|
|
70
73
|
}
|
|
74
|
+
|
|
75
|
+
export type WidgetInstance = {
|
|
76
|
+
root: Root
|
|
77
|
+
container: HTMLElement
|
|
78
|
+
queryClient: QueryClient
|
|
79
|
+
}
|
package/src/wrapper.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
import { Main } from './main'
|
|
4
|
+
import { SparkieService } from './modules/sparkie'
|
|
5
|
+
import { useSparkieStateAtom } from './modules/sparkie/store'
|
|
6
|
+
import type { WidgetSettingProps } from './types'
|
|
7
|
+
|
|
8
|
+
export type WrapperProps = {
|
|
9
|
+
settings: WidgetSettingProps
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function Wrapper({ settings }: WrapperProps) {
|
|
13
|
+
const [, setSparkieState] = useSparkieStateAtom()
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
SparkieService.initSparkie({
|
|
17
|
+
token: settings?.hotmartToken,
|
|
18
|
+
skipPresenceSetup: true,
|
|
19
|
+
retryOptions: {
|
|
20
|
+
maxRetries: 5,
|
|
21
|
+
retryDelay: 2000,
|
|
22
|
+
backoffMultiplier: 1.5
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
.then((result) => setSparkieState(result ? 'initialized' : 'failed'))
|
|
26
|
+
.catch(() => setSparkieState('failed'))
|
|
27
|
+
}, [setSparkieState, settings?.hotmartToken])
|
|
28
|
+
|
|
29
|
+
return <Main settings={settings} />
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default Wrapper
|