@stack-spot/ai-chat-widget 1.36.2 → 1.36.3

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 (52) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/StackspotAIWidget.d.ts.map +1 -1
  3. package/dist/StackspotAIWidget.js +2 -1
  4. package/dist/StackspotAIWidget.js.map +1 -1
  5. package/dist/app-metadata.json +3 -3
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/layout.css +1 -1
  11. package/dist/state/WidgetState.d.ts +1 -1
  12. package/dist/state/WidgetState.d.ts.map +1 -1
  13. package/dist/views/Agents/AgentDescription.d.ts.map +1 -1
  14. package/dist/views/Agents/AgentDescription.js +26 -14
  15. package/dist/views/Agents/AgentDescription.js.map +1 -1
  16. package/dist/views/Agents/dictionary.d.ts +1 -1
  17. package/dist/views/Agents/dictionary.d.ts.map +1 -1
  18. package/dist/views/Agents/dictionary.js +2 -0
  19. package/dist/views/Agents/dictionary.js.map +1 -1
  20. package/dist/views/Agents/styled.d.ts.map +1 -1
  21. package/dist/views/Agents/styled.js +14 -3
  22. package/dist/views/Agents/styled.js.map +1 -1
  23. package/dist/views/Agents/useAgentFavorites.js +3 -3
  24. package/dist/views/Agents/useAgentFavorites.js.map +1 -1
  25. package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
  26. package/dist/views/Chat/ChatMessage.js +15 -9
  27. package/dist/views/Chat/ChatMessage.js.map +1 -1
  28. package/dist/views/Chat/styled.d.ts.map +1 -1
  29. package/dist/views/Chat/styled.js +24 -0
  30. package/dist/views/Chat/styled.js.map +1 -1
  31. package/dist/views/MessageInput/UploadBar.d.ts.map +1 -1
  32. package/dist/views/MessageInput/UploadBar.js +5 -0
  33. package/dist/views/MessageInput/UploadBar.js.map +1 -1
  34. package/dist/views/Resources.d.ts +2 -0
  35. package/dist/views/Resources.d.ts.map +1 -0
  36. package/dist/views/Resources.js +56 -0
  37. package/dist/views/Resources.js.map +1 -0
  38. package/dist/views/Steps/dictionary.d.ts +1 -1
  39. package/package.json +2 -2
  40. package/src/StackspotAIWidget.tsx +2 -0
  41. package/src/app-metadata.json +3 -3
  42. package/src/index.ts +2 -1
  43. package/src/layout.css +1 -1
  44. package/src/state/WidgetState.ts +1 -1
  45. package/src/views/Agents/AgentDescription.tsx +64 -23
  46. package/src/views/Agents/dictionary.ts +2 -0
  47. package/src/views/Agents/styled.ts +14 -3
  48. package/src/views/Agents/useAgentFavorites.ts +3 -3
  49. package/src/views/Chat/ChatMessage.tsx +31 -19
  50. package/src/views/Chat/styled.ts +24 -0
  51. package/src/views/MessageInput/UploadBar.tsx +6 -0
  52. package/src/views/Resources.tsx +99 -0
@@ -0,0 +1,99 @@
1
+ import { Box, Flex, IconBox, Text } from '@citric/core'
2
+ import { Agent } from '@citric/icons'
3
+ import { Avatar } from '@citric/ui'
4
+ import { agentToolsClient } from '@stack-spot/portal-network'
5
+ import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
6
+ import { useEffect, useMemo } from 'react'
7
+ import { Accordion } from '../components/Accordion'
8
+ import { useWidget, useWidgetState } from '../context/hooks'
9
+ import { useRightPanel } from '../right-panel/hooks'
10
+ import { toolById } from '../utils/tools'
11
+ import { AgentDescription } from './Agents/AgentDescription'
12
+
13
+ export const Resources = () => {
14
+ const t = useTranslate(dictionary)
15
+ const panel = useWidgetState('panel')
16
+ const message = useWidgetState('currentMessageInPanel')
17
+ const { open } = useRightPanel()
18
+ const widget = useWidget()
19
+
20
+ useEffect(() => {
21
+ if (panel === 'resources' && message) open(
22
+ <ResourcesPanel key={message.messageId} />,
23
+ { title: t.title, description: t.description, onClose: () => widget.set('panel', undefined) },
24
+ )
25
+ }, [panel, t])
26
+
27
+ return null
28
+ }
29
+
30
+ const ResourcesPanel = () => {
31
+ const { chatId, messageId } = useWidgetState('currentMessageInPanel') ?? {}
32
+ const widget = useWidget()
33
+ const message = useMemo(() => {
34
+ const chat = widget.chatTabs.getAll().find(c => c.id === chatId)
35
+ return chat?.getMessages().find(m => m.id === messageId)?.getValue()
36
+ }, [messageId])
37
+
38
+ const [toolKits] = agentToolsClient.tools.useStatefulQuery({}, { enabled: !!message?.agent?.id })
39
+ const [agent] = agentToolsClient.agent.useStatefulQuery({ agentId: message?.agent?.id || '' },
40
+ { enabled: !!message?.agent?.id })
41
+ const tools = useMemo(() => message?.tools?.map(id => toolById(id, toolKits)), [messageId, toolKits])
42
+ const customTools = useMemo(() => message?.tools?.map(id => toolById(id, agent?.toolkits?.custom_toolkits)),
43
+ [messageId, agent?.toolkits?.custom_toolkits])
44
+
45
+ const [agentsTools] = agentToolsClient.agentsByIds.useStatefulQuery({ searchAgentsRequest:{ ids: message?.tools || [] } })
46
+ const hasAgentTool = useMemo(() => message?.tools?.some(id => agentsTools?.find((agent) => agent.id === id)), [messageId, toolKits])
47
+
48
+ const header = (image?: string, label?: string) => (
49
+ <Flex alignItems="center">
50
+ {image ? <Avatar size="xxs">
51
+ <img title={label} src={image} />
52
+ </Avatar> :
53
+ <IconBox appearance="circle" title={label} color="gray"><Agent /></IconBox>}
54
+ <Text ml={3}>{label}</Text>
55
+ </Flex>
56
+ )
57
+
58
+ return !!(tools?.length || customTools?.length) && (
59
+ <>
60
+ <>
61
+ {[...(tools || []), ...(customTools || [])].map(
62
+ (tool) =>
63
+ tool && (
64
+ <Box key={tool.id} mt={3}>
65
+ <Accordion header={header(tool?.image, tool?.name)}>
66
+ <Box sx={{ backgroundColor: 'light.400', m: '-10px', p: '16px' }}>
67
+ {tool?.description}
68
+ </Box>
69
+ </Accordion>
70
+ </Box>))}
71
+ </>
72
+ {
73
+ hasAgentTool &&
74
+ <>
75
+ {message?.tools?.map((id) => {
76
+ const agentTool = agentsTools?.find((agent) => agent.id === id)
77
+ return (
78
+ <Box key={id} mt={3}>
79
+ <Accordion header={header(agentTool?.avatar || undefined, agentTool?.name)}>
80
+ <AgentDescription agentId={id} />
81
+ </Accordion>
82
+ </Box>)},
83
+ )}
84
+ </>
85
+ }
86
+ </>
87
+ )
88
+ }
89
+
90
+ const dictionary = {
91
+ en: {
92
+ title: 'Resources',
93
+ description: 'These are the resources used to generate this answer.',
94
+ },
95
+ pt: {
96
+ title: 'Recursos',
97
+ description: 'Esses são os recursos usados pra gerar essa resposta.',
98
+ },
99
+ } satisfies Dictionary