@stack-spot/ai-chat-widget 1.17.1 → 1.18.0-beta.10

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 (110) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/StackspotAIWidget.js +1 -1
  3. package/dist/app-metadata.json +6 -6
  4. package/dist/components/ComponentNavigator.d.ts +38 -0
  5. package/dist/components/ComponentNavigator.d.ts.map +1 -0
  6. package/dist/components/ComponentNavigator.js +33 -0
  7. package/dist/components/ComponentNavigator.js.map +1 -0
  8. package/dist/components/ListResource.d.ts +29 -0
  9. package/dist/components/ListResource.d.ts.map +1 -0
  10. package/dist/components/ListResource.js +17 -0
  11. package/dist/components/ListResource.js.map +1 -0
  12. package/dist/components/RightPanelForm.d.ts.map +1 -1
  13. package/dist/components/RightPanelForm.js +29 -1
  14. package/dist/components/RightPanelForm.js.map +1 -1
  15. package/dist/components/Selector/index.js +5 -5
  16. package/dist/components/Selector/index.js.map +1 -1
  17. package/dist/components/Selector/styled.d.ts +3 -1
  18. package/dist/components/Selector/styled.d.ts.map +1 -1
  19. package/dist/components/Selector/styled.js +2 -1
  20. package/dist/components/Selector/styled.js.map +1 -1
  21. package/dist/components/WorkspaceTabNavigator.d.ts +17 -0
  22. package/dist/components/WorkspaceTabNavigator.d.ts.map +1 -0
  23. package/dist/components/WorkspaceTabNavigator.js +95 -0
  24. package/dist/components/WorkspaceTabNavigator.js.map +1 -0
  25. package/dist/components/form/DescribedCheckboxGroup.d.ts.map +1 -1
  26. package/dist/components/form/DescribedCheckboxGroup.js +23 -2
  27. package/dist/components/form/DescribedCheckboxGroup.js.map +1 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/state/ChatEntry.d.ts +4 -0
  33. package/dist/state/ChatEntry.d.ts.map +1 -1
  34. package/dist/state/ChatEntry.js.map +1 -1
  35. package/dist/views/Agents/AgentsPanel.d.ts.map +1 -1
  36. package/dist/views/Agents/AgentsPanel.js +19 -11
  37. package/dist/views/Agents/AgentsPanel.js.map +1 -1
  38. package/dist/views/Agents/AgentsTab.d.ts +9 -3
  39. package/dist/views/Agents/AgentsTab.d.ts.map +1 -1
  40. package/dist/views/Agents/AgentsTab.js +25 -7
  41. package/dist/views/Agents/AgentsTab.js.map +1 -1
  42. package/dist/views/Agents/dictionary.d.ts +1 -1
  43. package/dist/views/Agents/dictionary.d.ts.map +1 -1
  44. package/dist/views/Agents/dictionary.js +2 -0
  45. package/dist/views/Agents/dictionary.js.map +1 -1
  46. package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
  47. package/dist/views/Chat/ChatMessage.js +5 -5
  48. package/dist/views/Chat/ChatMessage.js.map +1 -1
  49. package/dist/views/Chat/StepsList.js +2 -2
  50. package/dist/views/Chat/StepsList.js.map +1 -1
  51. package/dist/views/ChatHistory/utils.d.ts.map +1 -1
  52. package/dist/views/ChatHistory/utils.js +12 -3
  53. package/dist/views/ChatHistory/utils.js.map +1 -1
  54. package/dist/views/KnowledgeSources.d.ts +12 -0
  55. package/dist/views/KnowledgeSources.d.ts.map +1 -1
  56. package/dist/views/KnowledgeSources.js +20 -6
  57. package/dist/views/KnowledgeSources.js.map +1 -1
  58. package/dist/views/MessageInput/AgentSelector.d.ts.map +1 -1
  59. package/dist/views/MessageInput/AgentSelector.js +11 -7
  60. package/dist/views/MessageInput/AgentSelector.js.map +1 -1
  61. package/dist/views/MessageInput/ButtonGroup.js +2 -2
  62. package/dist/views/MessageInput/ButtonGroup.js.map +1 -1
  63. package/dist/views/MessageInput/QuickCommandSelector.d.ts.map +1 -1
  64. package/dist/views/MessageInput/QuickCommandSelector.js +12 -4
  65. package/dist/views/MessageInput/QuickCommandSelector.js.map +1 -1
  66. package/dist/views/MessageInput/dictionary.d.ts +1 -1
  67. package/dist/views/MessageInput/dictionary.d.ts.map +1 -1
  68. package/dist/views/MessageInput/dictionary.js +6 -4
  69. package/dist/views/MessageInput/dictionary.js.map +1 -1
  70. package/dist/views/Stacks.d.ts +9 -0
  71. package/dist/views/Stacks.d.ts.map +1 -1
  72. package/dist/views/Stacks.js +37 -14
  73. package/dist/views/Stacks.js.map +1 -1
  74. package/dist/views/Workspaces/WorkspacesTab.d.ts +20 -0
  75. package/dist/views/Workspaces/WorkspacesTab.d.ts.map +1 -0
  76. package/dist/views/Workspaces/WorkspacesTab.js +64 -0
  77. package/dist/views/Workspaces/WorkspacesTab.js.map +1 -0
  78. package/dist/views/{Workspaces.d.ts → Workspaces/index.d.ts} +1 -1
  79. package/dist/views/Workspaces/index.d.ts.map +1 -0
  80. package/dist/views/Workspaces/index.js +67 -0
  81. package/dist/views/Workspaces/index.js.map +1 -0
  82. package/package.json +3 -3
  83. package/src/app-metadata.json +6 -6
  84. package/src/components/ComponentNavigator.tsx +103 -0
  85. package/src/components/ListResource.tsx +60 -0
  86. package/src/components/RightPanelForm.tsx +29 -1
  87. package/src/components/Selector/index.tsx +5 -5
  88. package/src/components/Selector/styled.ts +3 -2
  89. package/src/components/WorkspaceTabNavigator.tsx +175 -0
  90. package/src/components/form/DescribedCheckboxGroup.tsx +38 -7
  91. package/src/index.ts +2 -0
  92. package/src/state/ChatEntry.ts +4 -0
  93. package/src/views/Agents/AgentsPanel.tsx +21 -11
  94. package/src/views/Agents/AgentsTab.tsx +42 -9
  95. package/src/views/Agents/dictionary.ts +3 -0
  96. package/src/views/Chat/ChatMessage.tsx +6 -5
  97. package/src/views/Chat/StepsList.tsx +2 -2
  98. package/src/views/ChatHistory/utils.ts +14 -3
  99. package/src/views/KnowledgeSources.tsx +37 -14
  100. package/src/views/MessageInput/AgentSelector.tsx +20 -8
  101. package/src/views/MessageInput/ButtonGroup.tsx +3 -3
  102. package/src/views/MessageInput/QuickCommandSelector.tsx +19 -6
  103. package/src/views/MessageInput/dictionary.ts +6 -4
  104. package/src/views/Stacks.tsx +57 -17
  105. package/src/views/Workspaces/WorkspacesTab.tsx +120 -0
  106. package/src/views/Workspaces/index.tsx +76 -0
  107. package/dist/views/Workspaces.d.ts.map +0 -1
  108. package/dist/views/Workspaces.js +0 -103
  109. package/dist/views/Workspaces.js.map +0 -1
  110. package/src/views/Workspaces.tsx +0 -137
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /* Attention: in order for the package "page" to work without linking the lib, we must export types separately, using the "type" keyword */
2
2
 
