@stack-spot/ai-chat-widget 1.0.0-dev.1768326007410 → 1.0.0-dev.1768329683444

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 (60) hide show
  1. package/dist/app-metadata.json +3 -3
  2. package/dist/chat-interceptors/send-message.d.ts.map +1 -1
  3. package/dist/chat-interceptors/send-message.js +5 -1
  4. package/dist/chat-interceptors/send-message.js.map +1 -1
  5. package/dist/components/Selector/SelectVersion.d.ts +12 -0
  6. package/dist/components/Selector/SelectVersion.d.ts.map +1 -0
  7. package/dist/components/Selector/SelectVersion.js +33 -0
  8. package/dist/components/Selector/SelectVersion.js.map +1 -0
  9. package/dist/components/Selector/index.d.ts +2 -0
  10. package/dist/components/Selector/index.d.ts.map +1 -1
  11. package/dist/components/Selector/index.js +5 -2
  12. package/dist/components/Selector/index.js.map +1 -1
  13. package/dist/components/Selector/styled.d.ts +2 -0
  14. package/dist/components/Selector/styled.d.ts.map +1 -1
  15. package/dist/components/Selector/styled.js +45 -0
  16. package/dist/components/Selector/styled.js.map +1 -1
  17. package/dist/hooks/enabled-feature-flags.d.ts +5 -0
  18. package/dist/hooks/enabled-feature-flags.d.ts.map +1 -0
  19. package/dist/hooks/enabled-feature-flags.js +28 -0
  20. package/dist/hooks/enabled-feature-flags.js.map +1 -0
  21. package/dist/state/types.d.ts +1 -0
  22. package/dist/state/types.d.ts.map +1 -1
  23. package/dist/utils/tools.d.ts +5 -5
  24. package/dist/utils/tools.d.ts.map +1 -1
  25. package/dist/utils/tools.js +2 -2
  26. package/dist/utils/tools.js.map +1 -1
  27. package/dist/views/Agents/AgentDescription.d.ts +6 -2
  28. package/dist/views/Agents/AgentDescription.d.ts.map +1 -1
  29. package/dist/views/Agents/AgentDescription.js +25 -10
  30. package/dist/views/Agents/AgentDescription.js.map +1 -1
  31. package/dist/views/Agents/AgentsTab.d.ts.map +1 -1
  32. package/dist/views/Agents/AgentsTab.js +21 -4
  33. package/dist/views/Agents/AgentsTab.js.map +1 -1
  34. package/dist/views/Agents/dictionary.d.ts +1 -1
  35. package/dist/views/Agents/dictionary.d.ts.map +1 -1
  36. package/dist/views/Agents/dictionary.js +2 -0
  37. package/dist/views/Agents/dictionary.js.map +1 -1
  38. package/dist/views/ChatHistory/utils.js +1 -1
  39. package/dist/views/ChatHistory/utils.js.map +1 -1
  40. package/dist/views/MessageInput/AgentSelector.d.ts.map +1 -1
  41. package/dist/views/MessageInput/AgentSelector.js +11 -1
  42. package/dist/views/MessageInput/AgentSelector.js.map +1 -1
  43. package/dist/views/MessageInput/ModelSwitcher/utils.d.ts +2 -2
  44. package/dist/views/MessageInput/ModelSwitcher/utils.d.ts.map +1 -1
  45. package/dist/views/MessageInput/ModelSwitcher/utils.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/app-metadata.json +3 -3
  48. package/src/chat-interceptors/send-message.ts +6 -2
  49. package/src/components/Selector/SelectVersion.tsx +55 -0
  50. package/src/components/Selector/index.tsx +11 -2
  51. package/src/components/Selector/styled.ts +47 -0
  52. package/src/hooks/enabled-feature-flags.ts +31 -0
  53. package/src/state/types.ts +1 -0
  54. package/src/utils/tools.ts +4 -4
  55. package/src/views/Agents/AgentDescription.tsx +48 -14
  56. package/src/views/Agents/AgentsTab.tsx +31 -13
  57. package/src/views/Agents/dictionary.ts +2 -1
  58. package/src/views/ChatHistory/utils.ts +4 -4
  59. package/src/views/MessageInput/AgentSelector.tsx +15 -5
  60. package/src/views/MessageInput/ModelSwitcher/utils.tsx +2 -2
