@stack-spot/ai-chat-widget 1.27.1 → 1.28.1-beta.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 (100) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/app-metadata.json +3 -3
  3. package/dist/chat-interceptors/quick-commands.d.ts.map +1 -1
  4. package/dist/chat-interceptors/quick-commands.js +19 -1
  5. package/dist/chat-interceptors/quick-commands.js.map +1 -1
  6. package/dist/components/AgentCard/dictionary.d.ts +4 -2
  7. package/dist/components/AgentCard/dictionary.d.ts.map +1 -1
  8. package/dist/components/AgentCard/dictionary.js +4 -2
  9. package/dist/components/AgentCard/dictionary.js.map +1 -1
  10. package/dist/components/Selector/index.d.ts +2 -2
  11. package/dist/components/Selector/index.d.ts.map +1 -1
  12. package/dist/components/Selector/index.js +2 -2
  13. package/dist/components/Selector/index.js.map +1 -1
  14. package/dist/layout.css +17 -0
  15. package/dist/state/types.d.ts +1 -1
  16. package/dist/state/types.d.ts.map +1 -1
  17. package/dist/utils/tools.d.ts +2 -2
  18. package/dist/utils/tools.d.ts.map +1 -1
  19. package/dist/utils/tools.js +3 -6
  20. package/dist/utils/tools.js.map +1 -1
  21. package/dist/utils/upload/UploadManager.d.ts +2 -0
  22. package/dist/utils/upload/UploadManager.d.ts.map +1 -1
  23. package/dist/utils/upload/UploadManager.js +32 -25
  24. package/dist/utils/upload/UploadManager.js.map +1 -1
  25. package/dist/utils/upload/use-paste-upload.d.ts +8 -0
  26. package/dist/utils/upload/use-paste-upload.d.ts.map +1 -0
  27. package/dist/utils/upload/use-paste-upload.js +19 -0
  28. package/dist/utils/upload/use-paste-upload.js.map +1 -0
  29. package/dist/views/Agents/AgentDescription.d.ts +2 -9
  30. package/dist/views/Agents/AgentDescription.d.ts.map +1 -1
  31. package/dist/views/Agents/AgentDescription.js +12 -9
  32. package/dist/views/Agents/AgentDescription.js.map +1 -1
  33. package/dist/views/Agents/AgentsPanel.d.ts.map +1 -1
  34. package/dist/views/Agents/AgentsPanel.js +11 -11
  35. package/dist/views/Agents/AgentsPanel.js.map +1 -1
  36. package/dist/views/Agents/AgentsTab.d.ts +2 -2
  37. package/dist/views/Agents/AgentsTab.d.ts.map +1 -1
  38. package/dist/views/Agents/AgentsTab.js +6 -6
  39. package/dist/views/Agents/AgentsTab.js.map +1 -1
  40. package/dist/views/Agents/useAgentFavorites.d.ts +1 -1
  41. package/dist/views/Agents/useAgentFavorites.js +4 -4
  42. package/dist/views/Agents/useAgentFavorites.js.map +1 -1
  43. package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
  44. package/dist/views/Chat/ChatMessage.js +3 -3
  45. package/dist/views/Chat/ChatMessage.js.map +1 -1
  46. package/dist/views/ChatHistory/HistoryItem.d.ts.map +1 -1
  47. package/dist/views/ChatHistory/HistoryItem.js +8 -5
  48. package/dist/views/ChatHistory/HistoryItem.js.map +1 -1
  49. package/dist/views/ChatHistory/utils.d.ts +0 -6
  50. package/dist/views/ChatHistory/utils.d.ts.map +1 -1
  51. package/dist/views/ChatHistory/utils.js +1 -16
  52. package/dist/views/ChatHistory/utils.js.map +1 -1
  53. package/dist/views/Home/CustomAgent.js +3 -3
  54. package/dist/views/Home/CustomAgent.js.map +1 -1
  55. package/dist/views/MessageInput/AgentSelector.js +4 -4
  56. package/dist/views/MessageInput/AgentSelector.js.map +1 -1
  57. package/dist/views/MessageInput/ButtonAgent.js +2 -2
  58. package/dist/views/MessageInput/ButtonAgent.js.map +1 -1
  59. package/dist/views/MessageInput/QuickCommandSelector.js +4 -4
  60. package/dist/views/MessageInput/QuickCommandSelector.js.map +1 -1
  61. package/dist/views/MessageInput/UploadDragNDrop.d.ts +14 -0
  62. package/dist/views/MessageInput/UploadDragNDrop.d.ts.map +1 -0
  63. package/dist/views/MessageInput/UploadDragNDrop.js +52 -0
  64. package/dist/views/MessageInput/UploadDragNDrop.js.map +1 -0
  65. package/dist/views/MessageInput/dictionary.d.ts +1 -1
  66. package/dist/views/MessageInput/dictionary.d.ts.map +1 -1
  67. package/dist/views/MessageInput/dictionary.js +9 -0
  68. package/dist/views/MessageInput/dictionary.js.map +1 -1
  69. package/dist/views/MessageInput/index.d.ts.map +1 -1
  70. package/dist/views/MessageInput/index.js +13 -1
  71. package/dist/views/MessageInput/index.js.map +1 -1
  72. package/dist/views/Tools.js +3 -3
  73. package/dist/views/Tools.js.map +1 -1
  74. package/dist/views/Workspaces/WorkspacesTab.js +1 -1
  75. package/package.json +2 -2
  76. package/src/app-metadata.json +3 -3
  77. package/src/chat-interceptors/quick-commands.ts +25 -3
  78. package/src/components/AgentCard/dictionary.ts +4 -2
  79. package/src/components/Selector/index.tsx +4 -5
  80. package/src/layout.css +17 -0
  81. package/src/state/types.ts +1 -1
  82. package/src/utils/tools.ts +5 -7
  83. package/src/utils/upload/UploadManager.ts +32 -23
  84. package/src/utils/upload/use-paste-upload.tsx +30 -0
  85. package/src/views/Agents/AgentDescription.tsx +19 -25
  86. package/src/views/Agents/AgentsPanel.tsx +11 -12
  87. package/src/views/Agents/AgentsTab.tsx +12 -17
  88. package/src/views/Agents/useAgentFavorites.ts +4 -4
  89. package/src/views/Chat/ChatMessage.tsx +3 -4
  90. package/src/views/ChatHistory/HistoryItem.tsx +10 -5
  91. package/src/views/ChatHistory/utils.ts +1 -18
  92. package/src/views/Home/CustomAgent.tsx +4 -4
  93. package/src/views/MessageInput/AgentSelector.tsx +4 -4
  94. package/src/views/MessageInput/ButtonAgent.tsx +2 -2
  95. package/src/views/MessageInput/QuickCommandSelector.tsx +4 -4
  96. package/src/views/MessageInput/UploadDragNDrop.tsx +83 -0
  97. package/src/views/MessageInput/dictionary.ts +9 -0
  98. package/src/views/MessageInput/index.tsx +17 -1
  99. package/src/views/Tools.tsx +4 -3
  100. package/src/views/Workspaces/WorkspacesTab.tsx +1 -1