3
+ export { ProgressBar } from './components/ProgressBar'
3
4
  export { QuickStartButton } from './components/QuickStartButton'
4
5
  export { AIWidgetProvider } from './context/AIWidgetProvider'
5
6
  export * from './context/hooks'
@@ -7,6 +8,7 @@ export { getFeaturesWithDefaults } from './features'
7
8
  export type { AIWidgetFeatures, ChatFeatures } from './features'
8
9
  export { StackspotAIWidget } from './StackspotAIWidget'
9
10
  export { ChatEntry } from './state/ChatEntry'
11
+ export type { ChatAction } from './state/ChatEntry'
10
12
  export { ChatState } from './state/ChatState'
11
13
  export type { MessageInterceptor } from './state/ChatState'
12
14
  export { ChatTabsController } from './state/ChatTabsController'
@@ -144,6 +144,10 @@ export interface TextChatEntry {
144
144
  maxLength?: number,
145
145
  pattern?: string,
146
146
  },
147
+ /**
148
+ * Valid for input types.
149
+ */
150
+ initialValue?: string[],
147
151
  }
148
152
 
149
153
  type ChatEntryListener = (value: TextChatEntry) => void
@@ -1,8 +1,9 @@
1
- import { useMemo } from 'react'
1
+ import { useEffect, useMemo, useRef } from 'react'
2
2
  import { RightPanelTabs } from '../../components/RightPanelTabs'
3
3
  import { useCurrentChat } from '../../context/hooks'
4
+ import { isAgentDefault } from '../../utils/agent'
4
5
  import { checkIsTrial } from '../../utils/check-is-trial'
5
- import { AgentsTab } from './AgentsTab'
6
+ import { AgentsTab, AgentsTabWorkspace } from './AgentsTab'
6
7
  import { useAgentsDictionary } from './dictionary'
7
8
 