@@ -9,6 +9,7 @@ import { NavigationComponent } from '../../components/ComponentNavigator'
9
9
  import { DescribedRadioGroup } from '../../components/form/DescribedRadioGroup'
10
10
  import { WorkspaceTabNavigator } from '../../components/WorkspaceTabNavigator'
11
11
  import { useCurrentChat } from '../../context/hooks'
12
+ import { useIsFeatureFlagEnabled } from '../../hooks/enabled-feature-flags'
12
13
  import { useRightPanel } from '../../right-panel/hooks'
13
14
  import { ChatProperties } from '../../state/ChatState'
14
15
  import { AgentDescription } from './AgentDescription'
@@ -28,9 +29,10 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
28
29
  const chat = useCurrentChat()
29
30
  const { useFavorites, onAddFavorite, onRemoveFavorite } = useAgentFavorites()
30
31
  const [submitEnabled, setSubmitEnabled] = useState(false)
32
+ const featureFlag = useIsFeatureFlagEnabled('ENABLE_VERSION_CONTENT_AI')
31
33
  const listFavorites = useFavorites()
32
34
  const agentDefault = agentToolsClient.agentDefault.useQuery()
33
-
35
+ const [agentVersions, setAgentVersions] = useState<Record<string, number | undefined>>({})
34
36
  const [filter, setFilter] = useState<string | undefined>()
35
37
  const [apiFilter, setApiFilter] = useState<string | undefined>()
36
38
  const [isPending, startTransition] = useTransition()
@@ -59,15 +61,15 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
59
61
 
60
62
  const agents = workspaceId ? workspaceAgents : agentsData
61
63
 
