@stack-spot/ai-chat-widget 2.10.0 → 2.11.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/dist/app-metadata.json +3 -3
- package/dist/components/Selector/index.d.ts +11 -2
- package/dist/components/Selector/index.d.ts.map +1 -1
- package/dist/components/Selector/index.js +18 -17
- package/dist/components/Selector/index.js.map +1 -1
- package/dist/components/form/DescribedCheckboxGroup.d.ts +3 -1
- package/dist/components/form/DescribedCheckboxGroup.d.ts.map +1 -1
- package/dist/components/form/DescribedCheckboxGroup.js +31 -19
- package/dist/components/form/DescribedCheckboxGroup.js.map +1 -1
- package/dist/views/Agents/AgentsTab.js.map +1 -1
- package/dist/views/KnowledgeSources.d.ts.map +1 -1
- package/dist/views/KnowledgeSources.js +31 -17
- package/dist/views/KnowledgeSources.js.map +1 -1
- package/dist/views/MessageInput/AgentSelector.d.ts.map +1 -1
- package/dist/views/MessageInput/AgentSelector.js +8 -6
- package/dist/views/MessageInput/AgentSelector.js.map +1 -1
- package/dist/views/MessageInput/QuickCommandSelector.d.ts.map +1 -1
- package/dist/views/MessageInput/QuickCommandSelector.js +12 -8
- package/dist/views/MessageInput/QuickCommandSelector.js.map +1 -1
- package/package.json +2 -2
- package/src/app-metadata.json +3 -3
- package/src/components/Selector/index.tsx +46 -33
- package/src/components/form/DescribedCheckboxGroup.tsx +61 -35
- package/src/views/Agents/AgentsTab.tsx +5 -5
- package/src/views/KnowledgeSources.tsx +59 -36
- package/src/views/MessageInput/AgentSelector.tsx +10 -8
- package/src/views/MessageInput/QuickCommandSelector.tsx +33 -23
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Icon } from '@stack-spot/citric-icons'
|
|
2
|
-
import { aiClient, workspaceAiClient } from '@stack-spot/portal-network'
|
|
3
|
-
import { QuickCommandResponse } from '@stack-spot/portal-network/api/ai'
|
|
2
|
+
import { AgentVisibilityLevel, aiClient, workspaceAiClient } from '@stack-spot/portal-network'
|
|
3
|
+
import { QuickCommandResponse, VisibilityLevelEnum } from '@stack-spot/portal-network/api/ai'
|
|
4
4
|
import { useCallback } from 'react'
|
|
5
5
|
import { Selector } from '../../components/Selector'
|
|
6
6
|
import { useCurrentChat, useCurrentChatState, useWidgetState } from '../../context/hooks'
|
|
@@ -8,17 +8,16 @@ import { quickCommandRegex } from '../../regex'
|
|
|
8
8
|
|
|
9
9
|
type QuickCommandResponseWithSpaceName = QuickCommandResponse & { spaceName?: string }
|
|
10
10
|
|
|
11
|
-
export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
11
|
+
export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
12
12
|
{ isTrial: boolean, inputRef: React.RefObject<HTMLTextAreaElement | HTMLInputElement> }) => {
|
|
13
13
|
const chat = useCurrentChat()
|
|
14
|
-
const isQuickCommandEnabled =
|
|
14
|
+
const isQuickCommandEnabled = useCurrentChatState('features').quickCommands
|
|
15
15
|
const spotId = useWidgetState('features')?.workspaceId
|
|
16
16
|
|
|
17
|
-
const useFavorites = () => aiClient.allQuickCommands.useQuery({ visibility: 'favorite' })
|
|
18
17
|
const [addFavorite, pendingAddFav] = aiClient.addFavoriteQuickCommand.useMutation()
|
|
19
18
|
const [removeFavorite, pendingRemoveFav] = aiClient.removeFavoriteQuickCommand.useMutation()
|
|
20
19
|
|
|
21
|
-
const addFavoriteQc = async(idOrSlug?: string) => {
|
|
20
|
+
const addFavoriteQc = async (idOrSlug?: string) => {
|
|
22
21
|
try {
|
|
23
22
|
await addFavorite({ slug: idOrSlug || '' })
|
|
24
23
|
await aiClient.allQuickCommands.invalidate()
|
|
@@ -32,7 +31,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
32
31
|
const onAddFavorite = (idOrSlug?: string) => new Promise<boolean>(async (resolve, reject) => {
|
|
33
32
|
try {
|
|
34
33
|
await addFavoriteQc(idOrSlug)
|
|
35
|
-
if (!pendingAddFav){
|
|
34
|
+
if (!pendingAddFav) {
|
|
36
35
|
resolve(true)
|
|
37
36
|
}
|
|
38
37
|
|
|
@@ -40,10 +39,10 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
40
39
|
// eslint-disable-next-line no-console
|
|
41
40
|
console.error(error)
|
|
42
41
|
reject(error)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
42
|
+
}
|
|
43
|
+
})
|
|
45
44
|
|
|
46
|
-
const removeFavoriteQc = async(idOrSlug?: string) => {
|
|
45
|
+
const removeFavoriteQc = async (idOrSlug?: string) => {
|
|
47
46
|
try {
|
|
48
47
|
await removeFavorite({ slug: idOrSlug || '' })
|
|
49
48
|
await aiClient.allQuickCommands.invalidate()
|
|
@@ -57,7 +56,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
57
56
|
const onRemoveFavorite = (idOrSlug?: string) => new Promise<boolean>(async (resolve, reject) => {
|
|
58
57
|
try {
|
|
59
58
|
await removeFavoriteQc(idOrSlug)
|
|
60
|
-
if (!pendingRemoveFav){
|
|
59
|
+
if (!pendingRemoveFav) {
|
|
61
60
|
resolve(true)
|
|
62
61
|
}
|
|
63
62
|
|
|
@@ -65,9 +64,9 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
65
64
|
// eslint-disable-next-line no-console
|
|
66
65
|
console.error(error)
|
|
67
66
|
reject(error)
|
|
68
|
-
}
|
|
67
|
+
}
|
|
69
68
|
})
|
|
70
|
-
|
|
69
|
+
|
|
71
70
|
const onSelectItem = useCallback((qc: QuickCommandResponseWithSpaceName) => {
|
|
72
71
|
const newValue = `/${qc.slug}`
|
|
73
72
|
chat.set('nextMessage', newValue)
|
|
@@ -77,12 +76,19 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
77
76
|
inputRef.current.focus()
|
|
78
77
|
}, [chat, inputRef])
|
|
79
78
|
|
|
80
|
-
const getQuickCommands = () => {
|
|
79
|
+
const getQuickCommands = ({ filter, visibility }: { filter?: string, visibility?: AgentVisibilityLevel[] | VisibilityLevelEnum[] }) => {
|
|
80
|
+
|
|
81
81
|
if (spotId) {
|
|
82
|
-
return workspaceAiClient.getQCFromWorkspaceAi.useQuery({ workspaceId: spotId })
|
|
82
|
+
return { data: workspaceAiClient.getQCFromWorkspaceAi.useQuery({ workspaceId: spotId, name: filter }) }
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const quickCommands = aiClient.
|
|
85
|
+
const [quickCommands, { fetchNextPage, hasNextPage }] = aiClient.allQuickCommandsV3.useInfiniteQuery({
|
|
86
|
+
order: 'a-to-z',
|
|
87
|
+
visibilityList: visibility as VisibilityLevelEnum[],
|
|
88
|
+
name: filter,
|
|
89
|
+
page: 1, size: 20,
|
|
90
|
+
})
|
|
91
|
+
|
|
86
92
|
const quickCommandsFiltered = quickCommands.filter(
|
|
87
93
|
(qc) => qc.visibility_level.toLowerCase() !== 'workspace',
|
|
88
94
|
)
|
|
@@ -92,11 +98,17 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
92
98
|
})
|
|
93
99
|
|
|
94
100
|
const workspaceQuickCommandsWithWorkspaceName: QuickCommandResponseWithSpaceName[] =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
workspaceQuickCommands.flatMap(({ qcs, space_name }) =>
|
|
102
|
+
qcs?.map((qc) => ({ ...qc, spaceName: space_name })),
|
|
103
|
+
) as QuickCommandResponseWithSpaceName[]
|
|
104
|
+
|
|
105
|
+
const filteredWorkspaceQuickCommand = filter ? workspaceQuickCommandsWithWorkspaceName?.filter((qc) =>
|
|
106
|
+
qc.name?.toLowerCase().includes(filter!)) : workspaceQuickCommandsWithWorkspaceName
|
|
98
107
|
|
|
99
|
-
|
|
108
|
+
const data = !visibility ? [...quickCommandsFiltered, ...filteredWorkspaceQuickCommand] : (
|
|
109
|
+
visibility.includes('workspace') ? filteredWorkspaceQuickCommand : quickCommandsFiltered
|
|
110
|
+
)
|
|
111
|
+
return { data, fetchNextPage: fetchNextPage, hasNextPage }
|
|
100
112
|
}
|
|
101
113
|
|
|
102
114
|
const QuickCommandItem = ({ slug, description, spaceName }: QuickCommandResponseWithSpaceName) => <>
|
|
@@ -107,9 +119,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
|
|
|
107
119
|
|
|
108
120
|
return <Selector
|
|
109
121
|
inputRef={inputRef}
|
|
110
|
-
favorite={{
|
|
111
|
-
useFavorites, onAddFavorite, onRemoveFavorite, favoriteIsSlug: true,
|
|
112
|
-
}}
|
|
122
|
+
favorite={{ onAddFavorite, onRemoveFavorite, favoriteIsSlug: true }}
|
|
113
123
|
selectorConfig={{
|
|
114
124
|
resourceName: 'Quick Command',
|
|
115
125
|
shortcut: '/',
|