@@ -0,0 +1,30 @@
1
+ import { useEffect } from 'react'
2
+
3
+ interface UsePasteUploadProps {
4
+ textAreaRef: React.RefObject<HTMLTextAreaElement>,
5
+ onUploadFiles: (files: File[]) => void,
6
+ enabled?: boolean,
7
+ }
8
+
9
+ export const usePasteUpload = ({
10
+ textAreaRef,
11
+ onUploadFiles,
12
+ enabled = true,
13
+ }: UsePasteUploadProps) => {
14
+ useEffect(() => {
15
+ const textarea = textAreaRef.current
16
+ if (!textarea || !enabled) return
17
+
18
+ const handlePaste = (e: ClipboardEvent) => {
19
+ if (e.clipboardData?.files?.length) {
20
+ onUploadFiles(Array.from(e.clipboardData.files))
21
+ e.preventDefault()
22
+ }
23
+ }
24
+
25
+ textarea.addEventListener('paste', handlePaste)
26
+ return () => {
27
+ textarea.removeEventListener('paste', handlePaste)
28
+ }
29
+ }, [onUploadFiles, textAreaRef, enabled])
30
+ }
@@ -1,29 +1,21 @@
1
1
  import { Text } from '@citric/core'
2
2
  import { Badge, Skeleton } from '@citric/ui'
3
- import { agentClient, AgentVisibilityLevel } from '@stack-spot/portal-network'
3
+ import { agentToolsClient } from '@stack-spot/portal-network'
4
4
  import { useMemo } from 'react'
5
5
  import { ToolBadge } from '../../components/ToolBadge'
6
+ import { toolById } from '../../utils/tools'
6
7
  import { useAgentsDictionary } from './dictionary'
7
8
  import { AgentDescriptionBox } from './styled'
8
9
 