62
- const initialValue = useMemo<AgentResponseWithBuiltIn | undefined>(
63
- () => {
64
- const initial = agent.current
65
- ? agents?.find(a => a.id === agent.current?.id)
66
- : chat.get('agent') ? agents?.find(a => a.id === chat.get('agent')?.id) : agentDefault as unknown as AgentResponseWithBuiltIn
67
- if (initial && !submitEnabled) setSubmitEnabled(true)
68
- return initial
69
- },
70
- [agents],
64
+ const initialValue = useMemo<AgentResponseWithBuiltIn | undefined>(() => {
65
+ const initial = agent.current
66
+ ? agents?.find(a => a.id === agent.current?.id)
67
+ : chat.get('agent') ?
68
+ agents?.find(a => a.id === chat.get('agent')?.id) : { ...agentDefault, suggested_prompts: null } as AgentResponseWithBuiltIn
69
+ if (initial && !submitEnabled) setSubmitEnabled(true)
70
+ return initial
71
+ },
72
+ [agents],
71
73
  )
72
74
 
73
75
  function submit() {
@@ -75,12 +77,26 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
75
77
  close()
76
78
  }
77
79
 
80
+ const onVersionChange = (ag: AgentResponseWithBuiltIn, version?: number) => {
81
+ setAgentVersions(prev => ({
82
+ ...prev,
83
+ [ag.id]: version,
84
+ }))
85
+
86
+ if (agent.current?.id === ag.id) {
87
+ agent.current = {
88
+ ...agent.current,
89
+ agent_version_number: version,
90
+ }
91
+ }
92
+ }
93
+
78
94
  return <>
79
95
  <div className="content">
80
96
  <DescribedRadioGroup
81
97
  fetchNextPage={fetchNextPage}
82
98
  hasNextPage={hasNextPage && !workspaceId}
83
- options={agents}
99
+ options={agents || []}
84
100
  initialValue={initialValue}
85
101
  filter={workspaceId ? undefined : filter}
86
102
  setFilter={workspaceId ? undefined : (value?: string) => {
@@ -89,7 +105,8 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
89
105
  }}
90
106
  onChange={(ag) => {
91
107
  agent.current = ag
92
- ? { ...ag, label: ag.name, image: ag.avatar!, slug: ag.slug, builtIn: ag.visibility_level === 'built_in' }
108
+ ? { ...ag, label: ag.name, image: ag.avatar!, slug: ag.slug, builtIn: ag.visibility_level === 'built_in',
109
+ agent_version_number: agentVersions[ag.id] ?? ag.version_number }
93
110
  : undefined
94
111
  setSubmitEnabled(true)
95
112
  }}
@@ -98,7 +115,8 @@ export const AgentsTab = ({ visibility, workspaceId, agent, showSubmitButton = t
98
115
  idOrSlug: ag.id,
99
116
  // below, "key" is important. I don't know why exactly, but sometimes the avatar doesn't update if we don't do this.
100
117
  image: <ImageWithFallback key={ag.id} src={ag.avatar ?? undefined} fallback={<Icon icon="Agent" />} />,
101
- description: <AgentDescription agentId={ag.id} />,
118
+ description: <AgentDescription agentId={ag.id} enableVersionSelect={featureFlag.flagEnabled}
119
+ onVersionChange={(version?: number) => onVersionChange(ag, version)} />,
102
120
  name: ag.name,
103
121
  listFavorites,
104
122
  onAddFavorite,
@@ -19,6 +19,7 @@ const dictionary = {
19
19
  tools: 'Tools',
20
20
  spots: 'Spots',
21
21
  multiAgent: 'Multi-agents',
22
+ version: 'Version',
22
23
  },
23
24
  pt: {
24
25
  title: 'Agentes',
@@ -38,7 +39,7 @@ const dictionary = {
38
39
  tools: 'Ferramentas',
39
40
  spots: 'Spots',
40
41
  multiAgent: 'Multi-agents',
41
-
42
+ version: 'Versão',
42
43
  },
43
44
  } satisfies Dictionary
44
45
 
@@ -1,5 +1,5 @@
1
1
  import { agentToolsClient, aiClient, AnswerChatStep, ChatAgentTool, ChatStep, PlanningChatStep, workspaceClient } from '@stack-spot/portal-network'
2
- import { AgentModel } from '@stack-spot/portal-network/api/agent-tools'
2
+ import { FindByIdAgentResponse } from '@stack-spot/portal-network/api/agent-tools'
3
3
  import { last } from 'lodash'
4
4
  import { ChatEntry } from '../../state/ChatEntry'
5
5
  import { ChatProperties, ChatState } from '../../state/ChatState'
@@ -56,7 +56,7 @@ function toJSONString(data: any) {
56
56
  return `${data}`
57
57
  }
58
58
 
59
- function findTool(agent: AgentModel | undefined, id: string) {
59
+ function findTool(agent: FindByIdAgentResponse | undefined, id: string) {
60
60
  const allToolkits = [
61
61
  ...agent?.toolkits?.builtin_toolkits ?? [],
62
62
  ...agent?.toolkits?.custom_toolkits ?? [],
@@ -75,7 +75,7 @@ async function stepsFromAgentInfo(
75
75
  ): Promise<ChatStep[] | undefined> {
76
76
  const planningInfo = agentInfo?.find(i => i.type === 'planning' && !!i.data)
77
77
  if (planningInfo) {
78
- let agent: AgentModel | undefined
78
+ let agent: FindByIdAgentResponse | undefined
79
79
  try {
80
80
  agent = agentId ? await agentToolsClient.agent.query({ agentId }) : undefined
81
81
  } catch { /* empty */ }
@@ -105,7 +105,7 @@ async function stepsFromAgentInfo(
105
105
  return {
106
106
  id: t.tool_id,
107
107
  executionId: t.tool_execution_id,
108
- name: tool?.name,
108
+ name: ('name' in tool ? tool.name : ('function' in tool ? tool?.function?.name : undefined) ?? ''),
109
109
  description: 'description' in tool ? tool.description : undefined,
110
110
  image: toolkit ? (('image_url' in toolkit ? toolkit?.image_url : toolkit?.avatar) ?? undefined) : undefined,
111
111
  goal: t.goal,
@@ -5,16 +5,16 @@ import { VisibilityLevelEnum } from '@stack-spot/portal-network/api/agent-tools'
5
5
  import { useCallback } from 'react'
6
6
  import { Selector } from '../../components/Selector'
7
7
  import { useCurrentChat, useCurrentChatState, useWidgetState } from '../../context/hooks'
8
+ import { useIsFeatureFlagEnabled } from '../../hooks/enabled-feature-flags'
8
9
  import { agentRegex } from '../../regex'
9
10
  import { useAgentFavorites } from '../Agents/useAgentFavorites'
10
11
 
11
- type AgentWithSpaceName = AgentResponseWithBuiltIn
12
-
13
- const AgentItem = ({ avatar, name, spaceName }: AgentWithSpaceName) => {
12
+ const AgentItem = ({ avatar, name, spaceName }: AgentResponseWithBuiltIn) => {
14
13
  const avatarComponent = avatar
15
14
  ? <img style={{ width: '32px', height: '32px', borderRadius: '50%' }} src={avatar} />
16
15
  : <IconBox size="md" icon="Agent" style={{ backgroundColor: 'transparent' }} />
17
16
 
17
+
18
18
  return <Row gap="8px" style={{ flexWrap: 'nowrap' }}>
19
19
  {avatarComponent}
20
20
  <div>
@@ -31,10 +31,11 @@ export const AgentSelector = ({ inputRef, isTrial }: {
31
31
  const chat = useCurrentChat()
32
32
  const isAgentEnabled = useCurrentChatState('features').agent
33
33
  const spotId = useWidgetState('features')?.workspaceId
34
+ const featureFlag = useIsFeatureFlagEnabled('ENABLE_VERSION_CONTENT_AI')
34
35
 
35
36
  const { useFavorites, onAddFavorite, onRemoveFavorite } = useAgentFavorites()
36
37
 
37
- const onSelectItem = useCallback(async (agent: AgentResponseWithBuiltIn) => {
38
+ const onSelectItem = useCallback(async (agent: AgentResponseWithBuiltIn, selectedVersion?: number) => {
38
39
  const newValue = `@${agent.slug}`
39
40
  chat.set('nextMessage', undefined)
40
41
  chat.set(
@@ -42,10 +43,11 @@ export const AgentSelector = ({ inputRef, isTrial }: {
42
43
  {
43
44
  id: agent.id,
44
45
  label: agent.name,
45
- image: agent.avatar,
46
+ image: agent.avatar,
46
47
  slug: agent.slug,
47
48
  builtIn: agent.builtIn,
48
49
  visibility_level: agent.visibility_level,
50
+ agent_version_number: selectedVersion || agent.version_number,
49
51
  },
50
52
  )
51
53
 
@@ -70,6 +72,12 @@ export const AgentSelector = ({ inputRef, isTrial }: {
70
72
  }) }
71
73
  }
72
74
 
75
+ const getAgentVersions = (id: string, enabled: boolean) => {
76
+ const [listVersions] = agentToolsClient.listAgentVersions.useStatefulQuery({ agentCoreId: id }, { enabled })
77
+ const optionsVersions = listVersions?.map((version) => version.version_number)
78
+ return optionsVersions
79
+ }
80
+
73
81
  return <Selector
74
82
  inputRef={inputRef}
75
83
  favorite={{ useFavorites, onAddFavorite, onRemoveFavorite }}
@@ -85,8 +93,10 @@ export const AgentSelector = ({ inputRef, isTrial }: {
85
93
  ['favorite', 'personal', 'workspace', 'account', 'shared', 'built_in', 'recently_used'],
86
94
  renderComponentItem: AgentItem,
87
95
  isEnabled: isAgentEnabled,
96
+ isEnabledVersionContent: featureFlag.flagEnabled,
88
97
  onSelect: onSelectItem,
89
98
  useData: getAgents,
99
+ useVersions: getAgentVersions,
90
100
  }}
91
101
  />
92
102
  }
@@ -1,6 +1,6 @@
1
1
  import { CitricIconOutline, CitricIconSocial } from '@stack-spot/citric-icons'
2
2
  import { IconBox } from '@stack-spot/citric-react'
3
- import { AgentModel } from '@stack-spot/portal-network/api/agent-tools'
3
+ import { FindByIdAgentResponse } from '@stack-spot/portal-network/api/agent-tools'
4
4
  import { LlmModelsResponse, PaginatedResponseLlmModelsResponse } from '@stack-spot/portal-network/api/genAiInference'
5
5
  import { theme } from '@stack-spot/portal-theme'
6
6
  import { Dispatch, ReactElement } from 'react'
@@ -27,7 +27,7 @@ export const providerIcon: Record<string, CitricIconSocial | CitricIconOutline>
27
27
  export function getListModelsData(
28
28
  chat: ChatState,
29
29
  setVisibleMenu: Dispatch<React.SetStateAction<boolean>>,
30
- agent?: AgentModel,
30
+ agent?: FindByIdAgentResponse,
31
31
  models?: PaginatedResponseLlmModelsResponse) {
32
32
 
33
33
  const chatSelectedModelId = chat.get('selected_model_id')