@stack-spot/ai-chat-widget 2.2.1 → 2.2.3-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 (86) hide show
  1. package/CHANGELOG.md +41 -6
  2. package/dist/app-metadata.json +6 -6
  3. package/dist/chat-interceptors/send-message.d.ts.map +1 -1
  4. package/dist/chat-interceptors/send-message.js +130 -1
  5. package/dist/chat-interceptors/send-message.js.map +1 -1
  6. package/dist/state/ChatEntry.d.ts +1 -1
  7. package/dist/state/ChatEntry.d.ts.map +1 -1
  8. package/dist/state/ChatEntry.js +2 -1
  9. package/dist/state/ChatEntry.js.map +1 -1
  10. package/dist/state/ChatState.d.ts +8 -0
  11. package/dist/state/ChatState.d.ts.map +1 -1
  12. package/dist/state/ChatState.js.map +1 -1
  13. package/dist/utils/chat.d.ts.map +1 -1
  14. package/dist/utils/chat.js +1 -0
  15. package/dist/utils/chat.js.map +1 -1
  16. package/dist/utils/planning-tool.d.ts +17 -0
  17. package/dist/utils/planning-tool.d.ts.map +1 -0
  18. package/dist/utils/planning-tool.js +32 -0
  19. package/dist/utils/planning-tool.js.map +1 -0
  20. package/dist/utils/update-tool-step.d.ts +3 -0
  21. package/dist/utils/update-tool-step.d.ts.map +1 -0
  22. package/dist/utils/update-tool-step.js +23 -0
  23. package/dist/utils/update-tool-step.js.map +1 -0
  24. package/dist/views/Chat/ChatMessage.d.ts +1 -1
  25. package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
  26. package/dist/views/Chat/ChatMessage.js +21 -6
  27. package/dist/views/Chat/ChatMessage.js.map +1 -1
  28. package/dist/views/Chat/StepsList.d.ts +13 -2
  29. package/dist/views/Chat/StepsList.d.ts.map +1 -1
  30. package/dist/views/Chat/StepsList.js +156 -21
  31. package/dist/views/Chat/StepsList.js.map +1 -1
  32. package/dist/views/Chat/styled.d.ts.map +1 -1
  33. package/dist/views/Chat/styled.js +17 -10
  34. package/dist/views/Chat/styled.js.map +1 -1
  35. package/dist/views/MessageInput/ButtonBar.d.ts.map +1 -1
  36. package/dist/views/MessageInput/ButtonBar.js +2 -1
  37. package/dist/views/MessageInput/ButtonBar.js.map +1 -1
  38. package/dist/views/MessageInput/ModelSwitcher/index.d.ts +2 -0
  39. package/dist/views/MessageInput/ModelSwitcher/index.d.ts.map +1 -0
  40. package/dist/views/MessageInput/ModelSwitcher/index.js +25 -0
  41. package/dist/views/MessageInput/ModelSwitcher/index.js.map +1 -0
  42. package/dist/views/MessageInput/ModelSwitcher/utils.d.ts +29 -0
  43. package/dist/views/MessageInput/ModelSwitcher/utils.d.ts.map +1 -0
  44. package/dist/views/MessageInput/ModelSwitcher/utils.js +101 -0
  45. package/dist/views/MessageInput/ModelSwitcher/utils.js.map +1 -0
  46. package/dist/views/MessageInput/dictionary.d.ts +1 -1
  47. package/dist/views/MessageInput/dictionary.d.ts.map +1 -1
  48. package/dist/views/MessageInput/dictionary.js +6 -0
  49. package/dist/views/MessageInput/dictionary.js.map +1 -1
  50. package/dist/views/MessageInput/styled.d.ts +12 -0
  51. package/dist/views/MessageInput/styled.d.ts.map +1 -1
  52. package/dist/views/MessageInput/styled.js +35 -0
  53. package/dist/views/MessageInput/styled.js.map +1 -1
  54. package/dist/views/Steps/FlowChart/NodeStep.js +1 -1
  55. package/dist/views/Steps/FlowChart/NodeStep.js.map +1 -1
  56. package/dist/views/Steps/FlowChart/layout.d.ts +1 -1
  57. package/dist/views/Steps/FlowChart/layout.d.ts.map +1 -1
  58. package/dist/views/Steps/FlowChart/layout.js +1 -0
  59. package/dist/views/Steps/FlowChart/layout.js.map +1 -1
  60. package/dist/views/Steps/FlowChart/types.d.ts +1 -1
  61. package/dist/views/Steps/FlowChart/types.d.ts.map +1 -1
  62. package/dist/views/Steps/StepModal.js +2 -2
  63. package/dist/views/Steps/StepModal.js.map +1 -1
  64. package/dist/views/Steps/dictionary.d.ts +1 -1
  65. package/dist/views/Steps/utils.d.ts +1 -1
  66. package/dist/views/Steps/utils.d.ts.map +1 -1
  67. package/package.json +4 -4
  68. package/src/app-metadata.json +6 -6
  69. package/src/chat-interceptors/send-message.ts +146 -2
  70. package/src/state/ChatEntry.ts +2 -1
  71. package/src/state/ChatState.ts +8 -0
  72. package/src/utils/chat.ts +1 -0
  73. package/src/utils/planning-tool.ts +41 -0
  74. package/src/utils/update-tool-step.tsx +27 -0
  75. package/src/views/Chat/ChatMessage.tsx +25 -5
  76. package/src/views/Chat/StepsList.tsx +340 -48
  77. package/src/views/Chat/styled.ts +17 -10
  78. package/src/views/MessageInput/ButtonBar.tsx +2 -0
  79. package/src/views/MessageInput/ModelSwitcher/index.tsx +67 -0
  80. package/src/views/MessageInput/ModelSwitcher/utils.tsx +148 -0
  81. package/src/views/MessageInput/dictionary.ts +6 -0
  82. package/src/views/MessageInput/styled.ts +37 -0
  83. package/src/views/Steps/FlowChart/NodeStep.tsx +1 -1
  84. package/src/views/Steps/FlowChart/layout.ts +1 -0
  85. package/src/views/Steps/FlowChart/types.ts +1 -1
  86. package/src/views/Steps/StepModal.tsx +2 -2