8
9
  /**
@@ -12,18 +13,27 @@ export const AgentsPanel = () => {
12
13
  const t = useAgentsDictionary()
13
14
  const chat = useCurrentChat()
14
15
  const isTrial = checkIsTrial()
16
+ const agent = useRef(chat.get('agent'))
17
+
18
+ useEffect(() => {
19
+ if (!isAgentDefault(chat.get('agent')?.slug)) {
20
+ agent.current = chat.get('agent')
21
+ }
22
+ }, [chat])
15
23
 
16
24
  const tabs= useMemo(() => isTrial ? [
17
- { title: t.favorites, content: <AgentsTab key="favorite" visibility="FAVORITE" /> },
18
- { title: t.builtin, content: <AgentsTab key="builtin" visibility="BUILT-IN" /> },
19
- { title: t.personal, content: <AgentsTab key="personal" visibility="PERSONAL" /> },
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} /> },
20
28
  ]: [
21
- { title: t.favorites, content: <AgentsTab key="favorite" visibility="FAVORITE" /> },
22
- { title: t.builtin, content: <AgentsTab key="builtin" visibility="BUILT-IN" /> },
23
- { title: t.personal, content: <AgentsTab key="personal" visibility="PERSONAL" /> },
24
- { title: t.shared, content: <AgentsTab key="shared" visibility="SHARED" /> },
25
- { title: t.account, content: <AgentsTab key="account" visibility="ACCOUNT" /> },
26
- ], [t, isTrial])
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} /> },
35
+
36
+ ], [t, isTrial, agent])
27
37
 
28
38
  return <RightPanelTabs key={chat.id} tabs={tabs} />
29
39
  }
@@ -2,21 +2,32 @@ 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 } from '@stack-spot/portal-network'
5
+ import { agentClient, workspaceAiClient } from '@stack-spot/portal-network'
6
6
  import { AgentResponse, VisibilityLevel } from '@stack-spot/portal-network/api/agent'
7
- import { useMemo, useState } from 'react'
7
+ import { WorkspaceResponse } from '@stack-spot/portal-network/api/workspace-ai'
8
+ import { useCallback, useMemo, useState } from 'react'
8
9
  import { ButtonFavorite } from '../../components/ButtonFavorite'
10
+ import { NavigationComponent } from '../../components/ComponentNavigator'
9
11
  import { DescribedRadioGroup } from '../../components/form/DescribedRadioGroup'
10
12
  import { IconInput } from '../../components/IconInput'
13
+ import { WorkspaceTabNavigator } from '../../components/WorkspaceTabNavigator'
11
14
  import { useCurrentChat } from '../../context/hooks'
12
15
  import { useRightPanel } from '../../right-panel/hooks'
16
+ import { ChatProperties } from '../../state/ChatState'
13
17
  import { isAgentDefault } from '../../utils/agent'
14
18
  import { AgentDescription } from './AgentDescription'
15
19
  import { useAgentsDictionary } from './dictionary'
16
20
  import { AgentLabel } from './styled'
17
21
  import { useAgentFavorites } from './useAgentFavorites'
18
22
 
19
- export const AgentsTab = ({ visibility }: { visibility: VisibilityLevel | 'BUILT-IN' }) => {
23
+ export interface AgentTabProps {
24
+ visibility: VisibilityLevel | 'BUILT-IN',
25
+ workspaceId?: string,
26
+ agent: React.MutableRefObject<ChatProperties['agent']>,
27
+ showSubmitButton?: boolean,
28
+ }
29
+
30
+ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = true }: AgentTabProps) => {
20
31
  const t = useAgentsDictionary()
21
32
  const { close } = useRightPanel()
22
33
  const chat = useCurrentChat()
@@ -26,10 +37,14 @@ export const AgentsTab = ({ visibility }: { visibility: VisibilityLevel | 'BUILT
26
37
 
27
38
  const agentsBuiltIn = agentClient.publicAgents.useQuery({})
28
39
  const agentDefault = agentsBuiltIn.find((agent) => isAgentDefault(agent.slug))
29
- const agents = visibility === 'BUILT-IN' ? agentsBuiltIn : agentClient.agents.useQuery({ visibility })
30
-
40
+ const agents = workspaceId
41
+ ? workspaceAiClient.getAgentFromWorkspaceAi.useQuery({ workspaceId })
42
+ : visibility === 'BUILT-IN' ? agentsBuiltIn : agentClient.agents.useQuery({ visibility })
43
+
31
44
  const [value, setValue] = useState<AgentResponse | undefined>(
32
- chat.get('agent') ? agents.find(a => a.id === chat.get('agent')?.id) : agentDefault,
45
+ agent.current
46
+ ? agents.find(a => a.id === agent.current?.id)
47
+ : chat.get('agent') ? agents.find(a => a.id === chat.get('agent')?.id) : agentDefault,
33
48
  )
34
49
 
35
50
  const filtered = useMemo(
@@ -53,6 +68,13 @@ export const AgentsTab = ({ visibility }: { visibility: VisibilityLevel | 'BUILT
53
68
  close()
54
69
  }
55
70
 
71
+ const onChange = useCallback((newValue: AgentResponse) => {
72
+ const isBuiltIn = visibility === 'BUILT-IN' || agentsBuiltIn.some((agent) => agent.id === newValue.id)
73
+
74
+ setValue(newValue)
75
+ agent.current = { ...newValue, builtIn: isBuiltIn, label: newValue.name }
76
+ }, [])
77
+
56
78
  return (
57
79
  <>
58
80
  <div className="content">
@@ -65,7 +87,7 @@ export const AgentsTab = ({ visibility }: { visibility: VisibilityLevel | 'BUILT
65
87
  )}
66
88
  keygen={a => a.id}
67
89
  value={value}
68
- onChange={setValue}
90
+ onChange={onChange}
69
91
  renderLabel={({ name, avatar, id }) => (
70
92
  <AgentLabel>
71
93
  {id ? (avatar ? <img src={avatar} /> : <IconBox size="xs"><Agent /></IconBox>) : <MiniLogo />}
@@ -74,7 +96,7 @@ export const AgentsTab = ({ visibility }: { visibility: VisibilityLevel | 'BUILT
74
96
  )}
75
97
  renderDescription={a => <AgentDescription
76
98
  agentId={a.id}
77
- visibility={visibility}
99
+ visibility={visibility}
78
100
  description={a.description}
79
101
  llm={a.llm_config?.model_slug}
80
102
  numberOfKnowledgeSources={a.knowledge_sources_config?.knowledge_sources?.length ?? 0}
@@ -89,7 +111,18 @@ export const AgentsTab = ({ visibility }: { visibility: VisibilityLevel | 'BUILT
89
111
  <Placeholder title={t.noSearchResults} description={t.noSearchResultsDescription} className="no-data-placeholder" />}
90
112
  {!agents.length && <Placeholder title={t.noData} description={t.noDataDescription} />}
91
113
  </div>
92
- {!!filtered.length && <Button onClick={submit} disabled={!value}>{t.apply}</Button>}
114
+ {!!filtered.length && showSubmitButton && <Button onClick={submit} disabled={!value}>{t.apply}</Button>}
93
115
  </>
94
116
  )
95
117
  }
118
+
119
+ export function AgentsTabWorkspace({ agent, visibility, showSubmitButton }: AgentTabProps) {
120
+ const workspaceTabComponents = useMemo(() => ({ agent: AgentsTab }), [agent])
121
+
122
+ const buildNavigateParams = (workspace: WorkspaceResponse): NavigationComponent<typeof workspaceTabComponents> => ({
123
+ component: 'agent',
124
+ props: { visibility, workspaceId: workspace.id, agent, showSubmitButton },
125
+ })
126
+
127
+ return <WorkspaceTabNavigator components={workspaceTabComponents} getNavigateParam={buildNavigateParams} />
128
+ }
@@ -17,6 +17,7 @@ const dictionary = {
17
17
  description: 'Description',
18
18
  favorites: 'Favorites',
19
19
  tools: 'Tools',
20
+ spots: 'Spots',
20
21
  },
21
22
  pt: {
22
23
  title: 'Agentes',
@@ -34,6 +35,8 @@ const dictionary = {
34
35
  description: 'Descrição',
35
36
  favorites: 'Favoritos',
36
37
  tools: 'Ferramentas',
38
+ spots: 'Spots',
39
+
37
40
  },
38
41
  } satisfies Dictionary
39
42
 
@@ -61,7 +61,8 @@ const RenderInputsEntry = ({ isLast, entry, value, setValue, labels, setLabels }
61
61
 
62
62
  const renderInputs = () => {
63
63
  if (entry.type === 'input-text') {
64
- return <Input name={entry.name}
64
+ return <Input name={entry.name}
65
+ value={value[0] ?? ''}
65
66
  sx={{ maxWidth: '500px' }}
66
67
  autoFocus
67
68
  {...entry.validations} onChange={(data) => setValue([data.target.value])} required={entry.required} />
@@ -113,7 +114,7 @@ const RenderInputsEntry = ({ isLast, entry, value, setValue, labels, setLabels }
113
114
 
114
115
  if (entry.type === 'input-checkbox') {
115
116
  return <Flex className="checkbox-group">
116
- {entry.options?.map((option) => (<Flex w={6} key={option.label} alignItems="center" className="checkbox-item">
117
+ {entry.options?.map((option) => (<Flex as="label" w={6} key={option.label} alignItems="center" className="checkbox-item">
117
118
  <Checkbox name={entry.name} key={option.label} onChange={(data) => {
118
119
  if (data.target.checked) {
119
120
  setValue([...value, option.label])
@@ -159,8 +160,8 @@ const RenderInputsEntry = ({ isLast, entry, value, setValue, labels, setLabels }
159
160
  export const ChatMessage = ({ message, username, isLast }: Props) => {
160
161
  const t = useTranslate(dictionary)
161
162
  const [liked, setLiked] = useState<boolean | undefined>()
162
- const [value, setValue] = useState<string[]>([])
163
- const [labels, setLabels] = useState<string[]>([])
163
+ const [value, setValue] = useState<string[]>(message.getValue()?.initialValue ?? [])
164
+ const [labels, setLabels] = useState<string[]>(message.getValue()?.initialValue ?? [])
164
165
  const entry = useChatEntry(message)
165
166
  const dateFormatter = useDateFormatter()
166
167
  const userInfo = entry.agentType === 'user' ? <Avatar size="xs">{username}</Avatar> : <AgentInfo agent={entry.agent} />
@@ -267,7 +268,7 @@ export const ChatMessage = ({ message, username, isLast }: Props) => {
267
268
  }
268
269
 
269
270
  return (entry.content || entry.error || !!entry.steps?.length) && (
270
- <li className={entry.agentType} ref={ref}>
271
+ <li key={entry.messageId} className={entry.agentType} ref={ref}>
271
272
  <div className="chat-message" ref={chatRef} onKeyDown={handleKeyDown} tabIndex={0}>
272
273
  <div className={`user-info ${entry.agentType}`}>{userInfo}</div>
273
274
  {(entry.content || entry.steps) && <div className={listToClass(['message-content', entry.card && 'card', entry.type])}>
@@ -1,5 +1,5 @@
1
1
  import { Button, IconBox, Text } from '@citric/core'
2
- import { CheckCircleFill, Circle, PlayFill, TimesCircleFill } from '@citric/icons'
2
+ import { CheckCircleFill, PlayFill, Spaces, TimesCircleFill } from '@citric/icons'
3
3
  import { LoadingCircular } from '@citric/ui'
4
4
  import { AnimatedHeight } from '@stack-spot/portal-components/AnimatedHeight'
5
5
  import { ChatStep, StepChatStep } from '@stack-spot/portal-network'
@@ -27,7 +27,7 @@ function getStatusIcon(status: ChatStep['status']) {
27
27
  switch (status) {
28
28
  case 'error': return <IconBox {...iconBoxProps}><TimesCircleFill /></IconBox>
29
29
  case 'success': return <IconBox {...iconBoxProps}><CheckCircleFill /></IconBox>
30
- case 'pending': return <IconBox {...iconBoxProps}><Circle /></IconBox>
30
+ case 'pending': return <IconBox {...iconBoxProps}><Spaces /></IconBox>
31
31
  case 'running': return <LoadingCircular className="loading" colorScheme="inverse" size="xs" />
32
32
  }
33
33
  }
@@ -1,4 +1,4 @@
1
- import { agentClient, aiClient, workspaceClient } from '@stack-spot/portal-network'
1
+ import { agentClient, aiClient, workspaceAiClient, workspaceClient } from '@stack-spot/portal-network'
2
2
  import { ChatProperties } from '../../state/ChatState'
3
3
  import { LabeledWithImage } from '../../state/types'
4
4
 
@@ -44,9 +44,20 @@ export async function findWorkspace(id: string | null): Promise<ChatProperties['
44
44
  */