9
- interface Props {
10
- agentId?: string,
11
- llm?: string,
12
- description?: string,
13
- numberOfKnowledgeSources: number,
14
- visibility: AgentVisibilityLevel,
15
- }
16
-
17
- export const AgentDescription = ({ agentId, llm, description, numberOfKnowledgeSources, visibility }: Props) => {
10
+ export const AgentDescription = ({ agentId }: { agentId?: string }) => {
18
11
  const t = useAgentsDictionary()
19
- const [agent, , , { isLoading }] = agentClient.agentById.useStatefulQuery(
20
- { agentId: agentId!, builtIn: visibility === 'BUILT-IN' },
21
- { enabled: !!agentId },
22
- )
12
+ const [agent, , , { isLoading }] = agentToolsClient.agent.useStatefulQuery({ agentId: agentId! }, { enabled: !!agentId })
13
+ const [toolKits, , , { isLoading: isLoadingToolKit }] = agentToolsClient.tools.useStatefulQuery({})
14
+ const numberOfKnowledgeSources = agent?.knowledge_source_config?.knowledge_sources.length ?? 0
23
15
 
24
16
  const knowledgeSources = useMemo(
25
- () => agent?.knowledge_sources_config?.knowledge_sources_details?.map((ks, index) => (
26
- <li key={index}><Badge palette="teal" appearance="square">{ks.name}</Badge></li>
17
+ () => agent?.knowledge_source_config?.knowledge_sources?.map((ks, index) => (
18
+ <li key={index}><Badge palette="teal" appearance="square">{ks}</Badge></li>
27
19
  )),
28
20
  [agent],
29
21
  )
@@ -36,31 +28,33 @@ export const AgentDescription = ({ agentId, llm, description, numberOfKnowledgeS
36
28
  }, [numberOfKnowledgeSources])
37
29
  const tools = useMemo(() => {
38
30
  const result: React.ReactElement[] = []
39
- for (const kit of agent?.toolkits?.builtins ?? []) {
40
- for (const tool of kit.tools ?? []) {
41
- result.push(<li key={tool.id}><ToolBadge name={tool.name || tool.id || 'unknown'} image={kit.image_url} /></li>)
42
- }
31
+ const builtInTools = agent?.toolkits?.builtin_toolkits?.[0].tools
32
+ for (const tool of builtInTools ?? []) {
33
+ const toolWithImage = toolById(tool.id, toolKits)
34
+ result.push(<li key={tool.id}>
35
+ <ToolBadge name={toolWithImage?.name || toolWithImage?.id || 'unknown'} image={toolWithImage?.image} />
36
+ </li>)
43
37
  }
44
38
  return result
45
39
  }, [agent])
46
40
 
47
41
  return (
48
42
  <AgentDescriptionBox>
49
- {description && <section>
43
+ {agent?.description && <section>
50
44
  <Text appearance="microtext1" className="title">{t.description}</Text>
51
- <Text>{description}</Text>
45
+ <Text>{agent?.description}</Text>
52
46
  </section>}
53
47
  {(!!numberOfKnowledgeSources || !!knowledgeSources?.length) && <section>
54
48
  <Text appearance="microtext1" className="title">Knowledge sources</Text>
55
- <ul>{isLoading ? skeleton : knowledgeSources}</ul>
49
+ <ul>{isLoading || isLoadingToolKit ? skeleton : knowledgeSources}</ul>
56
50
  </section>}
57
51
  {!!tools.length && <section>
58
52
  <Text appearance="microtext1" className="title">{t.tools}</Text>
59
53
  <ul>{tools}</ul>
60
54
  </section>}
61
- {llm && <section>
55
+ {agent?.model_name && <section>
62
56
  <Text appearance="microtext1" className="title">LLM</Text>
63
- <Badge palette="orange" appearance="square">{llm}</Badge>
57
+ <Badge palette="orange" appearance="square">{agent?.model_name}</Badge>
64
58
  </section>}
65
59
  </AgentDescriptionBox>
66
60
  )
@@ -1,3 +1,4 @@
1
+ import { agentToolsClient } from '@stack-spot/portal-network'
1
2
  import { useEffect, useMemo, useRef } from 'react'
2
3
  import { RightPanelTabs } from '../../components/RightPanelTabs'
3
4
  import { useCurrentChat } from '../../context/hooks'
@@ -5,8 +6,6 @@ import { checkIsTrial } from '../../utils/check-is-trial'
5
6
  import { AgentsTab, AgentsTabWorkspace } from './AgentsTab'
6
7
  import { useAgentsDictionary } from './dictionary'
7
8
 
8
- const agentDefaultSlug = 'stk_code_buddy'
9
-
10
9
  /**
11
10
  * Renders the Agent selection form in the Right Panel if this is the panel that is currently opened.
12
11
  */
@@ -17,22 +16,22 @@ export const AgentsPanel = () => {
17
16
  const agent = useRef(chat.get('agent'))
18
17
 
19
18
  useEffect(() => {
20
- if (agentDefaultSlug !== chat.get('agent')?.slug) {
19
+ if (agentToolsClient.agentDefaultSlug !== chat.get('agent')?.slug) {
21
20
  agent.current = chat.get('agent')
22
21
  }
23
22
  }, [chat])
24
23
 
25
24
  const tabs= useMemo(() => isTrial ? [
26
- { title: t.favorites, content: <AgentsTab key="favorite" visibility="FAVORITE" agent={agent} /> },
27
- { title: t.builtin, content: <AgentsTab key="builtin" visibility="BUILT-IN" agent={agent} /> },
28
- { title: t.personal, content: <AgentsTab key="personal" visibility="PERSONAL" agent={agent} /> },
25
+ { title: t.favorites, content: <AgentsTab key="favorite" visibility="favorite" agent={agent} /> },
26
+ { title: t.builtin, content: <AgentsTab key="builtin" visibility="built_in" agent={agent} /> },
27
+ { title: t.personal, content: <AgentsTab key="personal" visibility="personal" agent={agent} /> },
29
28
  ]: [
30
- { title: t.favorites, content: <AgentsTab key="favorite" visibility="FAVORITE" agent={agent} /> },
31
- { title: t.builtin, content: <AgentsTab key="builtin" visibility="BUILT-IN" agent={agent} /> },
32
- { title: t.personal, content: <AgentsTab key="personal" visibility="PERSONAL" agent={agent} /> },
33
- { title: t.shared, content: <AgentsTab key="shared" visibility="SHARED" agent={agent} /> },
34
- { title: t.spots, content: <AgentsTabWorkspace key="workspace" visibility="WORKSPACE" agent={agent} /> },
35
- { title: t.account, content: <AgentsTab key="account" visibility="ACCOUNT" agent={agent} /> },
29
+ { title: t.favorites, content: <AgentsTab key="favorite" visibility="favorite" agent={agent} /> },
30
+ { title: t.builtin, content: <AgentsTab key="builtin" visibility="built_in" agent={agent} /> },
31
+ { title: t.personal, content: <AgentsTab key="personal" visibility="personal" agent={agent} /> },
32
+ { title: t.shared, content: <AgentsTab key="shared" visibility="shared" agent={agent} /> },
33
+ { title: t.spots, content: <AgentsTabWorkspace key="workspace" visibility="workspace" agent={agent} /> },
34
+ { title: t.account, content: <AgentsTab key="account" visibility="account" agent={agent} /> },
36
35
 
37
36
  ], [t, isTrial, agent])
38
37
 
@@ -2,8 +2,7 @@ import { Button, IconBox, Text } from '@citric/core'
2
2
  import { Agent, Search } from '@citric/icons'
3
3
  import { Placeholder } from '@stack-spot/portal-components/Placeholder'
4
4
  import { MiniLogo } from '@stack-spot/portal-components/svg'
5
- import { agentClient, AgentResponseWithBuiltIn, workspaceAiClient } from '@stack-spot/portal-network'
6
- import { VisibilityLevel } from '@stack-spot/portal-network/api/agent'
5
+ import { AgentResponseWithBuiltIn, agentToolsClient, AgentVisibilityLevel, workspaceAiClient } from '@stack-spot/portal-network'
7
6
  import { WorkspaceResponse } from '@stack-spot/portal-network/api/workspace-ai'
8
7
  import { useCallback, useMemo, useState } from 'react'
9
8
  import { ButtonFavorite } from '../../components/ButtonFavorite'
@@ -20,7 +19,7 @@ import { AgentLabel } from './styled'
20
19
  import { useAgentFavorites } from './useAgentFavorites'
21
20
 
22
21
  export interface AgentTabProps {
23
- visibility: VisibilityLevel | 'BUILT-IN',
22
+ visibility: AgentVisibilityLevel,
24
23
  workspaceId?: string,
25
24
  agent: React.MutableRefObject<ChatProperties['agent']>,
26
25
  showSubmitButton?: boolean,
@@ -33,16 +32,15 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
33
32
  const [filter, setFilter] = useState('')
34
33
  const { useFavorites, onAddFavorite, onRemoveFavorite } = useAgentFavorites()
35
34
  const listFavorites = useFavorites()
36
- const agentDefault = agentClient.agentDefault.useQuery({})
35
+ const agentDefault = agentToolsClient.agentDefault.useQuery()
37
36
  const agents = workspaceId
38
- ? workspaceAiClient.getAgentFromWorkspaceAi.useQuery({ workspaceId })
39
- : agentClient.allAgents.useQuery({ visibilities: [visibility] })
40
-
37
+ ? workspaceAiClient.getAgentFromWorkspaceAi.useQuery({ workspaceId }) as AgentResponseWithBuiltIn[]
38
+ : agentToolsClient.agents.useQuery({ visibility })
41
39
 
42
40
  const [value, setValue] = useState<AgentResponseWithBuiltIn | undefined>(
43
41
  agent.current
44
42
  ? agents.find(a => a.id === agent.current?.id)
45
- : chat.get('agent') ? agents.find(a => a.id === chat.get('agent')?.id) : agentDefault,
43
+ : chat.get('agent') ? agents.find(a => a.id === chat.get('agent')?.id) : agentDefault as unknown as AgentResponseWithBuiltIn,
46
44
  )
47
45
 
48
46
  const filtered = useMemo(
@@ -53,14 +51,17 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
53
51
 
54
52
  function submit() {
55
53
  if (value) {
56
- chat.set('agent', { id: value.id, label: value.name, image: value.avatar, builtIn: !!value.builtIn, slug: value.slug })
54
+ chat.set(
55
+ 'agent',
56
+ { id: value.id, label: value.name, image: value.avatar!, builtIn: value.visibility_level === 'built_in', slug: value.slug },
57
+ )
57
58
  }
58
59
  close()
59
60
  }
60
61
 
61
62
  const onChange = useCallback((newValue: AgentResponseWithBuiltIn) => {
62
63
  setValue(newValue)
63
- agent.current = { ...newValue, label: newValue.name, builtIn: !!newValue.builtIn }
64
+ agent.current = { ...newValue, label: newValue.name, builtIn: newValue.visibility_level === 'built_in' }
64
65
  }, [])
65
66
 
66
67
  return (
@@ -83,13 +84,7 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
83
84
  <Text>{name}</Text>
84
85
  </AgentLabel>
85
86
  )}
86
- renderDescription={a => <AgentDescription
87
- agentId={a.id}
88
- visibility={visibility}
89
- description={a.description}
90
- llm={a.llm_config?.model_slug}
91
- numberOfKnowledgeSources={a.knowledge_sources_config?.knowledge_sources?.length ?? 0}
92
- />}
87
+ renderDescription={a => <AgentDescription agentId={a.id} />}
93
88
  optionClassName={a => (a === value && filter && !a.name.toLocaleLowerCase().includes(filter.toLocaleLowerCase()))
94
89
  ? 'filtered-out'
95
90
  : ''
@@ -1,15 +1,15 @@
1
1
  /* eslint-disable filenames/match-regex */
2
- import { agentClient } from '@stack-spot/portal-network'
2
+ import { agentClient, agentToolsClient } from '@stack-spot/portal-network'
3
3
 
4
4
  export function useAgentFavorites() {
5
- const useFavorites = () => agentClient.allAgents.useQuery({ visibilities: ['FAVORITE'] })
5
+ const useFavorites = () => agentToolsClient.agents.useQuery({ visibility: 'favorite' })
6
6
  const [addFavorite, pendingAddFav] = agentClient.addFavoriteAgent.useMutation()
7
7
  const [removeFavorite, pendingRemoveFav] = agentClient.removeFavoriteAgent.useMutation()
8
8
 
9
9
  const removeFavoriteAgent = async (idOrSlug?: string) => {
10
10
  try {
11
11
  await removeFavorite({ agentId: idOrSlug || '' })
12
- await agentClient.allAgents.invalidate({ visibilities: ['FAVORITE'] })
12
+ await agentToolsClient.agents.invalidate({ visibility: 'favorite' })
13
13
  } catch (error) {
14
14
  // eslint-disable-next-line no-console
15
15
  console.error(error)
@@ -19,7 +19,7 @@ export function useAgentFavorites() {
19
19
  const addFavoriteAgent = async (idOrSlug?: string) => {
20
20
  try {
21
21
  await addFavorite({ agentId: idOrSlug || '' })
22
- await agentClient.allAgents.invalidate({ visibilities: ['FAVORITE'] })
22
+ await agentToolsClient.agents.invalidate({ visibility: 'favorite' })
23
23
  } catch (error) {
24
24
  // eslint-disable-next-line no-console
25
25
  console.error(error)
@@ -1,7 +1,7 @@
1
1
  import { Box, Button, Checkbox, Flex, IconBox, Input, Label, Radio, Text } from '@citric/core'
2
2
  import { Check, Cog, Copy, Dislike, DislikeFill, Like, LikeFill, TimesCircle } from '@citric/icons'
3
3
  import { Badge, IconButton, Tooltip } from '@citric/ui'
4
- import { agentClient } from '@stack-spot/portal-network'
4
+ import { agentToolsClient } from '@stack-spot/portal-network'
5
5
  import { listToClass } from '@stack-spot/portal-theme'
6
6
  import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
7
7
  import { groupBy } from 'lodash'
@@ -193,11 +193,10 @@ export const ChatMessage = ({ message, isLast, beforeMessage, afterMessage }: Pr
193
193
  const widget = useWidget()
194
194
  const chat = useCurrentChat()
195
195
  const agentId = entry.agent?.id ?? ''
196
- const [agent] = agentClient.agentById.useStatefulQuery({ agentId, builtIn: !!entry?.agent?.builtIn }, { enabled: !!agentId })
196
+ const [toolKits] = agentToolsClient.tools.useStatefulQuery({}, { enabled: !!agentId })
197
197
  const [copied, setCopied] = useState(false)
198
198
  const [showUserButtonCopy, setShowUserButtonCopy] = useState(false)
199
199
 
200
-
201
200
  useChatScrollToBottomEffect(ref, [entry])
202
201
 
203
202
  const detailKS = useCallback(({ name, slug, documentScore, documentId }: Required<TextChatEntry>['knowledgeSources'][number]) => {
@@ -349,7 +348,7 @@ export const ChatMessage = ({ message, isLast, beforeMessage, afterMessage }: Pr
349
348
  className="tools-badge"
350
349
  label={t.tools}
351
350
  images={entry.tools.slice(0, 3).map((id) => {
352
- const tool = toolById(id, agent?.toolkits)
351
+ const tool = toolById(id, toolKits)
353
352
  return { key: id, name: tool?.name || id, icon: <Cog />, url: tool?.image }
354
353
  })}
355
354
  onClick={openToolsPanel}
@@ -2,7 +2,7 @@ import { IconBox, Input } from '@citric/core'
2
2
  import { Check, Download, EllipsisHorizontal, Pencil, Trash } from '@citric/icons'
3
3
  import { IconButton, LoadingCircular } from '@citric/ui'
4
4
  import { focusNextIgnoringChildren } from '@stack-spot/portal-components'
5
- import { aiClient } from '@stack-spot/portal-network'
5
+ import { agentToolsClient, aiClient } from '@stack-spot/portal-network'
6
6
  import { ConversationResponse } from '@stack-spot/portal-network/api/ai'
7
7
  import { theme } from '@stack-spot/portal-theme'
8
8
  import { last } from 'lodash'
@@ -11,12 +11,13 @@ import { OverlayMenu } from '../../components/OverlayMenu'
11
11
  import { useWidget } from '../../context/hooks'
12
12
  import { ChatEntry } from '../../state/ChatEntry'
13
13
  import { ChatState } from '../../state/ChatState'
14
+ import { LabeledAgent } from '../../state/types'
14
15
  import { ButtonAction } from '../../types'
15
16
  import { download } from '../../utils/download'
16
17
  import { genericSourcesToKnowledgeSources } from '../../utils/knowledge-source'
17
18
  import { useHistoryDictionary } from './dictionary'
18
19
  import { HistoryItemBox } from './styled'
19
- import { findStack, findWorkspace, getAllAgents } from './utils'
20
+ import { findStack, findWorkspace } from './utils'
20
21
 
21
22
  /**
22
23
  * Renders an item of the list of conversations (history).
@@ -88,12 +89,16 @@ export const HistoryItem = ({ item }: { item: ConversationResponse }) => {
88
89
  setLoading(true)
89
90
  try {
90
91
  const chat = await aiClient.chat.query({ conversationId: item.id })
92
+ const historyAgentIds = chat.history?.map(item => item.custom_agent?.id).filter(Boolean) as string[] ?? []
91
93
  const [stack, workspace, agents] = await Promise.all([
92
94
  findStack(chat.ai_stack_id),
93
95
  findWorkspace(chat.workspace_id),
94
- getAllAgents(),
96
+ agentToolsClient.agentsByIds.query({ searchAgentsRequest: { ids: historyAgentIds } }),
95
97
  ])
96
- const agent = agents.find(a => a.id === last(chat.history)?.custom_agent?.id)
98
+ const agentsAsLabeledAgents: LabeledAgent[] = agents
99
+ .map((a) => ({ ...a, label: a.name, image: a.avatar ?? '', builtIn: a.visibility_level === 'built_in' }))
100
+
101
+ const agent = agentsAsLabeledAgents.find(a => a.id === last(chat.history)?.custom_agent?.id)
97
102
  const builtIn = !!last(chat.history ?? [])?.custom_agent?.built_in
98
103
  widget.chatTabs.add(new ChatState({
99
104
  id: chat.id,
@@ -103,7 +108,7 @@ export const HistoryItem = ({ item }: { item: ConversationResponse }) => {
103
108
  agentType: item.agent === 'USER' ? 'user' : 'bot',
104
109
  content: item.content,
105
110
  type: 'md',
106
- agent: agents.find(a => a.id === item.custom_agent?.id),
111
+ agent: agentsAsLabeledAgents.find(a => a.id === item.custom_agent?.id),
107
112
  messageId: item.message_id,
108
113
  knowledgeSources: item.agent === 'USER' ? undefined : genericSourcesToKnowledgeSources(item.sources),
109
114
  updated: item.updated,
@@ -1,6 +1,5 @@
1
- import { agentClient, aiClient, workspaceClient } from '@stack-spot/portal-network'
1
+ import { aiClient, workspaceClient } from '@stack-spot/portal-network'
2
2
  import { ChatProperties } from '../../state/ChatState'
3
- import { LabeledWithImage } from '../../state/types'
4
3
 
5
4
  /**
6
5
  * Finds a stack by its id.
@@ -36,19 +35,3 @@ export async function findWorkspace(id: string | null): Promise<ChatProperties['
36
35
  return { id, label: id }
37
36
  }
38
37
  }
39
-
40
-
41
- /**
42
- * Finds all the agents, including common agents and public agents.
43
- * @returns an array with every agent.
44
- */
45
- export async function getAllAgents(): Promise<LabeledWithImage[]> {
46
- try {
47
- const agents = await agentClient.allAgents.query({ visibilities: ['ALL'] })
48
- return agents.map(a => ({ id: a.id, label: a.name, image: a.avatar, slug: a.slug, builtIn: a.builtIn }))
49
- } catch (error) {
50
- // eslint-disable-next-line no-console
51
- console.error(error)
52
- return []
53
- }
54
- }
@@ -1,6 +1,6 @@
1
1
  import { IconBox, Text } from '@citric/core'
2
2
  import { Agent } from '@citric/icons'
3
- import { agentClient } from '@stack-spot/portal-network'
3
+ import { agentToolsClient } from '@stack-spot/portal-network'
4
4
  import { useMemo } from 'react'
5
5
  import { QuickStartButton } from '../../components/QuickStartButton'
6
6
  import { useCurrentChat, useCurrentChatState } from '../../context/hooks'
@@ -12,15 +12,15 @@ import { HomeBox } from './styled'
12
12
  */
13
13
  export const CustomAgent = () => {
14
14
  const { id, label, image } = useCurrentChatState('agent') ?? {}
15
- const [agent] = agentClient.agent.useStatefulQuery({ agentId: id! })
15
+ const [agent] = agentToolsClient.agent.useStatefulQuery({ agentId: id! })
16
16
  const chat = useCurrentChat()
17
- const suggestions = useMemo(() => agent?.suggested_prompts?.map((prompt, index) => (
17
+ const suggestions = useMemo(() => agent?.conversation_starter?.map((prompt, index) => (
18
18
  <QuickStartButton
19
19
  key={index}
20
20
  label={prompt}
21
21
  onClick={() => send(prompt)}
22
22
  />
23
- )), [agent?.suggested_prompts])
23
+ )), [agent?.conversation_starter])
24
24
 
25
25
  function send(message: string) {
26
26
  chat.pushMessage(ChatEntry.createUserEntry(message))
@@ -1,6 +1,6 @@
1
1
  import { Flex, IconBox, Image } from '@citric/core'
2
2
  import { Agent } from '@citric/icons'
3
- import { agentClient, AgentResponseWithBuiltIn } from '@stack-spot/portal-network'
3
+ import { AgentResponseWithBuiltIn, agentToolsClient } from '@stack-spot/portal-network'
4
4
  import { useCallback } from 'react'
5
5
  import { Selector } from '../../components/Selector'
6
6
  import { useCurrentChat, useCurrentChatState } from '../../context/hooks'
@@ -53,9 +53,9 @@ export const AgentSelector = ({ inputRef, isTrial }: {
53
53
 
54
54
  const getAgents = () => {
55
55
  if (isTrial) {
56
- return agentClient.allAgents.useQuery({ visibilities: ['PERSONAL', 'BUILT-IN'] })
56
+ return agentToolsClient.allAgents.useQuery({ visibilities: ['personal', 'built_in'] })
57
57
  }
58
- return agentClient.allAgents.useQuery({ visibilities: ['ACCOUNT', 'SHARED', 'PERSONAL', 'BUILT-IN', 'WORKSPACE'] })
58
+ return agentToolsClient.allAgents.useQuery({ visibilities: ['account', 'shared', 'personal', 'built_in', 'workspace'] })
59
59
  }
60
60
 
61
61
  return <Selector
@@ -68,7 +68,7 @@ export const AgentSelector = ({ inputRef, isTrial }: {
68
68
  regex: agentRegex,
69
69
  urlBuilder: (agent) => `/agents/${agent?.id}`,
70
70
  searchProp: 'name',
71
- sections: isTrial ? ['favorite', 'personal', 'built-in'] : ['favorite', 'personal', 'workspace', 'account', 'shared', 'built-in'],
71
+ sections: isTrial ? ['favorite', 'personal', 'built_in'] : ['favorite', 'personal', 'workspace', 'account', 'shared', 'built_in'],
72
72
  renderComponentItem: AgentItem,
73
73
  isEnabled: isAgentEnabled,
74
74
  onSelect: onSelectItem,
@@ -2,14 +2,14 @@ import { Flex, IconBox } from '@citric/core'
2
2
  import { Agent, TimesMini } from '@citric/icons'
3
3
  import { IconButton, Tooltip } from '@citric/ui'
4
4
  import { MiniLogo } from '@stack-spot/portal-components/svg'
5
- import { agentClient } from '@stack-spot/portal-network'
5
+ import { agentToolsClient } from '@stack-spot/portal-network'
6
6
  import { useEffect } from 'react'
7
7
  import { useCurrentChat, useCurrentChatState, useWidget } from '../../context/hooks'
8
8
  import { useMessageInputDictionary } from './dictionary'
9
9
 
10
10
  export const ButtonAgent = () => {
11
11
  const t = useMessageInputDictionary()
12
- const agentDefault = agentClient.agentDefault.useQuery({})
12
+ const agentDefault = agentToolsClient.agentDefault.useQuery()
13
13
  const widget = useWidget()
14
14
  const chat = useCurrentChat()
15
15
  const agent = useCurrentChatState('agent')
@@ -13,14 +13,14 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
13
13
  const chat = useCurrentChat()
14
14
  const isQuickCommandEnabled = useCurrentChatState('features').quickCommands
15
15
 
16
- const useFavorites = () => aiClient.quickCommands.useQuery({ visibility: 'favorite' })
16
+ const useFavorites = () => aiClient.allQuickCommands.useQuery({ visibility: 'favorite' })
17
17
  const [addFavorite, pendingAddFav] = aiClient.addFavoriteQuickCommand.useMutation()
18
18
  const [removeFavorite, pendingRemoveFav] = aiClient.removeFavoriteQuickCommand.useMutation()
19
19
 
20
20
  const addFavoriteQc = async(idOrSlug?: string) => {
21
21
  try {
22
22
  await addFavorite({ slug: idOrSlug || '' })
23
- await aiClient.quickCommands.invalidate()
23
+ await aiClient.allQuickCommands.invalidate()
24
24
  } catch (error) {
25
25
  // eslint-disable-next-line no-console
26
26
  console.error(error)
@@ -45,7 +45,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
45
45
  const removeFavoriteQc = async(idOrSlug?: string) => {
46
46
  try {
47
47
  await removeFavorite({ slug: idOrSlug || '' })
48
- await aiClient.quickCommands.invalidate()
48
+ await aiClient.allQuickCommands.invalidate()
49
49
  } catch (error) {
50
50
  // eslint-disable-next-line no-console
51
51
  console.error(error)
@@ -77,7 +77,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
77
77
  }, [chat, inputRef])
78
78
 
79
79
  const getQuickCommands = () => {
80
- const quickCommands = aiClient.quickCommands.useQuery({ order: 'a-to-z' })
80
+ const quickCommands = aiClient.allQuickCommands.useQuery({ order: 'a-to-z' })
81
81
  const quickCommandsFiltered = quickCommands.filter((qc) => qc.visibility_level.toLowerCase() !== 'workspace')
82
82
  const workspaceQuickCommands = workspaceAiClient.workspacesContentsByType.useQuery({ contentType: 'quick_command' })
83
83
  const workspaceQuickCommandsWithWorkspaceName: QuickCommandResponseWithSpaceName[] = workspaceQuickCommands
@@ -0,0 +1,83 @@
1
+ import { IconBox } from '@citric/core'
2
+ import { Document } from '@citric/icons'
3
+ import { DragEvent, useCallback, useEffect, useState } from 'react'
4
+ import { useCurrentChat } from '../../context/hooks'
5
+ import { useMessageInputDictionary } from './dictionary'
6
+
7
+ export function useUploadDragDrop(containerSelector: string = '.chat-container') {
8
+ const [isDragging, setIsDragging] = useState(false)
9
+ const chat = useCurrentChat()
10
+
11
+ const handleDrop = useCallback((e: DragEvent) => {
12
+ e.preventDefault()
13
+ e.stopPropagation()
14
+ setIsDragging(false)
15
+ if (e.dataTransfer?.files?.length) {
16
+ chat.uploadManager.add(Array.from(e.dataTransfer.files))
17
+ }
18
+ }, [chat])
19
+
20
+ const handleDragLeave = useCallback((e: DragEvent) => {
21
+ e.preventDefault()
22
+ if (e.currentTarget && !e.currentTarget.contains(e.relatedTarget as Node)) {
23
+ setIsDragging(false)
24
+ }
25
+ }, [])
26
+
27
+ useEffect(() => {
28
+ const container = document.querySelector(containerSelector) as HTMLDivElement | null
29
+ if (!container) return
30
+
31
+ const nativeHandleDragEnter = (e: Event) => {
32
+ e.preventDefault()
33
+ setIsDragging(true)
34
+ }
35
+
36
+ container.addEventListener('dragenter', nativeHandleDragEnter)
37
+ return () => {
38
+ container.removeEventListener('dragenter', nativeHandleDragEnter)
39
+ }
40
+ }, [containerSelector])
41
+
42
+ return {
43
+ isDragging,
44
+ handleDrop,
45
+ handleDragLeave,
46
+ }
47
+ }
48
+
49
+ interface UploadDragNDropProps {
50
+ isDragging?: boolean,
51
+ onDrop?: (e: DragEvent) => void,
52
+ onDragLeave?: (e: DragEvent) => void,
53
+ }
54
+
55
+ export const UploadDragNDrop = ({ isDragging, onDrop, onDragLeave }: UploadDragNDropProps) => {
56
+ const t = useMessageInputDictionary()
57
+
58
+ if (!isDragging) return null
59
+
60
+ return (
61
+ <div
62
+ className="upload-drag-drop"
63
+ data-active={isDragging}
64
+ role="dialog"
65
+ aria-modal="true"
66
+ aria-labelledby="upload-drag-drop-title"
67
+ aria-describedby="upload-drag-drop-description"
68
+ onDrop={onDrop}
69
+ onDragLeave={onDragLeave}
70
+ onDragOver={e => {
71
+ e.preventDefault()
72
+ e.stopPropagation()
73
+ }}
74
+ tabIndex={-1}
75
+ >
76
+ <IconBox size="lg" aria-hidden={true}>
77
+ <Document />
78
+ </IconBox>
79
+ <h2 id="upload-drag-drop-title">{t.uploadDragDropTitle}</h2>
80
+ <p id="upload-drag-drop-description">{t.uploadDragDropDescription}</p>
81
+ </div>
82
+ )
83
+ }
@@ -9,6 +9,7 @@ const dictionary = {
9
9
  agent: 'Select agent',
10
10
  send: 'Send message',
11
11
  placeholder: 'Send a message to $0. For commands, use @ or /',
12
+ typing: 'Type your message...',
12
13
  cancel: 'Cancel',
13
14
  removeConfig: 'Remove all the configuration',
14
15
  removeStack: 'Stop using the current stack',
@@ -22,6 +23,10 @@ const dictionary = {
22
23
  collapse: 'Collapse options',
23
24
  uploadSizeError: 'The following files were not added to the upload list because they\'re larger than $1:',
24
25
  uploadItemLimitError: 'The following files were not added because no more than $1 items may be uploaded at a time:',
26
+ uploadError: 'An error occurred while uploading the file "$0".',
27
+ uploadDragging: 'Drop the file here to upload',
28
+ uploadDragDropTitle: 'Arraste e solte arquivos',
29
+ uploadDragDropDescription: 'Solte arquivos aqui para enviá-los na conversa',
25
30
  cantSendBecauseOfUploadError: 'Can\'t send the message because one of the files in the upload list could not be uploaded. Please, retry it or remove it from the list.',
26
31
  cantSendBecauseOfUploadProgress: 'Please wait until all files are uploaded before sending the message. You can also cancel the upload by removing it from the list of uploads.',
27
32
  cantSendBecauseOfEmptyContent: 'You can\'t send empty messages. Please write some text or upload a file.',
@@ -35,6 +40,7 @@ const dictionary = {
35
40
  agent: 'Selecionar agente',
36
41
  send: 'Enviar mensagem',
37
42
  placeholder: 'Envie uma mensagem para $0. Para comandos, use @ ou /',
43
+ typing: 'Digite sua mensagem...',
38
44
  cancel: 'Cancelar',
39
45
  removeConfig: 'Remover todas as configurações',
40
46
  removeStack: 'Parar de usar a stack atual',
@@ -49,6 +55,9 @@ const dictionary = {
49
55
  uploadSizeError: 'Os seguintes arquivos não foram adicionados à lista de upload porque eles são maiores que $0:',
50
56
  uploadItemLimitError: 'Os seguintes arquivos não foram adicionados à lista de upload porque é permitido enviar no máximo $0 arquivos por vez:',
51
57
  uploadError: 'Ocorreu um erro ao enviar o arquivo "$0".',
58
+ uploadDragging: 'Solte o arquivo aqui para fazer upload',
59
+ uploadDragDropTitle: 'Solte seus arquivos aqui',
60
+ uploadDragDropDescription: 'Arraste ou solte arquivos para compartilhar na conversa',
52
61
  unknownUploadError: 'Ocorreu um erro ao enviar os arquivos.',
53
62
  cantSendBecauseOfUploadError: 'Não é possível enviar a mensagem, pois um dos arquivos na lista de uploads não pôde ser enviado. Por favor, tente enviá-lo novamente ou remova-o da lista.',
54
63
  cantSendBecauseOfUploadProgress: 'Por favor aguarde todos os uploads de arquivos antes de enviar a mensagem. Você pode cancelar o upload removendo o arquivo da lista de uploads.',