@@ -1,100 +1,392 @@
1
- import { Icon } from '@stack-spot/citric-icons'
2
- import { Button, ProgressCircular, Text } from '@stack-spot/citric-react'
1
+ import { Accordion, Badge, Button, Card, Column, Divider, Icon, IconBox, ImageWithFallback, ProgressCircular, Row, Skeleton, Text } from '@stack-spot/citric-react'
3
2
  import { AnimatedHeight } from '@stack-spot/portal-components/AnimatedHeight'
4
- import { ChatStep, StepChatStep } from '@stack-spot/portal-network'
3
+ import { ChatStep, StepChatStep, ToolChatStep } from '@stack-spot/portal-network'
5
4
  import { theme } from '@stack-spot/portal-theme'
6
5
  import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
7
- import { findLastIndex } from 'lodash'
8
- import { useState } from 'react'
9
- import { useWidget } from '../../context/hooks'
6
+ import { findLast, findLastIndex } from 'lodash'
7
+ import React, { useEffect, useMemo } from 'react'
8
+ import styled from 'styled-components'
9
+ import { Markdown } from '../../components/Markdown'
10
+ import { useChat, useChatMessages, useCurrentChat, useCurrentChatMessages, useWidget } from '../../context/hooks'
11
+ import { ChatEntry } from '../../state/ChatEntry'
12
+ import { planningToolDictionaryHelper } from '../../utils/planning-tool'
13
+ import { updateToolStep } from '../../utils/update-tool-step'
14
+ import { onCopyCode } from './events'
10
15
 
11
16
  interface Props {
12
17
  steps: ChatStep[],
13
18
  messageId: number,
14
19
  chatId: string,
20
+ userHasAlreadyAnswered?: boolean,
21
+ }
22
+
23
+ interface StepChatStepWithTarget extends Omit<StepChatStep, 'status' | 'id' | 'type'> {
24
+ status: 'pending' | 'running' | 'success' | 'error' | 'target' | 'awaiting_approval',
15
25
  }
16
26
 
