@stack-spot/ai-chat-widget 1.20.0 → 1.20.2

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 (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/app-metadata.json +5 -5
  3. package/dist/components/Selector/index.d.ts +1 -1
  4. package/dist/components/Selector/index.d.ts.map +1 -1
  5. package/dist/components/Selector/index.js +4 -4
  6. package/dist/components/Selector/index.js.map +1 -1
  7. package/dist/components/WorkspaceTabNavigator.js +4 -4
  8. package/dist/components/WorkspaceTabNavigator.js.map +1 -1
  9. package/dist/views/Agents/AgentDescription.d.ts +2 -2
  10. package/dist/views/Agents/AgentDescription.d.ts.map +1 -1
  11. package/dist/views/Agents/AgentDescription.js +1 -3
  12. package/dist/views/Agents/AgentDescription.js.map +1 -1
  13. package/dist/views/Agents/AgentsPanel.d.ts.map +1 -1
  14. package/dist/views/Agents/AgentsPanel.js +2 -2
  15. package/dist/views/Agents/AgentsPanel.js.map +1 -1
  16. package/dist/views/Agents/AgentsTab.d.ts.map +1 -1
  17. package/dist/views/Agents/AgentsTab.js +5 -16
  18. package/dist/views/Agents/AgentsTab.js.map +1 -1
  19. package/dist/views/Agents/useAgentFavorites.d.ts +1 -1
  20. package/dist/views/Agents/useAgentFavorites.js +3 -3
  21. package/dist/views/Agents/useAgentFavorites.js.map +1 -1
  22. package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
  23. package/dist/views/Chat/ChatMessage.js +1 -3
  24. package/dist/views/Chat/ChatMessage.js.map +1 -1
  25. package/dist/views/ChatHistory/utils.d.ts.map +1 -1
  26. package/dist/views/ChatHistory/utils.js +3 -13
  27. package/dist/views/ChatHistory/utils.js.map +1 -1
  28. package/dist/views/MessageInput/AgentSelector.d.ts.map +1 -1
  29. package/dist/views/MessageInput/AgentSelector.js +11 -19
  30. package/dist/views/MessageInput/AgentSelector.js.map +1 -1
  31. package/dist/views/MessageInput/ButtonAgent.d.ts.map +1 -1
  32. package/dist/views/MessageInput/ButtonAgent.js +3 -4
  33. package/dist/views/MessageInput/ButtonAgent.js.map +1 -1
  34. package/dist/views/MessageInput/InfoBar.d.ts.map +1 -1
  35. package/dist/views/MessageInput/InfoBar.js +3 -1
  36. package/dist/views/MessageInput/InfoBar.js.map +1 -1
  37. package/dist/views/Steps/StepModal.d.ts.map +1 -1
  38. package/dist/views/Steps/StepModal.js +1 -1
  39. package/dist/views/Steps/StepModal.js.map +1 -1
  40. package/package.json +3 -3
  41. package/src/app-metadata.json +5 -5
  42. package/src/components/Selector/index.tsx +6 -6
  43. package/src/components/WorkspaceTabNavigator.tsx +4 -4
  44. package/src/views/Agents/AgentDescription.tsx +7 -7
  45. package/src/views/Agents/AgentsPanel.tsx +3 -2
  46. package/src/views/Agents/AgentsTab.tsx +12 -23
  47. package/src/views/Agents/useAgentFavorites.ts +3 -3
  48. package/src/views/Chat/ChatMessage.tsx +1 -3
  49. package/src/views/ChatHistory/utils.ts +3 -15
  50. package/src/views/MessageInput/AgentSelector.tsx +17 -27
  51. package/src/views/MessageInput/ButtonAgent.tsx +4 -4
  52. package/src/views/MessageInput/InfoBar.tsx +9 -3
  53. package/src/views/Steps/StepModal.tsx +0 -2
  54. package/dist/utils/agent.d.ts +0 -2
  55. package/dist/utils/agent.d.ts.map +0 -1
  56. package/dist/utils/agent.js +0 -2
  57. package/dist/utils/agent.js.map +0 -1
  58. package/src/utils/agent.ts +0 -1
@@ -1,15 +1,13 @@
1
1
  import { Flex, IconBox, Image } from '@citric/core'
2
2
  import { Agent } from '@citric/icons'
3
- import { agentClient, workspaceAiClient } from '@stack-spot/portal-network'
4
- import { AgentResponse } from '@stack-spot/portal-network/api/agent'
5
- import { uniqBy } from 'lodash'
3
+ import { agentClient, AgentResponseWithBuiltIn } from '@stack-spot/portal-network'
6
4
  import { useCallback } from 'react'
7
5
  import { Selector } from '../../components/Selector'
8
6
  import { useCurrentChat, useCurrentChatState } from '../../context/hooks'
9
7
  import { agentRegex } from '../../regex'
10
8
  import { useAgentFavorites } from '../Agents/useAgentFavorites'
11
9
 
12
- type AgentWithSpaceName = AgentResponse & { spaceName?: string }
10
+ type AgentWithSpaceName = AgentResponseWithBuiltIn
13
11
 
14
12
  const AgentItem = ({ avatar, name, spaceName }: AgentWithSpaceName) => {
15
13
  const avatarComponent = avatar ? <Image width="32" height="32" radius="full" src={avatar} /> : <IconBox size="md"><Agent /></IconBox>
@@ -23,25 +21,27 @@ const AgentItem = ({ avatar, name, spaceName }: AgentWithSpaceName) => {
23
21
  </Flex>
24
22
  }
25
23
 
26
- export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
24
+ export const AgentSelector = ({ inputRef, isTrial }: {
25
+ isTrial: boolean,
27
26
  inputRef: React.RefObject<HTMLTextAreaElement | HTMLInputElement>,
28
27
  }) => {
29
28
  const chat = useCurrentChat()
30
29
  const isAgentEnabled = useCurrentChatState('features').agent
31
30
 
32
31
  const { useFavorites, onAddFavorite, onRemoveFavorite } = useAgentFavorites()
33
-
34
- const onSelectItem = useCallback(async (agent: AgentResponse) => {
35
- const publicAgents = await agentClient.publicAgents.query({})
36
- const builtInsAgents = [...publicAgents.map((agent) => ({ ...agent, visibility_level: 'builtIn' }))]
32
+
33
+ const onSelectItem = useCallback(async (agent: AgentResponseWithBuiltIn) => {
37
34
  const newValue = `@${agent.slug}`
38
35
  chat.set('nextMessage', undefined)
39
- const isBuiltIn = agent.visibility_level === 'builtIn' || builtInsAgents.some((builtInAgent) => builtInAgent.id === agent.id)
40
36
  chat.set(
41
37
  'agent',
42
38
  {
43
- id: agent.id, label: agent.name, image: agent.avatar, slug: agent.slug,
44
- builtIn: isBuiltIn, visibility_level: agent.visibility_level,
39
+ id: agent.id,
40
+ label: agent.name,
41
+ image: agent.avatar,
42
+ slug: agent.slug,
43
+ builtIn: agent.builtIn,
44
+ visibility_level: agent.visibility_level,
45
45
  },
46
46
  )
47
47
 
@@ -50,22 +50,12 @@ export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
50
50
  inputRef.current.focus()
51
51
  }, [chat, inputRef])
52
52
 
53
- const getAgents = () => {
54
- const personalAgents = agentClient.agents.useQuery({ visibility: 'PERSONAL' })
55
- const publicAgents = agentClient.publicAgents.useQuery({})
56
- const builtInsAgents = [...publicAgents.map((agent) => ({ ...agent, visibility_level: 'builtIn' }))]
57
- const workspaceAgents = workspaceAiClient.workspacesContentsByType.useQuery({ contentType: 'agent' })
58
53
 
59
- const workspaceAgentsWithWorkspaceName = workspaceAgents.flatMap(({ agents, space_name }) =>
60
- agents?.map((agent) => ({ ...agent, spaceName: space_name }))) as AgentWithSpaceName[]
61
- let accountAgents: AgentResponse[] = []
62
- let sharedAgents: AgentResponse[] = []
63
- if (!isTrial) {
64
- accountAgents = agentClient.agents.useQuery({ visibility: 'ACCOUNT' }) || []
65
- sharedAgents = agentClient.agents.useQuery({ visibility: 'SHARED' }) || []
54
+ const getAgents = () => {
55
+ if (isTrial) {
56
+ return agentClient.allAgents.useQuery({ visibilities: ['PERSONAL', 'BUILT-IN'] })
66
57
  }
67
-
68
- return uniqBy([...personalAgents, ...workspaceAgentsWithWorkspaceName, ...accountAgents, ...sharedAgents, ...builtInsAgents], 'id')
58
+ return agentClient.allAgents.useQuery({ visibilities: ['ACCOUNT', 'SHARED', 'PERSONAL', 'BUILT-IN', 'WORKSPACE'] })
69
59
  }
70
60
 
71
61
  return <Selector
@@ -78,7 +68,7 @@ export const AgentSelector = ({ inputRef, isTrial }: { isTrial: boolean,
78
68
  regex: agentRegex,
79
69
  urlBuilder: (agent) => `/agents/${agent?.id}`,
80
70
  searchProp: 'name',
81
- sections: isTrial ? ['favorite', 'personal', 'builtIn'] : ['favorite', 'personal', 'workspace', 'account', 'shared', 'builtIn'],
71
+ sections: isTrial ? ['favorite', 'personal', 'built-in'] : ['favorite', 'personal', 'workspace', 'account', 'shared', 'built-in'],
82
72
  renderComponentItem: AgentItem,
83
73
  isEnabled: isAgentEnabled,
84
74
  onSelect: onSelectItem,
@@ -5,13 +5,11 @@ import { MiniLogo } from '@stack-spot/portal-components/svg'
5
5
  import { agentClient } from '@stack-spot/portal-network'
6
6
  import { useEffect } from 'react'
7
7
  import { useCurrentChat, useCurrentChatState, useWidget } from '../../context/hooks'
8
- import { isAgentDefault } from '../../utils/agent'
9
8
  import { useMessageInputDictionary } from './dictionary'
10
9
 
11
10
  export const ButtonAgent = () => {
12
11
  const t = useMessageInputDictionary()
13
- const [agentsBuiltIn] = agentClient.publicAgents.useStatefulQuery({})
14
- const agentDefault = agentsBuiltIn?.find((agent) => isAgentDefault(agent.slug))
12
+ const agentDefault = agentClient.agentDefault.useQuery({})
15
13
  const widget = useWidget()
16
14
  const chat = useCurrentChat()
17
15
  const agent = useCurrentChatState('agent')
@@ -37,6 +35,8 @@ export const ButtonAgent = () => {
37
35
  }
38
36
  }, [agentDefault, agent])
39
37
 
38
+ const isAgentDefault = () => agent?.id === agentDefault?.id
39
+
40
40
  return (
41
41
  <div className="button-group">
42
42
  {features.agent && (
@@ -44,7 +44,7 @@ export const ButtonAgent = () => {
44
44
  <IconButton aria-label={t.agent} title={t.agent} className="agent" onClick={() => widget.set('panel', 'agent')}>
45
45
  {agentDefault?.avatar ? <img src={agentDefault.avatar} className="image" /> : <MiniLogo />}
46
46
  </IconButton>
47
- {agent?.id && !isAgentDefault(agent?.slug) &&
47
+ {agent?.id && !isAgentDefault() &&
48
48
  <Tooltip text={t.remove} >
49
49
  <IconButton aria-label={t.remove} className="agent agent-selected" onClick={setAgentDefault}>
50
50
  {agent?.image ? <img src={agent.image} className="image" /> : <IconBox className="image" size="xs"><Agent /></IconBox>}
@@ -1,3 +1,4 @@
1
+ import { Text } from '@citric/core'
1
2
  import { Times, TimesMini } from '@citric/icons'
2
3
  import { Badge, IconButton } from '@citric/ui'
3
4
  import { loader } from '@monaco-editor/react'
@@ -15,9 +16,14 @@ interface InfoBadgeProps {
15
16
  }
16
17
 
17
18
  const InfoBadge = ({ label, color, dismiss, onDismiss }: InfoBadgeProps) => (
18
- <Badge appearance="square" palette={color} className="info-badge">
19
- {label}
20
- {onDismiss && <IconButton onClick={onDismiss} title={dismiss} arial-label={dismiss}><TimesMini /></IconButton>}
19
+ <Badge appearance="square" palette={color} className="info-badge"
20
+ afterElement={
21
+ onDismiss &&
22
+ <IconButton appearance="square" colorIcon={`${color}.800`} onClick={onDismiss} title={dismiss} arial-label={dismiss}>
23
+ <TimesMini />
24
+ </IconButton>
25
+ }>
26
+ <Text nowrapEllipsis>{label}</Text>
21
27
  </Badge>
22
28
  )
23
29
 
@@ -154,7 +154,6 @@ export const StepModal = ({ message, stepId, onClose }: Props) => {
154
154
  {attempt > 0 && (
155
155
  <IconButton
156
156
  size="xs"
157
- appearance="text"
158
157
  title={t.previousAttempt}
159
158
  aria-label={t.previousAttempt}
160
159
  onClick={() => setAttempt(attempt - 1)}
@@ -166,7 +165,6 @@ export const StepModal = ({ message, stepId, onClose }: Props) => {
166
165
  {attempt < step.attempts.length - 1 && (
167
166
  <IconButton
168
167
  size="xs"
169
- appearance="text"
170
168
  title={t.nextAttempt}
171
169
  aria-label={t.nextAttempt}
172
170
  onClick={() => setAttempt(attempt + 1)}
@@ -1,2 +0,0 @@
1
- export declare const isAgentDefault: (agentSlug?: string) => agentSlug is "stk_code_buddy";
2
- //# sourceMappingURL=agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,eAAgB,MAAM,kCAAmC,CAAA"}
@@ -1,2 +0,0 @@
1
- export const isAgentDefault = (agentSlug) => agentSlug === 'stk_code_buddy';
2
- //# sourceMappingURL=agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAE,EAAE,CAAC,SAAS,KAAK,gBAAgB,CAAA"}
@@ -1 +0,0 @@
1
- export const isAgentDefault = (agentSlug?: string) => agentSlug === 'stk_code_buddy'