@stack-spot/ai-chat-widget 1.12.4 → 1.13.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 (149) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/StackspotAIWidget.d.ts.map +1 -1
  3. package/dist/StackspotAIWidget.js +3 -2
  4. package/dist/StackspotAIWidget.js.map +1 -1
  5. package/dist/app-metadata.json +3 -3
  6. package/dist/chat-interceptors/send-message.d.ts.map +1 -1
  7. package/dist/chat-interceptors/send-message.js +2 -0
  8. package/dist/chat-interceptors/send-message.js.map +1 -1
  9. package/dist/components/Markdown.d.ts.map +1 -1
  10. package/dist/components/Markdown.js +1 -1
  11. package/dist/components/Markdown.js.map +1 -1
  12. package/dist/components/StackedBadge.d.ts +14 -0
  13. package/dist/components/StackedBadge.d.ts.map +1 -0
  14. package/dist/components/StackedBadge.js +56 -0
  15. package/dist/components/StackedBadge.js.map +1 -0
  16. package/dist/components/ToolBadge.d.ts +14 -0
  17. package/dist/components/ToolBadge.d.ts.map +1 -0
  18. package/dist/components/ToolBadge.js +108 -0
  19. package/dist/components/ToolBadge.js.map +1 -0
  20. package/dist/state/ChatEntry.d.ts +9 -16
  21. package/dist/state/ChatEntry.d.ts.map +1 -1
  22. package/dist/state/ChatEntry.js.map +1 -1
  23. package/dist/state/WidgetState.d.ts +3 -4
  24. package/dist/state/WidgetState.d.ts.map +1 -1
  25. package/dist/state/WidgetState.js +1 -12
  26. package/dist/state/WidgetState.js.map +1 -1
  27. package/dist/utils/tools.d.ts +7 -0
  28. package/dist/utils/tools.d.ts.map +1 -0
  29. package/dist/utils/tools.js +9 -0
  30. package/dist/utils/tools.js.map +1 -0
  31. package/dist/views/Agents/AgentDescription.d.ts.map +1 -1
  32. package/dist/views/Agents/AgentDescription.js +11 -1
  33. package/dist/views/Agents/AgentDescription.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/Agents/styled.js +1 -1
  39. package/dist/views/Chat/AgentInfo.js +3 -3
  40. package/dist/views/Chat/AgentInfo.js.map +1 -1
  41. package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
  42. package/dist/views/Chat/ChatMessage.js +17 -2
  43. package/dist/views/Chat/ChatMessage.js.map +1 -1
  44. package/dist/views/Chat/StepsList.d.ts +2 -2
  45. package/dist/views/Chat/StepsList.d.ts.map +1 -1
  46. package/dist/views/Chat/StepsList.js +2 -2
  47. package/dist/views/Chat/StepsList.js.map +1 -1
  48. package/dist/views/Chat/styled.d.ts.map +1 -1
  49. package/dist/views/Chat/styled.js +21 -12
  50. package/dist/views/Chat/styled.js.map +1 -1
  51. package/dist/views/ChatTabSelection.d.ts.map +1 -1
  52. package/dist/views/ChatTabSelection.js +16 -2
  53. package/dist/views/ChatTabSelection.js.map +1 -1
  54. package/dist/views/{Tools → Steps}/FlowChart/HandleGroup.d.ts.map +1 -1
  55. package/dist/views/{Tools → Steps}/FlowChart/HandleGroup.js.map +1 -1
  56. package/dist/views/{Tools → Steps}/FlowChart/NodeStep.d.ts.map +1 -1
  57. package/dist/views/Steps/FlowChart/NodeStep.js +13 -0
  58. package/dist/views/Steps/FlowChart/NodeStep.js.map +1 -0
  59. package/dist/views/Steps/FlowChart/index.d.ts +10 -0
  60. package/dist/views/Steps/FlowChart/index.d.ts.map +1 -0
  61. package/dist/views/{Tools → Steps}/FlowChart/index.js +1 -5
  62. package/dist/views/{Tools → Steps}/FlowChart/index.js.map +1 -1
  63. package/dist/views/{Tools → Steps}/FlowChart/layout.d.ts.map +1 -1
  64. package/dist/views/{Tools → Steps}/FlowChart/layout.js.map +1 -1
  65. package/dist/views/{Tools → Steps}/FlowChart/styled.d.ts.map +1 -1
  66. package/dist/views/{Tools → Steps}/FlowChart/styled.js +0 -49
  67. package/dist/views/{Tools → Steps}/FlowChart/styled.js.map +1 -1
  68. package/dist/views/{Tools → Steps}/FlowChart/types.d.ts +3 -3
  69. package/dist/views/Steps/FlowChart/types.d.ts.map +1 -0
  70. package/dist/views/Steps/FlowChart/types.js.map +1 -0
  71. package/dist/views/Steps/StepModal.d.ts +9 -0
  72. package/dist/views/Steps/StepModal.d.ts.map +1 -0
  73. package/dist/views/Steps/StepModal.js +124 -0
  74. package/dist/views/Steps/StepModal.js.map +1 -0
  75. package/dist/views/Steps/StepsPanel.d.ts +6 -0
  76. package/dist/views/Steps/StepsPanel.d.ts.map +1 -0
  77. package/dist/views/{Tools/ToolsPanel.js → Steps/StepsPanel.js} +3 -3
  78. package/dist/views/{Tools/ToolsPanel.js.map → Steps/StepsPanel.js.map} +1 -1
  79. package/dist/views/{Tools → Steps}/dictionary.d.ts +9 -11
  80. package/dist/views/Steps/dictionary.d.ts.map +1 -0
  81. package/dist/views/{Tools → Steps}/dictionary.js +9 -11
  82. package/dist/views/Steps/dictionary.js.map +1 -0
  83. package/dist/views/{Tools → Steps}/index.d.ts +1 -1
  84. package/dist/views/Steps/index.d.ts.map +1 -0
  85. package/dist/views/{Tools → Steps}/index.js +10 -10
  86. package/dist/views/{Tools → Steps}/index.js.map +1 -1
  87. package/dist/views/Steps/utils.d.ts +6 -0
  88. package/dist/views/Steps/utils.d.ts.map +1 -0
  89. package/dist/views/{Tools → Steps}/utils.js.map +1 -1
  90. package/dist/views/Tools.d.ts +2 -0
  91. package/dist/views/Tools.d.ts.map +1 -0
  92. package/dist/views/Tools.js +51 -0
  93. package/dist/views/Tools.js.map +1 -0
  94. package/package.json +2 -2
  95. package/src/StackspotAIWidget.tsx +2 -0
  96. package/src/app-metadata.json +3 -3
  97. package/src/chat-interceptors/send-message.ts +2 -0
  98. package/src/components/Markdown.tsx +1 -0
  99. package/src/components/StackedBadge.tsx +77 -0
  100. package/src/components/ToolBadge.tsx +146 -0
  101. package/src/state/ChatEntry.ts +9 -17
  102. package/src/state/WidgetState.ts +4 -16
  103. package/src/utils/tools.ts +11 -0
  104. package/src/views/Agents/AgentDescription.tsx +14 -0
  105. package/src/views/Agents/dictionary.ts +2 -0
  106. package/src/views/Agents/styled.ts +1 -1
  107. package/src/views/Chat/AgentInfo.tsx +3 -3
  108. package/src/views/Chat/ChatMessage.tsx +28 -2
  109. package/src/views/Chat/StepsList.tsx +6 -6
  110. package/src/views/Chat/styled.ts +21 -12
  111. package/src/views/ChatTabSelection.tsx +22 -4
  112. package/src/views/{Tools → Steps}/FlowChart/NodeStep.tsx +11 -23
  113. package/src/views/{Tools → Steps}/FlowChart/index.tsx +3 -7
  114. package/src/views/{Tools → Steps}/FlowChart/styled.ts +0 -49
  115. package/src/views/{Tools → Steps}/FlowChart/types.ts +3 -3
  116. package/src/views/Steps/StepModal.tsx +216 -0
  117. package/src/views/{Tools/ToolsPanel.tsx → Steps/StepsPanel.tsx} +2 -2
  118. package/src/views/{Tools → Steps}/dictionary.ts +9 -11
  119. package/src/views/{Tools → Steps}/index.tsx +10 -10
  120. package/src/views/{Tools → Steps}/utils.tsx +4 -4
  121. package/src/views/Tools.tsx +71 -0
  122. package/dist/views/Tools/FlowChart/NodeStep.js +0 -15
  123. package/dist/views/Tools/FlowChart/NodeStep.js.map +0 -1
  124. package/dist/views/Tools/FlowChart/index.d.ts +0 -9
  125. package/dist/views/Tools/FlowChart/index.d.ts.map +0 -1
  126. package/dist/views/Tools/FlowChart/types.d.ts.map +0 -1
  127. package/dist/views/Tools/FlowChart/types.js.map +0 -1
  128. package/dist/views/Tools/StepModal.d.ts +0 -9
  129. package/dist/views/Tools/StepModal.d.ts.map +0 -1
  130. package/dist/views/Tools/StepModal.js +0 -156
  131. package/dist/views/Tools/StepModal.js.map +0 -1
  132. package/dist/views/Tools/ToolsPanel.d.ts +0 -6
  133. package/dist/views/Tools/ToolsPanel.d.ts.map +0 -1
  134. package/dist/views/Tools/dictionary.d.ts.map +0 -1
  135. package/dist/views/Tools/dictionary.js.map +0 -1
  136. package/dist/views/Tools/index.d.ts.map +0 -1
  137. package/dist/views/Tools/utils.d.ts +0 -6
  138. package/dist/views/Tools/utils.d.ts.map +0 -1
  139. package/src/views/Tools/StepModal.tsx +0 -247
  140. /package/dist/views/{Tools → Steps}/FlowChart/HandleGroup.d.ts +0 -0
  141. /package/dist/views/{Tools → Steps}/FlowChart/HandleGroup.js +0 -0
  142. /package/dist/views/{Tools → Steps}/FlowChart/NodeStep.d.ts +0 -0
  143. /package/dist/views/{Tools → Steps}/FlowChart/layout.d.ts +0 -0
  144. /package/dist/views/{Tools → Steps}/FlowChart/layout.js +0 -0
  145. /package/dist/views/{Tools → Steps}/FlowChart/styled.d.ts +0 -0
  146. /package/dist/views/{Tools → Steps}/FlowChart/types.js +0 -0
  147. /package/dist/views/{Tools → Steps}/utils.js +0 -0
  148. /package/src/views/{Tools → Steps}/FlowChart/HandleGroup.tsx +0 -0
  149. /package/src/views/{Tools → Steps}/FlowChart/layout.ts +0 -0