17
27
  interface StepProps {
18
- step: StepChatStep,
28
+ step: StepChatStepWithTarget,
19
29
  index: number,
20
- total: number,
30
+ total?: number,
31
+ totalTools?: number,
32
+ isAllDone?: boolean,
21
33
  onClick?: () => void,
22
34
  }
23
35
 
24
- function getStatusIcon(status: ChatStep['status']) {
36
+ function getStatusIcon(status: StepChatStepWithTarget['status'] | 'target', isDone?: boolean) {
25
37
  const iconProps = { style: { color: theme.color.light[700] }, size: 'xs' } as const
26
38
  switch (status) {
27
39
  case 'error': return <Icon group="fill" icon="TimesCircle" {...iconProps} />
28
40
  case 'success': return <Icon group="fill" icon="CheckCircle" {...iconProps} />
29
- case 'pending': return <Icon icon="Spaces" {...iconProps} />
41
+ case 'pending': return <Icon group="fill" icon="Circle" {...iconProps} style={{ color: theme.color.light[600] }} />
42
+ case 'awaiting_approval': return <Icon group="fill" icon="ExclamationTriangle" {...iconProps} />
43
+ case 'target': return <Icon icon="Target" {...iconProps} style={{ color: isDone ? theme.color.light[700] : theme.color.light[600] }} />
30
44
  case 'running': return <ProgressCircular className="loading" colorScheme="inverse" size="xs" />
31
45
  }
32
46
  }
33
47
 
34
- const Step = ({ step, index, total, onClick }: StepProps) => {
48
+ const StepAccordionHeader = ({ step, index, expand }: Pick<StepProps, 'step' | 'index'> & { expand: React.ReactElement }) => {
49
+ const t = useTranslate(dictionary)
50
+ return <Row gap="8px">
51
+ {expand}
52
+ {step.status === 'target' ? <Text className="step-title" appearance="body2" color="light.700">{t.planGoal}:</Text> :
53
+ <Badge colorScheme="inverse" appearance="square">
54
+ {t.step} {index}
55
+ </Badge>}
56
+ <Text className="step-title" appearance="body2">
57
+ {step.input}
58
+ </Text>
59
+ {step.status === 'awaiting_approval' &&
60
+ <Badge appearance="square" style={{ backgroundColor: theme.color.gray[800], color: theme.color.gray[50] }}>
61
+ <Icon icon="Security" />
62
+ {t.pendingReview}
63
+ </Badge>}
64
+ </Row>
65
+ }
66
+
67
+ const StyledCard = styled(Card)`
68
+ &:hover {
69
+ background-color: ${theme.color.light[500]}
70
+ }
71
+ `
72
+
73
+ const Step = ({ step, index, onClick, total, totalTools, isAllDone }: StepProps) => {
35
74
  const t = useTranslate(dictionary)
75
+ const status = getStatusIcon(step.status, isAllDone)
76
+ const hasTools = step.attempts?.[0]?.tools && step.attempts?.[0]?.tools?.length > 0
77
+
36
78
  return (
37
79
  <li tabIndex={onClick ? 0 : undefined} onClick={onClick} role={onClick ? 'button' : 'listitem'}>
38
- <div className="step-status-icon">{getStatusIcon(step.status)}</div>
39
- <Text className="step-title" appearance="microtext1" color="light.700">
40
- {t.step} {index}/{total}: {step.input}
41
- </Text>
80
+ <Row gap="4px" alignItems="center">
81
+ <div className="step-status-icon">{status}</div>
82
+ <StyledCard p="8px" w="80%">
83
+ <Accordion header={expand => <StepAccordionHeader step={step} index={index} expand={expand} />}>
84
+ <Column pt="12px">
85
+ {total ?
86
+ <Row gap="40px">
87
+ <Row gap="4px">
88
+ <Icon icon="Hashtag" size="sm" color="light.700" />
89
+ <Text color="light.700">{t.totalSteps}</Text>
90
+ {total}
91
+ </Row>
92
+ <Row gap="4px">
93
+ <Icon icon="BorderRadius" size="sm" color="light.700" />
94
+ <Text color="light.700">{t.totalTools}</Text>
95
+ {totalTools ?? 0}
96
+ </Row>
97
+ </Row>
98
+ : <>
99
+ <Row pb="8px">
100
+ <Icon icon="Target" size="sm" color="light.700" />
101
+ <Text color="light.700" tag="span" style={{ margin: '0 4px' }}>{t.stepGoal}:</Text>
102
+ <Text tag="span">
103
+ {step.input}
104
+ </Text>
105
+ </Row>
106
+ {hasTools ? <>
107
+ <Row gap="4px">
108
+ <Icon icon="BorderRadius" size="sm" color="light.700" />
109
+ <Text color="light.700">{t.toolsToBeExecuted}:</Text>
110
+ </Row>
111
+ <ul className="tools-list">
112
+ {step.attempts?.[0]?.tools?.map((tool, index) => (<li key={`${tool.id}-${index}`}>
113
+ <Text>{tool.name}: {tool.goal}</Text>
114
+ </li>))}
115
+ </ul>
116
+ </> : <Row gap="4px">
117
+ <Icon icon="BorderRadius" size="sm" color="light.700" />
118
+ <Text color="light.700">{t.noToolToBeUsed}</Text>
119
+ </Row>
120
+ }
121
+ </>
122
+ }
123
+ </Column>
124
+ </Accordion>
125
+ </StyledCard>
126
+ </Row>
42
127
  </li>
43
128
  )
44
129
  }
45
130
 
46
- export const StepsList = ({ steps, chatId, messageId }: Props) => {
131
+ export const StepsPlaceholder = () => {
47
132
  const t = useTranslate(dictionary)
48
- const [isExpanded, setExpanded] = useState(false)
49
- const actualSteps = steps.filter(s => s.type === 'step')
50
- let currentStepIndex = findLastIndex(actualSteps, s => s.status === 'running' || s.status === 'success')
51
- if (currentStepIndex === -1) currentStepIndex = 0
52
- const widget = useWidget()
133
+ return <Card gap="8px">
134
+ <Row gap="8px">
135
+ <ProgressCircular colorScheme="inverse" size="xs" />
136
+ <Text color="light.700">{t.generatingPlan}</Text>
137
+ </Row>
138
+ <Text color="light.700">
139
+ {t.analyzingRequirements}
140
+ </Text>
141
+ <Row gap="12px">
142
+ <Skeleton height="31px" width="148px" bgLevel={600} />
143
+ <Skeleton height="31px" width="148px" bgLevel={600} />
144
+ <Skeleton height="31px" width="148px" bgLevel={600} />
145
+ <Skeleton height="31px" width="148px" bgLevel={600} />
146
+ </Row>
147
+ </Card>
148
+ }
53
149
 
54
- function openToolsPanel() {
55
- widget.set('currentMessageInPanel', { chatId, messageId })
56
- widget.set('panel', 'steps')
57
- }
150
+ const AwaitingApproval = ({ customApproveText, chatId }: { chatId: string, customApproveText?: string }) => {
151
+ const t = useTranslate(dictionary)
152
+ const chat = useChat(chatId)
58
153
 
59
- if (!actualSteps.length) {
60
- return null
154
+ const onAnswer = (response: string) => {
155
+ chat.pushMessage(ChatEntry.createUserEntry('', false, undefined, undefined, response))
61
156
  }
62
-
63
- return (
64
- <AnimatedHeight>
157
+
158
+ return <>
159
+ <Row gap="8px">
160
+ <Button colorScheme="light" onClick={() => onAnswer(t.cancel)}>
161
+ <Row gap="8px">
162
+ <Icon icon="Stop" />
163
+ {t.cancel}
164
+ </Row>
165
+ </Button>
166
+
167
+ <Button colorScheme="inverse" onClick={() => onAnswer(customApproveText ?? t.approve)}>
168
+ <Row gap="8px">
169
+ <Icon group="fill" icon="Play" />
170
+ {customApproveText ?? t.approve}
171
+ </Row>
172
+ </Button>
173
+ </Row>
174
+ </>
175
+ }
176
+
177
+ export const ToolStepsList = ({ toolStep, messageId, chatId }: { toolStep: ToolChatStep, messageId: number, chatId: string }) => {
178
+ const t = useTranslate(dictionary)
179
+ const chat = useCurrentChat()
180
+ const messages = useCurrentChatMessages()
181
+ const inputParsed = `\`\`\`json
182
+ ${JSON.stringify(toolStep?.input, null, 2)}
183
+ \`\`\``
184
+
185
+ const tool = useMemo(() => {
186
+ if (!toolStep) return undefined
187
+ return toolStep.attempts?.[0].tools?.[0]
188
+ }, [toolStep])
189
+
190
+ useEffect(() => {
191
+ if (!toolStep) return undefined
192
+ const executionId = toolStep.attempts?.[0]?.tools?.[0]?.executionId
193
+ if (!executionId) return
194
+
195
+ updateToolStep(messages, executionId, toolStep.status)
196
+
197
+ }, [messages, toolStep, toolStep.status])
198
+
199
+ return <>
200
+ {toolStep && tool ? <AnimatedHeight>
65
201
  <div className="steps">
66
- <ul>
67
- {isExpanded
68
- ? actualSteps.map((s, i) => <Step step={s} key={i} index={i + 1} total={actualSteps.length} />)
69
- : <Step
70
- step={actualSteps[currentStepIndex]}
71
- index={currentStepIndex + 1}
72
- total={actualSteps.length}
73
- onClick={() => setExpanded(true)}
74
- />
75
- }
202
+ <Badge colorPalette="yellow" appearance="square">
203
+ <Icon icon="StopWatch" />
204
+ <Text>{tool.name} {t.keepWorking}</Text>
205
+ </Badge>
206
+ <Card mt="16px" gap="8px" bgLevel={500}>
207
+ <Row>
208
+ <ImageWithFallback src={tool.image} width="32px" fallback={<IconBox appearance="circle" icon="StackSpot" />} />
209
+ <Text>{tool.name}</Text>
210
+ </Row>
211
+
212
+ <Text>
213
+ {toolStep.user_question}
214
+ </Text>
215
+
216
+ <Accordion header={expand => <Row gap="8px" mb="4px">
217
+ <Card p="4px" bgLevel={400}>{expand}</Card>
218
+ <Text > {t.viewDetails} </Text>
219
+ </Row>}>
220
+ <Markdown onCopyCode={(code) => onCopyCode(code, `${messageId}`, chat)}>
221
+ {inputParsed}
222
+ </Markdown>
223
+ </Accordion>
224
+
225
+ <AwaitingApproval customApproveText={t.approveTool} chatId={chatId} />
226
+ </Card>
227
+ </div>
228
+ </AnimatedHeight> : null}
229
+ </>
230
+ }
231
+
232
+ export const StepsList = ({ steps, messageId, chatId, userHasAlreadyAnswered }: Props) => {
233
+ const t = useTranslate(dictionary)
234
+
235
+ const filteredSteps = steps.filter(s => s.type === 'step')
236
+ const actualSteps = useMemo(() => filteredSteps.filter((item) => {
237
+ const messageIdForStep = planningToolDictionaryHelper.getMessageIdFromStepId(item.id)
238
+ if (!messageIdForStep) {
239
+ planningToolDictionaryHelper.setMessageIdForStepId(messageId, item.id)
240
+ return true
241
+ } else if (messageIdForStep === messageId) {
242
+ return true
243
+ }
244
+ // If a step is from a planning and it is already inserted in the planningToolDictionaryHelper it means the step is already in a
245
+ // previous message and we do not want to show it again (for instance, when required a approval in the planning, we will have
246
+ // two messages with the same step id one for the planning awaiting and one for the planning end, so we want to show only one)
247
+ return false
248
+ }), [filteredSteps])
249
+
250
+ const planning = steps.filter(s => s.type === 'planning')
251
+
252
+ useEffect(() => {
253
+ actualSteps.map((item) => {
254
+ const executionId = item.attempts[0]?.tools?.[0]?.executionId
255
+ if (executionId) {
256
+ planningToolDictionaryHelper.setMessageIdPlanningStepToolExecutionId(`${messageId}`, executionId)
257
+ }
258
+ })
259
+ }, [actualSteps, messageId])
260
+
261
+ const toolsStep = findLast(steps, s => s.type === 'tool')
262
+
263
+ useEffect(() => {
264
+ const executionId = toolsStep?.attempts?.[0]?.tools?.[0]?.executionId
265
+ if (executionId) {
266
+ planningToolDictionaryHelper.setMessageIdToolStepToolExecutionId(`${messageId}`, executionId)
267
+ }
268
+ }, [toolsStep, messageId])
269
+
270
+ const planningGoal = planning?.[0]?.goal
271
+ const isLastStepDone = actualSteps[actualSteps.length - 1]?.status !== 'running' &&
272
+ actualSteps[actualSteps.length - 1]?.status !== 'pending'
273
+ const totalTools = useMemo(() => actualSteps?.reduce((sum, step) => {
274
+ const firstAttempt = step.attempts && step.attempts[0]
275
+ const toolsCount = firstAttempt.tools?.length ?? 0
276
+ return sum + toolsCount
277
+ }, 0), [steps])
278
+
279
+ let currentStepIndex = findLastIndex(actualSteps, s => s.status === 'running' || s.status === 'success')
280
+ if (currentStepIndex === -1) currentStepIndex = 0
281
+
282
+ return (<>
283
+ {actualSteps.length > 0 ? <AnimatedHeight>
284
+ <div className="steps">
285
+ <Row gap="14px" mb="8px" ml="5px">
286
+ <Icon icon="Target" size="sm" color="light.600" />
287
+ <Text>{t.executionPlan}</Text>
288
+ </Row>
289
+
290
+ <ul className="steps-list">
291
+ {actualSteps.map((s, i) => <Step step={s} key={i} index={i + 1} />)}
292
+
293
+ <Step
294
+ step={{ status: 'target', input: planningGoal, attempts: [] }}
295
+ index={currentStepIndex + 1}
296
+ total={actualSteps.length}
297
+ totalTools={totalTools}
298
+ isAllDone={isLastStepDone}
299
+ />
76
300
  </ul>
77
- {isExpanded && <div className="step-actions">
78
- <Button colorScheme="light" size="sm" onClick={() => setExpanded(false)}>{t.hideSteps}</Button>
79
- <Button colorScheme="light" size="sm" className="icon-button details" onClick={openToolsPanel}>
80
- <Icon group="fill" icon="Play" size="xs" />
81
- {t.detailed}
82
- </Button>
83
- </div>}
301
+
302
+ <Column gap="8px" mt="8px">
303
+ <Divider colorScheme="light" />
304
+ <Text color="light.700">{planning?.[0]?.user_question}</Text>
305
+ {!userHasAlreadyAnswered && planning?.[0]?.status === 'awaiting_approval' && <AwaitingApproval chatId={chatId} />}
306
+ </Column>
307
+
308
+ <ViewToolsDetails chatId={chatId} messageChatId={messageId} />
309
+
84
310
  </div>
85
- </AnimatedHeight>
311
+ </AnimatedHeight> : null}
312
+
313
+ {toolsStep && toolsStep.status === 'awaiting_approval' && !userHasAlreadyAnswered &&
314
+ <ToolStepsList toolStep={toolsStep} messageId={messageId} chatId={chatId} />}
315
+ </>
86
316
  )
87
317
  }
88
318
 
319
+ export const ViewToolsDetails = ({ chatId, messageChatId }: { chatId: string, messageChatId?: number }) => {
320
+ const t = useTranslate(dictionary)
321
+ const messages = useChatMessages(chatId)
322
+ const planningMessageId = useMemo(() => {
323
+ const messageWithPlanning = findLast(messages, (message) => {
324
+ const steps = message.getValue().steps
325
+ const planningStep = steps?.find((step) => step.type === 'planning' && step.status === 'success')
326
+ return planningStep ? true : false
327
+ })
328
+ return messageWithPlanning?.id
329
+
330
+ }, [messages])
331
+ const widget = useWidget()
332
+ const messageId = messageChatId || planningMessageId
333
+
334
+ function openToolsPanel() {
335
+ if (messageId) {
336
+ widget.set('currentMessageInPanel', { chatId, messageId })
337
+ widget.set('panel', 'steps')
338
+ }
339
+ }
340
+
341
+ return <>
342
+ <div className="step-actions">
343
+ <Button colorScheme="light" size="sm" className="icon-button details" onClick={openToolsPanel}>
344
+ <Icon group="fill" icon="Play" size="xs" />
345
+ {t.detailed}
346
+ </Button>
347
+ </div>
348
+ </>
349
+ }
350
+
89
351
  const dictionary = {
90
352
  en: {
91
353
  step: 'Step',
92
354
  hideSteps: 'Hide steps',
93
355
  detailed: 'View detailed mode',
356
+ generatingPlan: 'Generating execution plan...',
357
+ analyzingRequirements: 'Analyzing task requirements',
358
+ executionPlan: 'Execution Plan',
359
+ planGoal: 'Plan Goal',
360
+ toolsToBeExecuted: 'Tools to be executed',
361
+ totalSteps: 'Total Steps',
362
+ totalTools: 'Total Tools',
363
+ stepGoal: 'Step Goal',
364
+ cancel: 'Cancel execution',
365
+ approve: 'Approve & Execute Plan',
366
+ keepWorking: 'will keep working after your answer',
367
+ viewDetails: 'View details',
368
+ approveTool: 'Approve execution',
369
+ pendingReview: 'Pending review',
370
+ noToolToBeUsed: 'No tool will be needed',
94
371
  },
95
372
  pt: {
96
373
  step: 'Passo',
97
374
  hideSteps: 'Esconder passos',
98
375
  detailed: 'Ver modo detalhado',
376
+ generatingPlan: 'Gerando plano de execução...',
377
+ analyzingRequirements: 'Analisando os requisitos da task',
378
+ executionPlan: 'Plano de Execução',
379
+ planGoal: 'Finalidade do Plano',
380
+ toolsToBeExecuted: 'Tools a serem executadas',
381
+ totalSteps: 'Total de Passos',
382
+ totalTools: 'Total de Tools',
383
+ stepGoal: 'Objetivo do passo',
384
+ cancel: 'Cancelar execução',
385
+ approve: 'Aprovar & Executar plano',
386
+ keepWorking: 'continuará trabalhando após a sua resposta',
387
+ viewDetails: 'Ver detalhes',
388
+ approveTool: 'Aprovar execução',
389
+ pendingReview: 'Revisão pendente',
390
+ noToolToBeUsed: 'Nenhuma tool será necessária',
99
391
  },
100
392
  } satisfies Dictionary
@@ -243,20 +243,27 @@ export const ChatList: IStyledComponentBase<
243
243
  }
244
244
 
245
245
  .steps {
246
- ul {
246
+ .steps-list {
247
247
  list-style: none;
248
248
  margin: 0;
249
249
  padding: 0;
250
250
  display: flex;
251
251
  flex-direction: column;
252
252
  gap: 6px;
253
+ }
253
254
 
254
- li {
255
- display: flex;
256
- flex-direction: row;
257
- gap: 4px;
258
- align-items: center;
255
+ .tools-list {
256
+ list-style: disc;
257
+ margin: 0;
258
+ padding-left: 24px;
259
+ display: block;
260
+ ::marker {
261
+ color: ${theme.color.light.contrastText};
262
+ }
263
+ }
259
264
 
265
+ ul {
266
+ li {
260
267
  &[role="button"] {
261
268
  cursor: pointer;
262
269
  }
@@ -275,7 +282,6 @@ export const ChatList: IStyledComponentBase<
275
282
  }
276
283
 
277
284
  .step-title {
278
- line-height: 0.75rem;
279
285
  overflow: hidden;
280
286
  text-overflow: ellipsis;
281
287
  display: -webkit-box;
@@ -285,8 +291,10 @@ export const ChatList: IStyledComponentBase<
285
291
  }
286
292
  }
287
293
 
288
- .step-actions {
289
- margin-top: 8px;
294
+ }
295
+
296
+ .step-actions {
297
+ margin-top: 16px;
290
298
  display: flex;
291
299
  gap: 6px;
292
300
 
@@ -296,7 +304,6 @@ export const ChatList: IStyledComponentBase<
296
304
  align-items: center;
297
305
  }
298
306
  }
299
- }
300
307
 
301
308
  .markdown img {
302
309
  max-width: 70%;
@@ -1,6 +1,7 @@
1
1
  import { IconButton, Row } from '@stack-spot/citric-react'
2
2
  import { useCurrentChat, useCurrentChatState, useWidget } from '../../context/hooks'
3
3
  import { useMessageInputDictionary } from './dictionary'
4
+ import { ModelSwitcher } from './ModelSwitcher'
4
5
  import { SelectContent } from './SelectContent'
5
6
  import { SelectionBarWrapper } from './styled'
6
7
 
@@ -29,6 +30,7 @@ export const ButtonBar = ({ onSend, isLoading }: SelectionBarProps) => {
29
30
  <IconButton icon="Code" appearance="square" aria-label={t.code} title={t.code} onClick={() => widget.set('panel', 'editor')} />
30
31
  )}
31
32
  </Row>
33
+ <ModelSwitcher />
32
34
  {isLoading ? (
33
35
  <IconButton
34
36
  icon="Stop"
@@ -0,0 +1,67 @@
1
+ import { CitricIconOutline, CitricIconSocial } from '@stack-spot/citric-icons'
2
+ import { AsyncContent, Button, Column, FieldGroup, Icon, Input, Row } from '@stack-spot/citric-react'
3
+ import { SelectionList } from '@stack-spot/portal-components/SelectionList'
4
+ import { agentToolsClient, genAiInferenceClient } from '@stack-spot/portal-network'
5
+ import { useMemo, useState } from 'react'
6
+ import { CSSProperties } from 'styled-components'
7
+ import { useCurrentChat, useCurrentChatState } from '../../../context/hooks'
8
+ import { useMessageInputDictionary } from '../dictionary'
9
+ import { RowWrapperStyled, stylesModelSwitcher } from '../styled'
10
+ import { getModelData, handleFilter, providerIcon } from './utils'
11
+
12
+ export const ModelSwitcher = () => {
13
+ const t = useMessageInputDictionary()
14
+ const agentCurrentChat = useCurrentChatState('agent')
15
+ const chat = useCurrentChat()
16
+ const [visibleMenu, setVisibleMenu] = useState(false)
17
+ const [agentData, isLoadingAgentData] = agentToolsClient.agent.useStatefulQuery({ agentId: agentCurrentChat?.id || '' })
18
+ const [listModels, isLoadingModels] = genAiInferenceClient.listModels.useStatefulQuery({ pageSize: 999, active: true })
19
+ const [filter, setFilter] = useState('')
20
+
21
+ const { modelName, modelProviderType, listItemsData } =
22
+ getModelData(chat, setVisibleMenu, agentData, listModels)
23
+
24
+ const data = useMemo(() => {
25
+ const items = listItemsData ?? []
26
+ return handleFilter(items, t, filter)
27
+ }, [filter, agentCurrentChat?.id, chat.get('selected_model_id'), listItemsData])
28
+
29
+ return (
30
+ <RowWrapperStyled>
31
+ <AsyncContent loading={isLoadingAgentData && isLoadingModels}>
32
+ <Button
33
+ className="button-select-model"
34
+ colorScheme="light"
35
+ size="sm"
36
+ aria-label={t.agent}
37
+ title={t.agent}
38
+ onClick={() => setVisibleMenu(state => !state)}
39
+ >
40
+ <Icon
41
+ icon={providerIcon[modelProviderType as CitricIconOutline | CitricIconSocial]}
42
+ group={modelProviderType === 'stackspot' ? 'outline' : 'social'}
43
+ />
44
+ {modelName}
45
+ <Icon icon="ChevronDown" group="fill" size="sm" />
46
+ </Button>
47
+ </AsyncContent>
48
+ <SelectionList
49
+ id="menuModelSwitcher"
50
+ items={data || []}
51
+ visible={visibleMenu}
52
+ onHide={() => setVisibleMenu(false)}
53
+ showListAsCard
54
+ style={stylesModelSwitcher.selection as CSSProperties}
55
+ before={
56
+ <Column>
57
+ <FieldGroup fullWidth style={{ marginTop: '8px' }}>
58
+ <Icon icon="Search" />
59
+ <Input type="search" value={filter} onChange={(value) => (setFilter(value))} />
60
+ </FieldGroup>
61
+ {!data.length ? <Row m="16px 8px">{t.nothingFound}</Row> : undefined}
62
+ </Column>
63
+ }
64
+ />
65
+ </RowWrapperStyled>
66
+ )
67
+ }