45
45
  export async function getAllAgents(): Promise<LabeledWithImage[]> {
46
46
  try {
47
- const [agents, publicAgents] = await Promise.all([agentClient.agents.query({}), agentClient.publicAgents.query({})])
47
+ const [agentsAccount, agentsPersonal, agentsShared, publicAgents, workspaceAgents] = await Promise.all([
48
+ agentClient.agents.query({ visibility: 'ACCOUNT' }),
49
+ agentClient.agents.query({ visibility: 'PERSONAL' }),
50
+ agentClient.agents.query({ visibility: 'SHARED' }),
51
+ agentClient.publicAgents.query({}),
52
+
53
+ workspaceAiClient.workspacesContentsByType.query({ contentType: 'agent' }),
54
+ ])
55
+
56
+ const workspaceAgentsAsArray = workspaceAgents.flatMap(({ agents }) => agents)
48
57
  const builtInAgents = publicAgents.map((a) => ({ id: a.id, label: a.name, image: a.avatar, slug: a.slug, builtIn: true }))
49
- return agents.map(a => ({ id: a.id, label: a.name, image: a.avatar, slug: a.slug, builtIn: false })).concat(builtInAgents)
58
+ return [...agentsAccount, ...agentsPersonal, ...agentsShared, ...workspaceAgentsAsArray]
59
+ .map(a => ({ id: a?.id, label: a?.name, image: a?.avatar, slug: a?.slug, builtIn: false }))
60
+ .concat(builtInAgents)
50
61
  } catch (error) {
51
62
  // eslint-disable-next-line no-console
52
63
  console.error(error)
@@ -1,24 +1,29 @@
1
1
  import { Button } from '@citric/core'
2
2
  import { Search } from '@citric/icons'
3
3
  import { Placeholder } from '@stack-spot/portal-components/Placeholder'
4
- import { aiClient, dataIntegrationClient } from '@stack-spot/portal-network'
4
+ import { aiClient, dataIntegrationClient, workspaceAiClient } from '@stack-spot/portal-network'
5
5
  import { KnowledgeSourceItemResponse, VisibilityLevelEnum } from '@stack-spot/portal-network/api/ai'
6
+ import { WorkspaceResponse } from '@stack-spot/portal-network/api/workspace-ai'
6
7
  import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
7
8
  import { difference, uniqBy } from 'lodash'
8
9
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
9
10
  import { ButtonFavorite } from '../components/ButtonFavorite'
11
+ import { NavigationComponent } from '../components/ComponentNavigator'
10
12
  import { DescribedCheckboxGroup } from '../components/form/DescribedCheckboxGroup'
11
13
  import { IconInput } from '../components/IconInput'
12
14
  import { RightPanelTabs } from '../components/RightPanelTabs'
15
+ import { WorkspaceTabNavigator } from '../components/WorkspaceTabNavigator'
13
16
  import { useCurrentChat, useWidget, useWidgetState } from '../context/hooks'
14
17
  import { useRightPanel } from '../right-panel/hooks'
15
18
  import { ChatProperties } from '../state/ChatState'
16
19
  import { checkIsTrial } from '../utils/check-is-trial'
17
20
 
18
- interface TabProps {
21
+ export interface TabProps {
19
22
  visibility: VisibilityLevelEnum,
20
- onSubmit: () => void,
21
23
  allKS: React.MutableRefObject<ChatProperties['knowledgeSources']>,
24
+ workspaceId?: string,
25
+ showSubmitButton?: boolean,
26
+ onSubmit?: () => void,
22
27
  }
23
28
 
24
29
  export const KnowledgeSources = () => {
@@ -55,7 +60,7 @@ const KnowledgeSourcesPanel = () => {
55
60
  useEffect(() => {
56
61
  allKS.current = chat.get('knowledgeSources') ?? []
57
62
  }, [chat])
58
-
63
+
59
64
  const tabs = isTrial ? [
60
65
  { title: t.favorites, content: <KnowledgeSourcesTab key="favorite" visibility="favorite" allKS={allKS} onSubmit={onSubmit} /> },
61
66
  { title: t.personal, content: <KnowledgeSourcesTab key="personal" visibility="personal" allKS={allKS} onSubmit={onSubmit} /> },
@@ -63,19 +68,23 @@ const KnowledgeSourcesPanel = () => {
63
68
  { title: t.favorites, content: <KnowledgeSourcesTab key="favorite" visibility="favorite" allKS={allKS} onSubmit={onSubmit} /> },
64
69
  { title: t.personal, content: <KnowledgeSourcesTab key="personal" visibility="personal" allKS={allKS} onSubmit={onSubmit} /> },
65
70
  { title: t.shared, content: <KnowledgeSourcesTab key="shared" visibility="shared" allKS={allKS} onSubmit={onSubmit} /> },
66
- { title: t.account, content: <KnowledgeSourcesTab key="account" visibility="account" allKS={allKS} onSubmit={onSubmit} /> },
71
+ { title: t.spots, content: <KnowledgeSourcesTabWorkspace key="workspace" visibility="workspace" allKS={allKS} onSubmit={onSubmit} /> },
72
+ { title: t.account, content: <KnowledgeSourcesTab key="account" visibility="account" allKS={allKS} onSubmit={onSubmit} /> },
67
73
  ]
68
-
74
+
69
75
  return <RightPanelTabs key={chat.id} tabs={tabs} />
70
76
  }
71
77
 
72
- const KnowledgeSourcesTab = ({ visibility, allKS, onSubmit }: TabProps) => {
78
+ export const KnowledgeSourcesTab = ({ visibility, allKS, onSubmit, workspaceId, showSubmitButton = true }: TabProps) => {
73
79
  const t = useTranslate(dictionary)
74
80
  const [filter, setFilter] = useState('')
75
-
76
- const knowledgeSources = aiClient.knowledgeSources.useQuery({
77
- visibility, order: 'a-to-z', types: ['snippet', 'api', 'event', 'custom'],
78
- })
81
+
82
+ const knowledgeSources = workspaceId
83
+ ? workspaceAiClient.getKSFromWorkspaceAi.useQuery({ workspaceId })
84
+ : aiClient.knowledgeSources.useQuery({
85
+ visibility, order: 'a-to-z', types: ['snippet', 'api', 'event', 'custom'],
86
+ })
87
+
79
88
  const listFavorites = dataIntegrationClient.knowledgeSources.useQuery({ visibility: 'favorite' })
80
89
  const [addFavorite, pendingAddFav] = dataIntegrationClient.addFavoriteKnowledgeSource.useMutation()
81
90
  const [removeFavorite, pendingRemoveFav] = dataIntegrationClient.removeFavoriteKnowledgeSource.useMutation()
@@ -131,7 +140,7 @@ const KnowledgeSourcesTab = ({ visibility, allKS, onSubmit }: TabProps) => {
131
140
  reject(error)
132
141
  }
133
142
  })
134
-
143
+
135
144
  const [value, setValue] = useState<KnowledgeSourceItemResponse[]>((() => {
136
145
  const currentlySelected = allKS.current?.map(ks => ks.id)
137
146
  return knowledgeSources.filter(ks => currentlySelected?.includes(ks.slug))
@@ -139,7 +148,7 @@ const KnowledgeSourcesTab = ({ visibility, allKS, onSubmit }: TabProps) => {
139
148
  const filtered = useMemo(
140
149
  () => filter
141
150
  // Recreate the list so that the favorites list is taken into account
142
- ? knowledgeSources.filter(ks => value.includes(ks) || ks.name.toLocaleLowerCase().includes(filter.toLocaleLowerCase()))
151
+ ? knowledgeSources.filter(ks => value.includes(ks) || ks.name.toLocaleLowerCase().includes(filter.toLocaleLowerCase()))
143
152
  : [...knowledgeSources]
144
153
  , [knowledgeSources, filter, value, listFavorites],
145
154
  )
@@ -181,11 +190,23 @@ const KnowledgeSourcesTab = ({ visibility, allKS, onSubmit }: TabProps) => {
181
190
  )}
182
191
  {!filtered.length && <Placeholder title={t.noData} description={t.noDataDescription} className="no-data-placeholder" />}
183
192
  </div>
184
- {!!filtered.length && <Button onClick={onSubmit}>{t.apply}</Button>}
193
+ {!!filtered.length && showSubmitButton && <Button onClick={onSubmit}>{t.apply}</Button>}
185
194
  </>
186
195
  )
187
196
  }
188
197
 
198
+ export function KnowledgeSourcesTabWorkspace({ allKS, onSubmit }: TabProps) {
199
+ const workspaceTabComponents = useMemo(() => ({ ks: KnowledgeSourcesTab }), [allKS, onSubmit])
200
+
201
+ const buildNavigateParams = (workspace: WorkspaceResponse): NavigationComponent<typeof workspaceTabComponents> => ({
202
+ component: 'ks',
203
+ props: { visibility: 'workspace', workspaceId: workspace.id, allKS, onSubmit },
204
+ })
205
+
206
+ return <WorkspaceTabNavigator components={workspaceTabComponents} getNavigateParam={buildNavigateParams} />
207
+ }
208
+
209
+
189
210
  const dictionary = {
190
211
  en: {
191
212
  title: 'Knowledge Sources',
@@ -199,6 +220,7 @@ const dictionary = {
199
220
  noSearchResultsDescription: 'Please, try another search term.',
200
221
  noData: 'There are no knowledge sources in this category yet.',
201
222
  noDataDescription: 'Use the tabs above to try other categories or use the AI portal to create new knowledge sources.',
223
+ spots: 'Spots',
202
224
  },
203
225
  pt: {
204
226
  title: 'Knowledge Sources',
@@ -212,5 +234,6 @@ const dictionary = {
212
234
  noSearchResultsDescription: 'Por favor, tente outra busca.',
213
235
  noData: 'Ainda não há knowledge sources nesta categoria.',
214
236
  noDataDescription: 'Use as abas acima para tentar outras categorias ou use o Portal AI para criar novos knowledge sources.',
237
+ spots: 'Spots',
215
238
  },
216
239
  } satisfies Dictionary
@@ -1,6 +1,6 @@
1
1
  import { Flex, IconBox, Image } from '@citric/core'
2
2
  import { Agent } from '@citric/icons'
3
- import { agentClient } from '@stack-spot/portal-network'
3
+ import { agentClient, workspaceAiClient } from '@stack-spot/portal-network'
4
4
  import { AgentResponse } from '@stack-spot/portal-network/api/agent'
5
5
  import { uniqBy } from 'lodash'
6
6
  import { useCallback } from 'react'
@@ -9,17 +9,23 @@ import { useCurrentChat, useCurrentChatState } from '../../context/hooks'
9
9
  import { agentRegex } from '../../regex'
10
10
  import { useAgentFavorites } from '../Agents/useAgentFavorites'
11
11
 
12
- const AgentItem = ({ avatar, name }: AgentResponse) => {
12
+ type AgentWithSpaceName = AgentResponse & { spaceName?: string }
13
+
14
+ const AgentItem = ({ avatar, name, spaceName }: AgentWithSpaceName) => {
13
15
  const avatarComponent = avatar ? <Image width="32" height="32" radius="full" src={avatar} /> : <IconBox size="md"><Agent /></IconBox>
14
16
 
15
17
  return <Flex flexWrap="nowrap" alignItems="center" sx={{ gap: '8px' }}>
16
18
  {avatarComponent}
17
- <p className="selector-title">{name}</p>
19
+ <div>
20
+ <p className="selector-description">{spaceName}</p>
21
+ <p className="selector-title">{name}</p>
22
+ </div>
18
23
  </Flex>
19
24
  }
20
25
 
21
26
  export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
22
- inputRef: React.RefObject<HTMLTextAreaElement | HTMLInputElement>, }) => {
27
+ inputRef: React.RefObject<HTMLTextAreaElement | HTMLInputElement>,
28
+ }) => {
23
29
  const chat = useCurrentChat()
24
30
  const isAgentEnabled = useCurrentChatState('features').agent
25
31
 
@@ -33,8 +39,10 @@ export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
33
39
  const isBuiltIn = agent.visibility_level === 'builtIn' || builtInsAgents.some((builtInAgent) => builtInAgent.id === agent.id)
34
40
  chat.set(
35
41
  'agent',
36
- { id: agent.id, label: agent.name, image: agent.avatar, slug: agent.slug,
37
- builtIn: isBuiltIn, visibility_level: agent.visibility_level },
42
+ {
43
+ id: agent.id, label: agent.name, image: agent.avatar, slug: agent.slug,
44
+ builtIn: isBuiltIn, visibility_level: agent.visibility_level,
45
+ },
38
46
  )
39
47
 
40
48
  if (!inputRef.current) return
@@ -46,6 +54,10 @@ export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
46
54
  const personalAgents = agentClient.agents.useQuery({ visibility: 'PERSONAL' })
47
55
  const publicAgents = agentClient.publicAgents.useQuery({})
48
56
  const builtInsAgents = [...publicAgents.map((agent) => ({ ...agent, visibility_level: 'builtIn' }))]
57
+ const workspaceAgents = workspaceAiClient.workspacesContentsByType.useQuery({ contentType: 'agent' })
58
+
59
+ const workspaceAgentsWithWorkspaceName = workspaceAgents.flatMap(({ agents, space_name }) =>
60
+ agents?.map((agent) => ({ ...agent, spaceName: space_name }))) as AgentWithSpaceName[]
49
61
  let accountAgents: AgentResponse[] = []
50
62
  let sharedAgents: AgentResponse[] = []
51
63
  if (!isTrial) {
@@ -53,7 +65,7 @@ export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
53
65
  sharedAgents = agentClient.agents.useQuery({ visibility: 'SHARED' }) || []
54
66
  }
55
67
 
56
- return uniqBy([...personalAgents, ...accountAgents, ...sharedAgents, ...builtInsAgents], 'id')
68
+ return uniqBy([...personalAgents, ...workspaceAgentsWithWorkspaceName, ...accountAgents, ...sharedAgents, ...builtInsAgents], 'id')
57
69
  }
58
70
 
59
71
  return <Selector
@@ -66,7 +78,7 @@ export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
66
78
  regex: agentRegex,
67
79
  urlBuilder: (agent) => `/agents/${agent?.id}`,
68
80
  searchProp: 'name',
69
- sections: isTrial ? ['favorite', 'personal', 'builtIn'] : ['favorite', 'personal', 'account', 'shared', 'builtIn'],
81
+ sections: isTrial ? ['favorite', 'personal', 'builtIn'] : ['favorite', 'personal', 'workspace', 'account', 'shared', 'builtIn'],
70
82
  renderComponentItem: AgentItem,
71
83
  isEnabled: isAgentEnabled,
72
84
  onSelect: onSelectItem,
@@ -1,4 +1,4 @@
1
- import { ChevronRight, Code, KnowledgeSource, Send, Stack, Times, Workspace } from '@citric/icons'
1
+ import { ChevronRight, Code, KnowledgeSource, Send, Spaces, Stack, Times } from '@citric/icons'
2
2
  import { IconButton } from '@citric/ui'
3
3
  import { listToClass } from '@stack-spot/portal-theme'
4
4
  import { useEffect, useRef } from 'react'
@@ -62,8 +62,8 @@ export const ButtonGroup = ({ onSend, onCancel, expanded, setExpanded, isLoading
62
62
  style={{ width: expanded ? featureButtonsWidth.current : 0 }}
63
63
  >
64
64
  {features.workspace && (
65
- <IconButton aria-label={t.workspace} title={t.workspace} onClick={() => widget.set('panel', 'workspace')}>
66
- <Workspace />
65
+ <IconButton aria-label={t.spot} title={t.spot} onClick={() => widget.set('panel', 'workspace')}>
66
+ <Spaces />
67
67
  </IconButton>
68
68
  )}
69
69
  {features.knowledgeSource && (
@@ -1,11 +1,13 @@
1
1
  import { QuickCommand } from '@citric/icons'
2
- import { aiClient } from '@stack-spot/portal-network'
3
- import { QuickCommandListResponse } from '@stack-spot/portal-network/api/ai'
2
+ import { aiClient, workspaceAiClient } from '@stack-spot/portal-network'
3
+ import { QuickCommandResponse } 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 } from '../../context/hooks'
7
7
  import { quickCommandRegex } from '../../regex'
8
8
 
9
+ type QuickCommandResponseWithSpaceName = QuickCommandResponse & { spaceName?: string }
10
+
9
11
  export const QuickCommandSelector = ({ inputRef, isTrial }:
10
12
  { isTrial: boolean, inputRef: React.RefObject<HTMLTextAreaElement | HTMLInputElement> }) => {
11
13
  const chat = useCurrentChat()
@@ -65,7 +67,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
65
67
  }
66
68
  })
67
69
 
68
- const onSelectItem = useCallback((qc: QuickCommandListResponse) => {
70
+ const onSelectItem = useCallback((qc: QuickCommandResponseWithSpaceName) => {
69
71
  const newValue = `/${qc.slug}`
70
72
  chat.set('nextMessage', newValue)
71
73
 
@@ -74,8 +76,19 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
74
76
  inputRef.current.focus()
75
77
  }, [chat, inputRef])
76
78
 
77
- const QuickCommandItem = ({ slug, description }: QuickCommandListResponse) => <>
78
- <p className="selector-title">/{slug.toUpperCase()}</p>
79
+ const getQuickCommands = () => {
80
+ const quickCommands = aiClient.quickCommands.useQuery({ order: 'a-to-z' })
81
+ const quickCommandsFiltered = quickCommands.filter((qc) => qc.visibility_level.toLowerCase() !== 'workspace')
82
+ const workspaceQuickCommands = workspaceAiClient.workspacesContentsByType.useQuery({ contentType: 'quick_command' })
83
+ const workspaceQuickCommandsWithWorkspaceName: QuickCommandResponseWithSpaceName[] = workspaceQuickCommands
84
+ .flatMap(({ qcs, space_name }) => qcs?.map((qc) => ({ ...qc, spaceName: space_name }))) as QuickCommandResponseWithSpaceName[]
85
+
86
+ return [...quickCommandsFiltered, ...workspaceQuickCommandsWithWorkspaceName]
87
+ }
88
+
89
+ const QuickCommandItem = ({ slug, description, spaceName }: QuickCommandResponseWithSpaceName) => <>
90
+ <p className="selector-description">{spaceName}</p>
91
+ <p className="selector-title">/{slug?.toUpperCase()}</p>
79
92
  <p className="selector-description">{description}</p>
80
93
  </>
81
94
 
@@ -95,7 +108,7 @@ export const QuickCommandSelector = ({ inputRef, isTrial }:
95
108
  isEnabled: isQuickCommandEnabled,
96
109
  onSelect: onSelectItem,
97
110
  renderComponentItem: QuickCommandItem,
98
- useData: () => aiClient.quickCommands.useQuery({ order: 'a-to-z' }),
111
+ useData: getQuickCommands,
99
112
  }}
100
113
  />
101
114
  }
@@ -4,7 +4,8 @@ const dictionary = {
4
4
  en: {
5
5
  stack: 'Select stack',
6
6
  code: 'Open code editor',
7
- workspace: 'Select workspace',
7
+ workspace: 'Select spot',
8
+ spot: 'Select spot',
8
9
  knowledgeSource: 'Select knowledge sources',
9
10
  agent: 'Select agent',
10
11
  collapse: 'Hide buttons',
@@ -14,7 +15,7 @@ const dictionary = {
14
15
  cancel: 'Cancel',
15
16
  removeConfig: 'Remove all the configuration',
16
17
  removeStack: 'Stop using the current stack',
17
- removeWorkspace: 'Stop using the current workspace',
18
+ removeWorkspace: 'Stop using the current spot',
18
19
  removeKS: 'Stop using this knowledge source',
19
20
  selected: 'Selected',
20
21
  removeSelection: 'Remove current code selection',
@@ -23,7 +24,8 @@ const dictionary = {
23
24
  pt: {
24
25
  stack: 'Selecionar stack',
25
26
  code: 'Abrir editor de código',
26
- workspace: 'Selecionar workspace',
27
+ workspace: 'Selecionar spot',
28
+ spot: 'Selecionar spot',
27
29
  knowledgeSource: 'Selecionar knowledge sources',
28
30
  agent: 'Selecionar agente',
29
31
  collapse: 'Esconder botões',
@@ -33,7 +35,7 @@ const dictionary = {
33
35
  cancel: 'Cancelar',
34
36
  removeConfig: 'Remover todas as configurações',
35
37
  removeStack: 'Parar de usar a stack atual',
36
- removeWorkspace: 'Parar de usar o workspace atual',
38
+ removeWorkspace: 'Parar de usar o spot atual',
37
39
  removeKS: 'Parar de usar este knowledge source',
38
40
  selected: 'Selecionado',
39
41
  removeSelection: 'Desfazer seleção de código',