@@ -1,16 +1,17 @@
1
+ import { ChatStep } from '@stack-spot/portal-network'
1
2
  import { listToClass, theme } from '@stack-spot/portal-theme'
2
3
  import { Background, Controls, Edge, MarkerType, ReactFlow } from '@xyflow/react'
3
4
  import '@xyflow/react/dist/style.css'
4
5
  import { useMemo } from 'react'
5
6
  import { useChatEntry } from '../../../context/hooks'
6
- import { ChatEntry, ChatEntryStep } from '../../../state/ChatEntry'
7
+ import { ChatEntry } from '../../../state/ChatEntry'
7
8
  import { useLayoutedElements } from './layout'
8
9
  import { NodeStep } from './NodeStep'
9
10
  import { FlowChartBox, runningColor } from './styled'
10
11
 
11
12
  interface Props {
12
13
  message: ChatEntry,
13
- onClick: (step: ChatEntryStep, index: number) => void,
14
+ onClick: (step: ChatStep, index: number) => void,
14
15
  }
15
16
 
16
17
  const nodeTypes = {
@@ -56,11 +57,6 @@ export const FlowChart = ({ message, onClick }: Props) => {
56
57
  edges={layouted.edges}
57
58
  nodeTypes={nodeTypes}
58
59
  snapToGrid={true}
59
- fitViewOptions={{
60
- minZoom: 1,
61
- maxZoom: 1,
62
- nodes: [layouted.nodes.find(n => n.data?.nextStatus === 'pending') ?? layouted.nodes[0]],
63
- }}
64
60
  fitView
65
61
  >
66
62
  <Controls orientation="horizontal" className="controls" showInteractive={false} />
@@ -88,55 +88,6 @@ export const FlowChartBox = styled.div`
88
88
  -webkit-line-clamp: 2;
89
89
  }
90
90
  }
91
-
92
- .step-tools {
93
- border-radius: 25px;
94
- background-color: ${theme.color.light[600]};
95
- border: 1px solid ${theme.color.light[500]};
96
- color: ${theme.color.light[700]};
97
- padding: 2px 7px;
98
- display: flex;
99
- gap: 5px;
100
- align-items: center;
101
-
102
- small {
103
- line-height: 0.75rem;
104
- }
105
-
106
- ul {
107
- list-style: none;
108
- margin: 0;
109
- padding: 0;
110
- display: flex;
111
- flex-direction: row;
112
-
113
- li {
114
- border: 1px solid ${theme.color.light[600]};
115
- background-color: ${theme.color.light[400]};
116
- border-radius: 50%;
117
- width: 16px;
118
- height: 16px;
119
- overflow: hidden;
120
- display: flex;
121
- align-items: center;
122
- justify-content: center;
123
-
124
- &:not(:first-child) {
125
- margin-left: -12px;
126
- }
127
- }
128
-
129
- i {
130
- width: 12px;
131
- height: 12px;
132
- }
133
-
134
- img, svg {
135
- width: 100%;
136
- height: 100%;
137
- }
138
- }
139
- }
140
91
  }
141
92
  }
142
93
 
@@ -1,9 +1,9 @@
1
- import { ChatEntryStep } from '../../../state/ChatEntry'
1
+ import { ChatStep } from '@stack-spot/portal-network'
2
2
 
3
3
  export interface NodeData {
4
- nextStatus: ChatEntryStep['status'] | undefined,
4
+ nextStatus: ChatStep['status'] | undefined,
5
5
  onClick?: () => void,
6
- step: ChatEntryStep,
6
+ step: ChatStep,
7
7
  index: number,
8
8
  }
9
9
 
@@ -0,0 +1,216 @@
1
+ import { Flex, Text } from '@citric/core'
2
+ import { ChevronLeft, ChevronRight } from '@citric/icons'
3
+ import { Badge, IconButton } from '@citric/ui'
4
+ import { theme } from '@stack-spot/portal-theme'
5
+ import { useMemo, useState } from 'react'
6
+ import { styled } from 'styled-components'
7
+ import { Code } from '../../components/Code'
8
+ import { Markdown } from '../../components/Markdown'
9
+ import { Modal } from '../../components/Modal'
10
+ import { ToolBadge } from '../../components/ToolBadge'
11
+ import { useChatEntry } from '../../context/hooks'
12
+ import { ChatEntry } from '../../state/ChatEntry'
13
+ import { useStepsDictionary } from './dictionary'
14
+ import { getTitle, toPrecision } from './utils'
15
+
16
+ interface Props {
17
+ message: ChatEntry,
18
+ stepId: string | undefined,
19
+ onClose: () => void,
20
+ }
21
+
22
+ const StyledSection = styled.section`
23
+ padding: 18px 14px;
24
+ border-bottom: 1px solid var(--light-600);
25
+ display: flex;
26
+ flex-direction: column;
27
+ gap: 12px;
28
+ align-items: start;
29
+
30
+ &:last-child {
31
+ border-bottom: none;
32
+ }
33
+
34
+ &.restrict-image-size img {
35
+ max-width: 100%;
36
+ }
37
+
38
+ .markdown p {
39
+ margin-top: 0;
40
+ }
41
+
42
+ .tool {
43
+ display: flex;
44
+ flex-direction: column;
45
+ align-items: start;
46
+ align-self: stretch;
47
+ gap: 6px;
48
+ background-color: ${theme.color.light[500]};
49
+ border-radius: 5px;
50
+ padding: 6px;
51
+
52
+ &:not(:last-child) {
53
+ border-bottom: 1px solid ${theme.color.light[500]};
54
+ }
55
+
56
+ .tool-input {
57
+ align-self: stretch;
58
+ &, .highlighter {
59
+ background: ${theme.color.light[300]} !important;
60
+ }
61
+ }
62
+ }
63
+
64
+ p {
65
+ line-height: 20px;
66
+ }
67
+
68
+ ul.steps {
69
+ margin: 0;
70
+ padding: 0;
71
+ list-style: none;
72
+ display: flex;
73
+ flex-direction: column;
74
+ gap: 8px;
75
+
76
+ > li {
77
+ padding: 8px 12px;
78
+ background-color: ${theme.color.light[500]};
79
+ border-radius: 6px;
80
+ }
81
+
82
+ .step-description {
83
+ color: ${theme.color.light[700]};
84
+ }
85
+ }
86
+
87
+ ul.side-by-side-tools {
88
+ margin: 14px 0 0 0;
89
+ padding: 0;
90
+ list-style: none;
91
+ display: flex;
92
+ gap: 10px;
93
+ flex-wrap: wrap;
94
+ }
95
+ `
96
+
97
+ const ExecutionBox = styled.div`
98
+ border-radius: 4px;
99
+ background-color: ${theme.color.light[500]};
100
+ color: ${theme.color.light[700]};
101
+ display: flex;
102
+ align-items: center;
103
+ .time {
104
+ padding: 6px 8px;
105
+ border-right: 1px solid ${theme.color.light[600]};
106
+ }
107
+ .navigator {
108
+ display: flex;
109
+ gap: 4px;
110
+ align-items: center;
111
+ padding: 2px 8px;
112
+ button {
113
+ width: 12px;
114
+ height: 12px;
115
+ padding: 0;
116
+ }
117
+ small {
118
+ line-height: 0.75rem;
119
+ }
120
+ }
121
+ `
122
+
123
+ export const StepModal = ({ message, stepId, onClose }: Props) => {
124
+ const t = useStepsDictionary()
125
+ const entry = useChatEntry(message)
126
+ const [attempt, setAttempt] = useState(0)
127
+ const stepIndex = useMemo(() => entry.steps?.findIndex(s => s.id === stepId) ?? -1, [entry, stepId])
128
+ const step = entry.steps?.[stepIndex]
129
+
130
+ const tools = step?.type === 'step' ? step.attempts[attempt]?.tools?.map(tool => (
131
+ <div className="tool" key={tool.id}>
132
+ <ToolBadge name={tool.name} duration={tool.duration} image={tool.image} description={tool.description} />
133
+ {tool.input && <>
134
+ <Text appearance="microtext1" colorScheme="light.700">{t.input}:</Text>
135
+ <Code language="json" className="tool-input" showLineNumbers={false} showActionBar>{tool.input}</Code>
136
+ </>}
137
+ {tool.output && <>
138
+ <Text appearance="microtext1" colorScheme="light.700">{t.response}:</Text>
139
+ <Code language="json" className="tool-input" showLineNumbers={false} showActionBar>{tool.output}</Code>
140
+ </>}
141
+ </div>
142
+ )) : undefined
143
+
144
+ const title = (
145
+ <Flex flex={1} justifyContent="space-between" alignItems="center">
146
+ <Text appearance="h6">{getTitle(t, step, stepIndex)}</Text>
147
+ <ExecutionBox>
148
+ <Text className="time" appearance="microtext1">
149
+ {step?.status === 'running' && t.running}
150
+ {step?.status === 'pending' && t.pending}
151
+ {step?.status === 'success' && `${t.executionTime}: ${step?.duration ? `${toPrecision(step?.duration)}s` : t.unknown}`}
152
+ </Text>
153
+ {step?.type === 'step' && step.attempts.length > 1 && <div className="navigator">
154
+ {attempt > 0 && (
155
+ <IconButton
156
+ size="xs"
157
+ appearance="text"
158
+ title={t.previousAttempt}
159
+ aria-label={t.previousAttempt}
160
+ onClick={() => setAttempt(attempt - 1)}
161
+ >
162
+ <ChevronLeft />
163
+ </IconButton>
164
+ )}
165
+ <Text appearance="microtext1">{attempt + 1}/{step.attempts.length}</Text>
166
+ {attempt < step.attempts.length - 1 && (
167
+ <IconButton
168
+ size="xs"
169
+ appearance="text"
170
+ title={t.nextAttempt}
171
+ aria-label={t.nextAttempt}
172
+ onClick={() => setAttempt(attempt + 1)}
173
+ >
174
+ <ChevronRight />
175
+ </IconButton>
176
+ )}
177
+ </div>}
178
+ </ExecutionBox>
179
+ </Flex>
180
+ )
181
+
182
+ return (
183
+ <Modal open={!!step} onClose={onClose} title={title}>
184
+ {step?.type === 'answer' && <StyledSection className="restrict-image-size">
185
+ {entry.type === 'md' ? <Markdown>{entry.content}</Markdown> : <Text>{entry.content}</Text>}
186
+ </StyledSection>}
187
+
188
+ {step?.type === 'planning' && <StyledSection style={{ alignItems: 'stretch' }}>
189
+ <Badge appearance="square" palette="blue" style={{ alignSelf: 'start' }}>Prompt</Badge>
190
+ <Text>{step.goal}</Text>
191
+ <ul className="steps">
192
+ {entry.steps?.filter(s => s.type === 'step').map((s, index) => (
193
+ <li key={index}>
194
+ <Flex mb={2}>
195
+ <Text>{t.step} {index + 1}: <span className="step-description">{s.input}</span></Text>
196
+ </Flex>
197
+ {!!s.attempts[0].tools?.length && <ul className="side-by-side-tools">
198
+ {s.attempts[0].tools.map((tool) => (
199
+ <li key={tool.id}>
200
+ <ToolBadge name={tool.name} image={tool.image} appearance="round" />
201
+ </li>
202
+ ))}
203
+ </ul>}
204
+ </li>
205
+ ))}
206
+ </ul>
207
+ </StyledSection>}
208
+
209
+ {step?.type === 'step' && step?.input && <StyledSection>
210
+ <Badge appearance="square" palette="blue">Prompt</Badge>
211
+ <Text>{step.input}</Text>
212
+ </StyledSection>}
213
+ {!!tools?.length && <StyledSection>{tools}</StyledSection>}
214
+ </Modal>
215
+ )
216
+ }
@@ -5,7 +5,7 @@ import { useWidget } from '../../context/hooks'
5
5
  import { FlowChart } from './FlowChart'
6
6
  import { StepModal } from './StepModal'
7
7
 
8
- const ToolsPanel = ({ chatId, messageId }: { chatId: string, messageId: number }) => {
8
+ const StepsPanel = ({ chatId, messageId }: { chatId: string, messageId: number }) => {
9
9
  const [currentStepId, setCurrentStepId] = useState<string | undefined>()
10
10
  const widget = useWidget()
11
11
  const message = useMemo(
@@ -21,4 +21,4 @@ const ToolsPanel = ({ chatId, messageId }: { chatId: string, messageId: number }
21
21
  ) : null
22
22
  }
23
23
 
24
- export default ToolsPanel
24
+ export default StepsPanel
@@ -2,7 +2,8 @@ import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
2
2
 
3
3
  export const dictionary = {
4
4
  en: {
5
- toolsDescription: 'A description for tools',
5
+ stepsPanelDescription: 'The steps and tools used to reach the answer',
6
+ steps: 'Steps',
6
7
  step: 'Step',
7
8
  response: 'Response',
8
9
  tools: 'Tools',
@@ -12,15 +13,15 @@ export const dictionary = {
12
13
  unknown: 'unknown',
13
14
  running: 'Running',
14
15
  pending: 'Pending',
15
- nextStep: 'Next step',
16
- previousStep: 'Previous step',
17
- thoughtFor: 'Thought for $0 seconds',
16
+ nextAttempt: 'Next execution',
17
+ previousAttempt: 'Previous execution',
18
18
  open: 'Open',
19
19
  close: 'Close',
20
20
  input: 'Input',
21
21
  },
22
22
  pt: {
23
- toolsDescription: 'Uma descrição para as Ferramentas',
23
+ stepsPanelDescription: 'Os passos e ferramentas usados para chegar na resposta',
24
+ steps: 'Passos',
24
25
  step: 'Passo',
25
26
  response: 'Resposta',
26
27
  tools: 'Ferramentas',
@@ -30,16 +31,13 @@ export const dictionary = {
30
31
  unknown: 'desconhecido',
31
32
  running: 'Executando',
32
33
  pending: 'Aguardando',
33
- nextStep: 'Próximo passo',
34
- previousStep: 'Passo anterior',
35
- thoughtFor: 'Pensado por $0 segundos',
36
- open: 'Open',
37
- close: 'Close',
34
+ nextAttempt: 'Próxima execução',
35
+ previousAttempt: 'Execução anterior',
38
36
  input: 'Entrada',
39
37
  },
40
38
  } satisfies Dictionary
41
39
 
42
- export function useToolsDictionary() {
40
+ export function useStepsDictionary() {
43
41
  return useTranslate(dictionary)
44
42
  }
45
43
 
@@ -3,31 +3,31 @@ import { LoadingCircular } from '@citric/ui'
3
3
  import { lazy, Suspense, useEffect } from 'react'
4
4
  import { useWidget, useWidgetState } from '../../context/hooks'
5
5
  import { useRightPanel } from '../../right-panel/hooks'
6
- import { useToolsDictionary } from './dictionary'
6
+ import { useStepsDictionary } from './dictionary'
7
7
 
8
- const LazyToolsPanel = lazy(() => import('./ToolsPanel'))
8
+ const LazyStepsPanel = lazy(() => import('./StepsPanel'))
9
9
 
10
10
  /**
11
11
  * Renders the Stack selection form in the Right Panel if this is the panel that is currently opened.
12
12
  */
13
- export const Tools = () => {
14
- const t = useToolsDictionary()
13
+ export const Steps = () => {
14
+ const t = useStepsDictionary()
15
15
  const panel = useWidgetState('panel')
16
- const message = useWidgetState('currentMessageInToolsPanel')
16
+ const message = useWidgetState('currentMessageInPanel')
17
17
  const { open } = useRightPanel()
18
18
  const widget = useWidget()
19
19
 
20
20
  useEffect(() => {
21
- if (panel === 'tools' && message) open(
21
+ if (panel === 'steps' && message) open(
22
22
  <Suspense fallback={<Flex alignItems="center" justifyContent="center" flex={1}><LoadingCircular /></Flex>}>
23
- <LazyToolsPanel key={message.messageId} chatId={message.chatId} messageId={message.messageId} />
23
+ <LazyStepsPanel key={message.messageId} chatId={message.chatId} messageId={message.messageId} />
24
24
  </Suspense>,
25
25
  {
26
- title: t.tools,
27
- description: t.toolsDescription,
26
+ title: t.steps,
27
+ description: t.stepsPanelDescription,
28
28
  onClose: () => {
29
29
  widget.set('panel', undefined)
30
- widget.set('currentMessageInToolsPanel', undefined)
30
+ widget.set('currentMessageInPanel', undefined)
31
31
  },
32
32
  },
33
33
  )
@@ -1,9 +1,9 @@
1
1
  import { IconBox } from '@citric/core'
2
2
  import { CheckCircleFill, ListUnordered, PlayFill, TimesCircleFill } from '@citric/icons'
3
3
  import { LoadingCircular } from '@citric/ui'
4
- import { ChatEntryStep } from '../../state/ChatEntry'
4
+ import { ChatStep } from '@stack-spot/portal-network'
5
5
 
6
- export function getStatusIcon(status: ChatEntryStep['status']) {
6
+ export function getStatusIcon(status: ChatStep['status']) {
7
7
  switch (status) {
8
8
  case 'success': return <IconBox colorIcon="success.500"><CheckCircleFill /></IconBox>
9
9
  case 'error': return <IconBox colorIcon="danger.500"><TimesCircleFill /></IconBox>
@@ -12,14 +12,14 @@ export function getStatusIcon(status: ChatEntryStep['status']) {
12
12
  }
13
13
  }
14
14
 
15
- export function getTypeIcon(type: ChatEntryStep['type']) {
15
+ export function getTypeIcon(type: ChatStep['type']) {
16
16
  switch (type) {
17
17
  case 'planning': return <ListUnordered />
18
18
  default: return <PlayFill />
19
19
  }
20
20
  }
21
21
 
22
- export function getTitle(translation: Record<'planning' | 'step' | 'answer', string>, step: ChatEntryStep | undefined, index: number) {
22
+ export function getTitle(translation: Record<'planning' | 'step' | 'answer', string>, step: ChatStep | undefined, index: number) {
23
23
  if (!step) return ''
24
24
  switch (step.type) {
25
25
  case 'planning': return translation.planning
@@ -0,0 +1,71 @@
1
+ import { agentClient } from '@stack-spot/portal-network'
2
+ import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
3
+ import { useEffect, useMemo } from 'react'
4
+ import styled from 'styled-components'
5
+ import { ToolBadge } from '../components/ToolBadge'
6
+ import { useWidget, useWidgetState } from '../context/hooks'
7
+ import { useRightPanel } from '../right-panel/hooks'
8
+ import { toolById } from '../utils/tools'
9
+
10
+ const ToolList = styled.ul`
11
+ margin: 0;
12
+ padding: 0;
13
+ list-style: none;
14
+ display: flex;
15
+ flex-direction: column;
16
+ gap: 8px;
17
+ `
18
+
19
+ export const Tools = () => {
20
+ const t = useTranslate(dictionary)
21
+ const panel = useWidgetState('panel')
22
+ const message = useWidgetState('currentMessageInPanel')
23
+ const { open } = useRightPanel()
24
+ const widget = useWidget()
25
+
26
+ useEffect(() => {
27
+ if (panel === 'tools' && message) open(
28
+ <ToolsPanel key={message.messageId} />,
29
+ { title: t.title, description: t.description, onClose: () => widget.set('panel', undefined) },
30
+ )
31
+ }, [panel, t])
32
+
33
+ return null
34
+ }
35
+
36
+ const ToolsPanel = () => {
37
+ const { chatId, messageId } = useWidgetState('currentMessageInPanel') ?? {}
38
+ const widget = useWidget()
39
+ const message = useMemo(() => {
40
+ const chat = widget.chatTabs.getAll().find(c => c.id === chatId)
41
+ return chat?.getMessages().find(m => m.id === messageId)?.getValue()
42
+ }, [messageId])
43
+ const [agent] = agentClient.agent.useStatefulQuery({ agentId: message?.agent?.id ?? '' }, { enabled: !!message?.agent?.id })
44
+ const tools = useMemo(() => message?.tools?.map(id => toolById(id, agent?.toolkits) ?? { id }), [messageId, agent])
45
+
46
+ return !!tools?.length && (
47
+ <ToolList>
48
+ {tools.map((tool) => (
49
+ <li key={tool.id}>
50
+ <ToolBadge
51
+ name={tool.name || tool.id}
52
+ image={tool.image}
53
+ description={tool.description}
54
+ backgroundColor="light.500"
55
+ />
56
+ </li>
57
+ ))}
58
+ </ToolList>
59
+ )
60
+ }
61
+
62
+ const dictionary = {
63
+ en: {
64
+ title: 'Tools',
65
+ description: 'The tools used to generate the answer.',
66
+ },
67
+ pt: {
68
+ title: 'Ferramentas',
69
+ description: 'As ferramentas usadas para gerar a resposta.',
70
+ },
71
+ } satisfies Dictionary
@@ -1,15 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { IconBox, Text } from '@citric/core';
3
- import { Cog } from '@citric/icons';
4
- import { listToClass } from '@stack-spot/portal-theme';
5
- import { last } from 'lodash';
6
- import { useToolsDictionary } from '../dictionary.js';
7
- import { getStatusIcon, getTitle, getTypeIcon } from '../utils.js';
8
- import { HandleGroup } from './HandleGroup.js';
9
- export const NodeStep = ({ data: { step, index, nextStatus, onClick } }) => {
10
- const t = useToolsDictionary();
11
- return (_jsxs("div", { className: listToClass(['chart-node', step.type, nextStatus]), onClick: onClick, onKeyDown: e => e.key === 'Enter' && onClick?.(), tabIndex: 0, role: "button", "aria-label": getTitle(t, step, index), children: [_jsxs("header", { children: [_jsx(IconBox, { children: getTypeIcon(step.type) }), _jsx(Text, { className: "step-index", children: getTitle(t, step, index) }), getStatusIcon(step.status)] }), step.input && _jsx(Text, { className: "step-title", children: step.input }), step.type === 'step' && _jsxs("div", { className: "step-details", children: [_jsx(Text, { className: listToClass(['step-description', !!step.tools?.length && 'with-tools']), children: step.output || last(step.tools)?.output }), !!step.tools?.length && (_jsxs("div", { className: "step-tools", children: [_jsx(Text, { appearance: "microtext1", children: t.tools }), _jsx("ul", { children: step.tools.slice(0, 3).map(({ id, name, image }) => (_jsx("li", { children: image
12
- ? _jsx("img", { alt: name, "aria-label": name, title: name, src: image })
13
- : _jsx(IconBox, { size: "xs", "aria-label": name, title: name, children: _jsx(Cog, {}) }) }, id))) })] }))] }), _jsx(HandleGroup, { renderSource: step.type !== 'answer', renderTarget: step.type !== 'planning' })] }));
14
- };
15
- //# sourceMappingURL=NodeStep.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeStep.js","sourceRoot":"","sources":["../../../../src/views/Tools/FlowChart/NodeStep.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAO3C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,EAAS,EAAE,EAAE;IAChF,MAAM,CAAC,GAAG,kBAAkB,EAAE,CAAA;IAE9B,OAAO,CACL,eACE,SAAS,EAAE,WAAW,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,EAC7D,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,IAAI,OAAO,EAAE,EAAE,EAChD,QAAQ,EAAE,CAAC,EACX,IAAI,EAAC,QAAQ,gBACD,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,aAEpC,6BACE,KAAC,OAAO,cAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAW,EAC3C,KAAC,IAAI,IAAC,SAAS,EAAC,YAAY,YAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,GAAQ,EAC7D,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,IACpB,EACR,IAAI,CAAC,KAAK,IAAI,KAAC,IAAI,IAAC,SAAS,EAAC,YAAY,YAAE,IAAI,CAAC,KAAK,GAAQ,EAC9D,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,eAAK,SAAS,EAAC,cAAc,aACpD,KAAC,IAAI,IAAC,SAAS,EAAE,WAAW,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,YAAY,CAAC,CAAC,YACrF,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GACnC,EACN,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,CACvB,eAAK,SAAS,EAAC,YAAY,aACzB,KAAC,IAAI,IAAC,UAAU,EAAC,YAAY,YAAE,CAAC,CAAC,KAAK,GAAQ,EAC9C,uBACG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CACzB,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CACvB,uBACG,KAAK;wCACJ,CAAC,CAAC,cAAK,GAAG,EAAE,IAAI,gBAAc,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,GAAI;wCAC/D,CAAC,CAAC,KAAC,OAAO,IAAC,IAAI,EAAC,IAAI,gBAAa,IAAI,EAAE,KAAK,EAAE,IAAI,YAAE,KAAC,GAAG,KAAG,GAAU,IAHhE,EAAE,CAKN,CACN,CACF,GACE,IACD,CACP,IACG,EACN,KAAC,WAAW,IAAC,YAAY,EAAE,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,IAAI,KAAK,UAAU,GAAI,IACzF,CACP,CAAA;AACH,CAAC,CAAA"}
@@ -1,9 +0,0 @@
1
- import '@xyflow/react/dist/style.css';
2
- import { ChatEntry, ChatEntryStep } from '../../../state/ChatEntry.js';
3
- interface Props {
4
- message: ChatEntry;
5
- onClick: (step: ChatEntryStep, index: number) => void;
6
- }
7
- export declare const FlowChart: ({ message, onClick }: Props) => import("react/jsx-runtime").JSX.Element;
8
- export {};
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Tools/FlowChart/index.tsx"],"names":[],"mappings":"AAEA,OAAO,8BAA8B,CAAA;AAGrC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAKnE,UAAU,KAAK;IACb,OAAO,EAAE,SAAS,CAAC;IACnB,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD;AAQD,eAAO,MAAM,SAAS,GAAI,sBAAsB,KAAK,4CAiDpD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/views/Tools/FlowChart/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC;IACrC,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/views/Tools/FlowChart/types.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import { ChatEntry } from '../../state/ChatEntry.js';
2
- interface Props {
3
- message: ChatEntry;
4
- stepId: string | undefined;
5
- onClose: () => void;
6
- }
7
- export declare const StepModal: ({ message, stepId: initialStepId, onClose }: Props) => import("react/jsx-runtime").JSX.Element;
8
- export {};
9
- //# sourceMappingURL=StepModal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StepModal.d.ts","sourceRoot":"","sources":["../../../src/views/Tools/StepModal.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAI5D,UAAU,KAAK;IACb,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAqJD,eAAO,MAAM,SAAS,GAAI,6CAA6C,KAAK,4CA6E3E,CAAA"}