@adminforth/agent 1.18.0 → 1.18.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.
- package/build.log +3 -2
- package/custom/ChatSurface.vue +8 -5
- package/custom/ConversationArea.vue +25 -13
- package/custom/ToolsGroup.vue +1 -1
- package/custom/composables/useAgentStore.ts +17 -11
- package/custom/utils.ts +9 -0
- package/dist/custom/ChatSurface.vue +8 -5
- package/dist/custom/ConversationArea.vue +25 -13
- package/dist/custom/ToolsGroup.vue +1 -1
- package/dist/custom/composables/useAgentStore.ts +17 -11
- package/dist/custom/utils.ts +9 -0
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -15,6 +15,7 @@ custom/package.json
|
|
|
15
15
|
custom/pnpm-lock.yaml
|
|
16
16
|
custom/tsconfig.json
|
|
17
17
|
custom/types.ts
|
|
18
|
+
custom/utils.ts
|
|
18
19
|
custom/composables/
|
|
19
20
|
custom/composables/useAgentStore.ts
|
|
20
21
|
custom/composables/useAgentTransitions.ts
|
|
@@ -31,5 +32,5 @@ custom/skills/fetch_data/SKILL.md
|
|
|
31
32
|
custom/skills/mutate_data/
|
|
32
33
|
custom/skills/mutate_data/SKILL.md
|
|
33
34
|
|
|
34
|
-
sent
|
|
35
|
-
total size is
|
|
35
|
+
sent 187,002 bytes received 451 bytes 374,906.00 bytes/sec
|
|
36
|
+
total size is 185,150 speedup is 0.99
|
package/custom/ChatSurface.vue
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
class="fixed bg-lightNavbar dark:bg-darkNavbar h-screen top-0 right-0 border-x border-b border-gray-200 dark:border-gray-700
|
|
24
24
|
flex flex z-40"
|
|
25
25
|
:class="[agentStore.isChatOpen ? 'translate-x-0' : 'translate-x-full', !agentStore.isTeleportedToBody ? 'shadow-2xl' : '']"
|
|
26
|
-
:style="{ width: agentStore.chatWidth + '
|
|
26
|
+
:style="{ width: agentStore.chatWidth + 'rem' }"
|
|
27
27
|
>
|
|
28
28
|
<div
|
|
29
29
|
v-if="!coreStore.isMobile"
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
<div
|
|
104
104
|
class="w-full mb-2 flex items-center justify-center px-2 bg-transparent relative translate-x-[-50%] left-1/2"
|
|
105
105
|
:style="{
|
|
106
|
-
maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'px' : '100%',
|
|
106
|
+
maxWidth: agentStore.isFullScreen ? remToPx(agentStore.MAX_WIDTH)+'px' : '100%',
|
|
107
107
|
transition: `transform ${agentTransitions.TRANSITION_DURATION}ms ease-in-out`
|
|
108
108
|
}"
|
|
109
109
|
>
|
|
@@ -185,6 +185,7 @@ import { useAgentStore } from './composables/useAgentStore';
|
|
|
185
185
|
import { useAgentTransitions } from './composables/useAgentTransitions';
|
|
186
186
|
import { Button } from '@/afcl';
|
|
187
187
|
import { useCoreStore } from '@/stores/core';
|
|
188
|
+
import { remToPx, pxToRem } from './utils';
|
|
188
189
|
|
|
189
190
|
const props = defineProps<{
|
|
190
191
|
meta: {
|
|
@@ -209,7 +210,7 @@ let startWidth = 0
|
|
|
209
210
|
|
|
210
211
|
const startResize = (e: MouseEvent) => {
|
|
211
212
|
startX = e.clientX
|
|
212
|
-
startWidth = agentStore.chatWidth
|
|
213
|
+
startWidth = remToPx(agentStore.chatWidth)
|
|
213
214
|
|
|
214
215
|
document.body.style.userSelect = 'none'
|
|
215
216
|
document.body.style.cursor = 'ew-resize'
|
|
@@ -220,7 +221,7 @@ const startResize = (e: MouseEvent) => {
|
|
|
220
221
|
|
|
221
222
|
const onResize = (e: MouseEvent) => {
|
|
222
223
|
const dx = startX - e.clientX
|
|
223
|
-
agentStore.setChatWidth(Math.min(Math.max(startWidth + dx, agentStore.MIN_WIDTH), agentStore.MAX_WIDTH))
|
|
224
|
+
agentStore.setChatWidth(Math.min(Math.max(startWidth + dx, remToPx(agentStore.MIN_WIDTH)), remToPx(agentStore.MAX_WIDTH)))
|
|
224
225
|
agentTransitions.setChatSurfaceTransition(true);
|
|
225
226
|
}
|
|
226
227
|
|
|
@@ -246,7 +247,9 @@ onMounted(async () => {
|
|
|
246
247
|
agentStore.setAvailableModes(props.meta.modes, props.meta.defaultModeName);
|
|
247
248
|
agentStore.regisrerTextInput(textInput.value);
|
|
248
249
|
textInput.value?.focus();
|
|
249
|
-
agentStore.
|
|
250
|
+
const isTeleportedToBodyFromLocalStorage = agentStore.getLocalStorageItem('isTeleportedToBody') === 'true';
|
|
251
|
+
|
|
252
|
+
agentStore.setIsTeleportedToBody(isTeleportedToBodyFromLocalStorage || props.meta.stickByDefault);
|
|
250
253
|
await agentStore.fetchSessionsList();
|
|
251
254
|
});
|
|
252
255
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
:threshold="10"
|
|
25
25
|
behavior="smooth"
|
|
26
26
|
:style="{
|
|
27
|
-
maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'
|
|
27
|
+
maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'rem' : '100%',
|
|
28
28
|
transition: `
|
|
29
29
|
max-width ${agentTransitions.TRANSITION_DURATION}ms ease-in-out,
|
|
30
30
|
transform ${agentTransitions.TRANSITION_DURATION}ms ease-in-out
|
|
@@ -37,9 +37,8 @@
|
|
|
37
37
|
class="flex flex-col w-full"
|
|
38
38
|
:class="message.role === 'user' ? 'self-end' : 'self-start'"
|
|
39
39
|
>
|
|
40
|
-
<ToolsGroup :toolGroup="groupToolCallParts(message)" />
|
|
41
40
|
<template
|
|
42
|
-
v-for="part in getParts(message)"
|
|
41
|
+
v-for="(part, index) in getParts(message)"
|
|
43
42
|
:key="part.type"
|
|
44
43
|
>
|
|
45
44
|
<Message
|
|
@@ -52,6 +51,7 @@
|
|
|
52
51
|
@toggle-thoughts="() => clicks++"
|
|
53
52
|
>
|
|
54
53
|
</Message>
|
|
54
|
+
<ToolsGroup v-else :toolGroup="groupToolCallParts(message, index, part)" />
|
|
55
55
|
</template>
|
|
56
56
|
</div>
|
|
57
57
|
<!-- Show a placeholder message if the last message is not of type 'text' or 'reasoning' -->
|
|
@@ -154,27 +154,39 @@ const formatToolCallTextPart = ((part: IPart, currentMessage: IMessage) => {
|
|
|
154
154
|
return null;
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
const groupToolCallParts = (message: IMessage) => {
|
|
158
|
-
const groupedParts = [];
|
|
159
|
-
let currentToolName = null;
|
|
157
|
+
const groupToolCallParts = (message: IMessage, currentPartIndex: number, currentPart: IPart) => {
|
|
158
|
+
const groupedParts: { title: string; groupedTools: IPart[] }[] = [];
|
|
159
|
+
let currentToolName: string | null = null;
|
|
160
160
|
const parts = getParts(message);
|
|
161
161
|
if (!parts) return [];
|
|
162
162
|
const formatedToolParts = parts.map(part => {
|
|
163
163
|
return formatToolCallTextPart(part as IPart, message)
|
|
164
164
|
});
|
|
165
|
+
const currentPartIndexInFormatedParts = formatedToolParts.findIndex(part => part?.toolInfo?.toolCallId === currentPart.data?.toolCallId);
|
|
166
|
+
if (currentPartIndexInFormatedParts === -1) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
165
169
|
for( const[index, part] of formatedToolParts.entries()){
|
|
166
|
-
if(
|
|
170
|
+
if ( index < currentPartIndexInFormatedParts - 1 ) {
|
|
167
171
|
continue;
|
|
168
172
|
}
|
|
169
|
-
if
|
|
170
|
-
groupedParts[groupedParts.length - 1].groupedTools.push(part);
|
|
173
|
+
if(!part || !part.toolInfo) {
|
|
171
174
|
continue;
|
|
172
175
|
}
|
|
173
176
|
currentToolName = part.toolInfo.toolName;
|
|
174
|
-
groupedParts.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
if (!groupedParts.find(group => group.title === currentToolName)) {
|
|
178
|
+
groupedParts.push({
|
|
179
|
+
title: currentToolName,
|
|
180
|
+
groupedTools: []
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
if( formatedToolParts[currentPartIndexInFormatedParts - 1]?.toolInfo.toolName === part.toolInfo.toolName) {
|
|
184
|
+
continue;
|
|
185
|
+
} else if ( formatedToolParts[currentPartIndexInFormatedParts + 1]?.toolInfo.toolName === part.toolInfo.toolName) {
|
|
186
|
+
groupedParts[groupedParts.length - 1].groupedTools.push(formatedToolParts[currentPartIndexInFormatedParts + 1] as IPart);
|
|
187
|
+
} else {
|
|
188
|
+
groupedParts[groupedParts.length - 1].groupedTools.push(part);
|
|
189
|
+
}
|
|
178
190
|
}
|
|
179
191
|
return groupedParts;
|
|
180
192
|
}
|
package/custom/ToolsGroup.vue
CHANGED
|
@@ -8,6 +8,7 @@ import { DefaultChatTransport } from 'ai';
|
|
|
8
8
|
import { useCoreStore } from '@/stores/core';
|
|
9
9
|
import { useAgentTransitions } from './useAgentTransitions';
|
|
10
10
|
import { useWindowSize } from '@vueuse/core';
|
|
11
|
+
import { remToPx, pxToRem } from '../utils';
|
|
11
12
|
|
|
12
13
|
type AgentMode = {
|
|
13
14
|
name: string;
|
|
@@ -19,9 +20,9 @@ const PLACEHOLDER_DELETING_DELAY_MS = 35;
|
|
|
19
20
|
const PLACEHOLDER_HOLD_DELAY_MS = 3000;
|
|
20
21
|
|
|
21
22
|
export const useAgentStore = defineStore('agent', () => {
|
|
22
|
-
const DEFAULT_CHAT_WIDTH =
|
|
23
|
-
const MAX_WIDTH =
|
|
24
|
-
const MIN_WIDTH =
|
|
23
|
+
const DEFAULT_CHAT_WIDTH = 30;
|
|
24
|
+
const MAX_WIDTH = 60;
|
|
25
|
+
const MIN_WIDTH = 25
|
|
25
26
|
const agentTransitions = useAgentTransitions();
|
|
26
27
|
|
|
27
28
|
const activeSessionId = ref<string | null>(null);
|
|
@@ -71,6 +72,9 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
71
72
|
})
|
|
72
73
|
watch(chatWidth, (newVal: number) => {
|
|
73
74
|
setLocalStorageItem('chatWidth', newVal.toString());
|
|
75
|
+
if (!isFullScreen.value) {
|
|
76
|
+
setLocalStorageItem('chatWidthBeforeFullScreen', newVal.toString());
|
|
77
|
+
}
|
|
74
78
|
})
|
|
75
79
|
watch(activeSessionId, (newVal: string | null) => {
|
|
76
80
|
if (newVal) {
|
|
@@ -90,14 +94,14 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
90
94
|
onMounted(() => {
|
|
91
95
|
const chatWidthBeforeFullScreen = parseInt(getLocalStorageItem('chatWidthBeforeFullScreen') || '0', 10);
|
|
92
96
|
if (chatWidthBeforeFullScreen) {
|
|
93
|
-
|
|
97
|
+
setChatWidth(remToPx(chatWidthBeforeFullScreen));
|
|
94
98
|
} else {
|
|
95
99
|
const savedChatWidth = parseInt(getLocalStorageItem('chatWidth') || '0', 10);
|
|
96
100
|
if (savedChatWidth) {
|
|
97
101
|
if (savedChatWidth > MAX_WIDTH || savedChatWidth < MIN_WIDTH) {
|
|
98
|
-
|
|
102
|
+
setChatWidth(remToPx(DEFAULT_CHAT_WIDTH));
|
|
99
103
|
} else {
|
|
100
|
-
|
|
104
|
+
setChatWidth(remToPx(savedChatWidth));
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
}
|
|
@@ -110,7 +114,7 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
110
114
|
isChatOpen.value = getLocalStorageItem('isChatOpen') === 'true';
|
|
111
115
|
}
|
|
112
116
|
if (coreStore.isMobile) {
|
|
113
|
-
|
|
117
|
+
setChatWidth(window.innerWidth);
|
|
114
118
|
}
|
|
115
119
|
appRoot.value = document.getElementById('app');
|
|
116
120
|
header.value = document.getElementById('af-header-nav');
|
|
@@ -135,23 +139,24 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
135
139
|
const isTeleportedBeforeFullScreen = getLocalStorageItem('isTeleportedToBodyBeforeFullScreen') === 'true';
|
|
136
140
|
agentTransitions.setAppRootTransition(true);
|
|
137
141
|
setIsTeleportedToBody(isTeleportedBeforeFullScreen);
|
|
138
|
-
setChatWidth(lastChatWidth, false);
|
|
142
|
+
setChatWidth(remToPx(lastChatWidth), false);
|
|
139
143
|
setTimeout(() => agentTransitions.setAppRootTransition(false), agentTransitions.TRANSITION_DURATION);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
|
|
147
|
+
//takes on input width in pixels, converts to rem and sets chat width
|
|
143
148
|
function setChatWidth(width: number, blockTransition = true) {
|
|
144
149
|
if (blockTransition) {
|
|
145
150
|
agentTransitions.setAppRootTransition(true);
|
|
146
151
|
}
|
|
147
|
-
chatWidth.value = width;
|
|
152
|
+
chatWidth.value = pxToRem(width);
|
|
148
153
|
|
|
149
154
|
}
|
|
150
155
|
watch([isTeleportedToBody, isChatOpen, chatWidth], ([newIsTeleportedToBody, newIsChatOpen, newChatWidth]: [boolean, boolean, number]) => {
|
|
151
156
|
if (appRoot.value && header.value) {
|
|
152
157
|
if (newIsTeleportedToBody && newIsChatOpen) {
|
|
153
|
-
appRoot.value.style.paddingRight = `${chatWidth.value}px`;
|
|
154
|
-
header.value.style.paddingRight = `${chatWidth.value}px`;
|
|
158
|
+
appRoot.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
|
|
159
|
+
header.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
|
|
155
160
|
} else {
|
|
156
161
|
appRoot.value.style.paddingRight = '';
|
|
157
162
|
header.value.style.paddingRight = '';
|
|
@@ -572,5 +577,6 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
572
577
|
DEFAULT_CHAT_WIDTH,
|
|
573
578
|
MAX_WIDTH,
|
|
574
579
|
MIN_WIDTH,
|
|
580
|
+
getLocalStorageItem
|
|
575
581
|
}
|
|
576
582
|
})
|
package/custom/utils.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function remToPx(rem: number): number {
|
|
2
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
3
|
+
return rem * rootFontSize;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function pxToRem(px: number): number {
|
|
7
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
8
|
+
return px / rootFontSize;
|
|
9
|
+
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
class="fixed bg-lightNavbar dark:bg-darkNavbar h-screen top-0 right-0 border-x border-b border-gray-200 dark:border-gray-700
|
|
24
24
|
flex flex z-40"
|
|
25
25
|
:class="[agentStore.isChatOpen ? 'translate-x-0' : 'translate-x-full', !agentStore.isTeleportedToBody ? 'shadow-2xl' : '']"
|
|
26
|
-
:style="{ width: agentStore.chatWidth + '
|
|
26
|
+
:style="{ width: agentStore.chatWidth + 'rem' }"
|
|
27
27
|
>
|
|
28
28
|
<div
|
|
29
29
|
v-if="!coreStore.isMobile"
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
<div
|
|
104
104
|
class="w-full mb-2 flex items-center justify-center px-2 bg-transparent relative translate-x-[-50%] left-1/2"
|
|
105
105
|
:style="{
|
|
106
|
-
maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'px' : '100%',
|
|
106
|
+
maxWidth: agentStore.isFullScreen ? remToPx(agentStore.MAX_WIDTH)+'px' : '100%',
|
|
107
107
|
transition: `transform ${agentTransitions.TRANSITION_DURATION}ms ease-in-out`
|
|
108
108
|
}"
|
|
109
109
|
>
|
|
@@ -185,6 +185,7 @@ import { useAgentStore } from './composables/useAgentStore';
|
|
|
185
185
|
import { useAgentTransitions } from './composables/useAgentTransitions';
|
|
186
186
|
import { Button } from '@/afcl';
|
|
187
187
|
import { useCoreStore } from '@/stores/core';
|
|
188
|
+
import { remToPx, pxToRem } from './utils';
|
|
188
189
|
|
|
189
190
|
const props = defineProps<{
|
|
190
191
|
meta: {
|
|
@@ -209,7 +210,7 @@ let startWidth = 0
|
|
|
209
210
|
|
|
210
211
|
const startResize = (e: MouseEvent) => {
|
|
211
212
|
startX = e.clientX
|
|
212
|
-
startWidth = agentStore.chatWidth
|
|
213
|
+
startWidth = remToPx(agentStore.chatWidth)
|
|
213
214
|
|
|
214
215
|
document.body.style.userSelect = 'none'
|
|
215
216
|
document.body.style.cursor = 'ew-resize'
|
|
@@ -220,7 +221,7 @@ const startResize = (e: MouseEvent) => {
|
|
|
220
221
|
|
|
221
222
|
const onResize = (e: MouseEvent) => {
|
|
222
223
|
const dx = startX - e.clientX
|
|
223
|
-
agentStore.setChatWidth(Math.min(Math.max(startWidth + dx, agentStore.MIN_WIDTH), agentStore.MAX_WIDTH))
|
|
224
|
+
agentStore.setChatWidth(Math.min(Math.max(startWidth + dx, remToPx(agentStore.MIN_WIDTH)), remToPx(agentStore.MAX_WIDTH)))
|
|
224
225
|
agentTransitions.setChatSurfaceTransition(true);
|
|
225
226
|
}
|
|
226
227
|
|
|
@@ -246,7 +247,9 @@ onMounted(async () => {
|
|
|
246
247
|
agentStore.setAvailableModes(props.meta.modes, props.meta.defaultModeName);
|
|
247
248
|
agentStore.regisrerTextInput(textInput.value);
|
|
248
249
|
textInput.value?.focus();
|
|
249
|
-
agentStore.
|
|
250
|
+
const isTeleportedToBodyFromLocalStorage = agentStore.getLocalStorageItem('isTeleportedToBody') === 'true';
|
|
251
|
+
|
|
252
|
+
agentStore.setIsTeleportedToBody(isTeleportedToBodyFromLocalStorage || props.meta.stickByDefault);
|
|
250
253
|
await agentStore.fetchSessionsList();
|
|
251
254
|
});
|
|
252
255
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
:threshold="10"
|
|
25
25
|
behavior="smooth"
|
|
26
26
|
:style="{
|
|
27
|
-
maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'
|
|
27
|
+
maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'rem' : '100%',
|
|
28
28
|
transition: `
|
|
29
29
|
max-width ${agentTransitions.TRANSITION_DURATION}ms ease-in-out,
|
|
30
30
|
transform ${agentTransitions.TRANSITION_DURATION}ms ease-in-out
|
|
@@ -37,9 +37,8 @@
|
|
|
37
37
|
class="flex flex-col w-full"
|
|
38
38
|
:class="message.role === 'user' ? 'self-end' : 'self-start'"
|
|
39
39
|
>
|
|
40
|
-
<ToolsGroup :toolGroup="groupToolCallParts(message)" />
|
|
41
40
|
<template
|
|
42
|
-
v-for="part in getParts(message)"
|
|
41
|
+
v-for="(part, index) in getParts(message)"
|
|
43
42
|
:key="part.type"
|
|
44
43
|
>
|
|
45
44
|
<Message
|
|
@@ -52,6 +51,7 @@
|
|
|
52
51
|
@toggle-thoughts="() => clicks++"
|
|
53
52
|
>
|
|
54
53
|
</Message>
|
|
54
|
+
<ToolsGroup v-else :toolGroup="groupToolCallParts(message, index, part)" />
|
|
55
55
|
</template>
|
|
56
56
|
</div>
|
|
57
57
|
<!-- Show a placeholder message if the last message is not of type 'text' or 'reasoning' -->
|
|
@@ -154,27 +154,39 @@ const formatToolCallTextPart = ((part: IPart, currentMessage: IMessage) => {
|
|
|
154
154
|
return null;
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
const groupToolCallParts = (message: IMessage) => {
|
|
158
|
-
const groupedParts = [];
|
|
159
|
-
let currentToolName = null;
|
|
157
|
+
const groupToolCallParts = (message: IMessage, currentPartIndex: number, currentPart: IPart) => {
|
|
158
|
+
const groupedParts: { title: string; groupedTools: IPart[] }[] = [];
|
|
159
|
+
let currentToolName: string | null = null;
|
|
160
160
|
const parts = getParts(message);
|
|
161
161
|
if (!parts) return [];
|
|
162
162
|
const formatedToolParts = parts.map(part => {
|
|
163
163
|
return formatToolCallTextPart(part as IPart, message)
|
|
164
164
|
});
|
|
165
|
+
const currentPartIndexInFormatedParts = formatedToolParts.findIndex(part => part?.toolInfo?.toolCallId === currentPart.data?.toolCallId);
|
|
166
|
+
if (currentPartIndexInFormatedParts === -1) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
165
169
|
for( const[index, part] of formatedToolParts.entries()){
|
|
166
|
-
if(
|
|
170
|
+
if ( index < currentPartIndexInFormatedParts - 1 ) {
|
|
167
171
|
continue;
|
|
168
172
|
}
|
|
169
|
-
if
|
|
170
|
-
groupedParts[groupedParts.length - 1].groupedTools.push(part);
|
|
173
|
+
if(!part || !part.toolInfo) {
|
|
171
174
|
continue;
|
|
172
175
|
}
|
|
173
176
|
currentToolName = part.toolInfo.toolName;
|
|
174
|
-
groupedParts.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
if (!groupedParts.find(group => group.title === currentToolName)) {
|
|
178
|
+
groupedParts.push({
|
|
179
|
+
title: currentToolName,
|
|
180
|
+
groupedTools: []
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
if( formatedToolParts[currentPartIndexInFormatedParts - 1]?.toolInfo.toolName === part.toolInfo.toolName) {
|
|
184
|
+
continue;
|
|
185
|
+
} else if ( formatedToolParts[currentPartIndexInFormatedParts + 1]?.toolInfo.toolName === part.toolInfo.toolName) {
|
|
186
|
+
groupedParts[groupedParts.length - 1].groupedTools.push(formatedToolParts[currentPartIndexInFormatedParts + 1] as IPart);
|
|
187
|
+
} else {
|
|
188
|
+
groupedParts[groupedParts.length - 1].groupedTools.push(part);
|
|
189
|
+
}
|
|
178
190
|
}
|
|
179
191
|
return groupedParts;
|
|
180
192
|
}
|
|
@@ -8,6 +8,7 @@ import { DefaultChatTransport } from 'ai';
|
|
|
8
8
|
import { useCoreStore } from '@/stores/core';
|
|
9
9
|
import { useAgentTransitions } from './useAgentTransitions';
|
|
10
10
|
import { useWindowSize } from '@vueuse/core';
|
|
11
|
+
import { remToPx, pxToRem } from '../utils';
|
|
11
12
|
|
|
12
13
|
type AgentMode = {
|
|
13
14
|
name: string;
|
|
@@ -19,9 +20,9 @@ const PLACEHOLDER_DELETING_DELAY_MS = 35;
|
|
|
19
20
|
const PLACEHOLDER_HOLD_DELAY_MS = 3000;
|
|
20
21
|
|
|
21
22
|
export const useAgentStore = defineStore('agent', () => {
|
|
22
|
-
const DEFAULT_CHAT_WIDTH =
|
|
23
|
-
const MAX_WIDTH =
|
|
24
|
-
const MIN_WIDTH =
|
|
23
|
+
const DEFAULT_CHAT_WIDTH = 30;
|
|
24
|
+
const MAX_WIDTH = 60;
|
|
25
|
+
const MIN_WIDTH = 25
|
|
25
26
|
const agentTransitions = useAgentTransitions();
|
|
26
27
|
|
|
27
28
|
const activeSessionId = ref<string | null>(null);
|
|
@@ -71,6 +72,9 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
71
72
|
})
|
|
72
73
|
watch(chatWidth, (newVal: number) => {
|
|
73
74
|
setLocalStorageItem('chatWidth', newVal.toString());
|
|
75
|
+
if (!isFullScreen.value) {
|
|
76
|
+
setLocalStorageItem('chatWidthBeforeFullScreen', newVal.toString());
|
|
77
|
+
}
|
|
74
78
|
})
|
|
75
79
|
watch(activeSessionId, (newVal: string | null) => {
|
|
76
80
|
if (newVal) {
|
|
@@ -90,14 +94,14 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
90
94
|
onMounted(() => {
|
|
91
95
|
const chatWidthBeforeFullScreen = parseInt(getLocalStorageItem('chatWidthBeforeFullScreen') || '0', 10);
|
|
92
96
|
if (chatWidthBeforeFullScreen) {
|
|
93
|
-
|
|
97
|
+
setChatWidth(remToPx(chatWidthBeforeFullScreen));
|
|
94
98
|
} else {
|
|
95
99
|
const savedChatWidth = parseInt(getLocalStorageItem('chatWidth') || '0', 10);
|
|
96
100
|
if (savedChatWidth) {
|
|
97
101
|
if (savedChatWidth > MAX_WIDTH || savedChatWidth < MIN_WIDTH) {
|
|
98
|
-
|
|
102
|
+
setChatWidth(remToPx(DEFAULT_CHAT_WIDTH));
|
|
99
103
|
} else {
|
|
100
|
-
|
|
104
|
+
setChatWidth(remToPx(savedChatWidth));
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
}
|
|
@@ -110,7 +114,7 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
110
114
|
isChatOpen.value = getLocalStorageItem('isChatOpen') === 'true';
|
|
111
115
|
}
|
|
112
116
|
if (coreStore.isMobile) {
|
|
113
|
-
|
|
117
|
+
setChatWidth(window.innerWidth);
|
|
114
118
|
}
|
|
115
119
|
appRoot.value = document.getElementById('app');
|
|
116
120
|
header.value = document.getElementById('af-header-nav');
|
|
@@ -135,23 +139,24 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
135
139
|
const isTeleportedBeforeFullScreen = getLocalStorageItem('isTeleportedToBodyBeforeFullScreen') === 'true';
|
|
136
140
|
agentTransitions.setAppRootTransition(true);
|
|
137
141
|
setIsTeleportedToBody(isTeleportedBeforeFullScreen);
|
|
138
|
-
setChatWidth(lastChatWidth, false);
|
|
142
|
+
setChatWidth(remToPx(lastChatWidth), false);
|
|
139
143
|
setTimeout(() => agentTransitions.setAppRootTransition(false), agentTransitions.TRANSITION_DURATION);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
|
|
147
|
+
//takes on input width in pixels, converts to rem and sets chat width
|
|
143
148
|
function setChatWidth(width: number, blockTransition = true) {
|
|
144
149
|
if (blockTransition) {
|
|
145
150
|
agentTransitions.setAppRootTransition(true);
|
|
146
151
|
}
|
|
147
|
-
chatWidth.value = width;
|
|
152
|
+
chatWidth.value = pxToRem(width);
|
|
148
153
|
|
|
149
154
|
}
|
|
150
155
|
watch([isTeleportedToBody, isChatOpen, chatWidth], ([newIsTeleportedToBody, newIsChatOpen, newChatWidth]: [boolean, boolean, number]) => {
|
|
151
156
|
if (appRoot.value && header.value) {
|
|
152
157
|
if (newIsTeleportedToBody && newIsChatOpen) {
|
|
153
|
-
appRoot.value.style.paddingRight = `${chatWidth.value}px`;
|
|
154
|
-
header.value.style.paddingRight = `${chatWidth.value}px`;
|
|
158
|
+
appRoot.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
|
|
159
|
+
header.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
|
|
155
160
|
} else {
|
|
156
161
|
appRoot.value.style.paddingRight = '';
|
|
157
162
|
header.value.style.paddingRight = '';
|
|
@@ -572,5 +577,6 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
572
577
|
DEFAULT_CHAT_WIDTH,
|
|
573
578
|
MAX_WIDTH,
|
|
574
579
|
MIN_WIDTH,
|
|
580
|
+
getLocalStorageItem
|
|
575
581
|
}
|
|
576
582
|
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function remToPx(rem: number): number {
|
|
2
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
3
|
+
return rem * rootFontSize;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function pxToRem(px: number): number {
|
|
7
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
8
|
+
return px / rootFontSize;
|
|
9
|
+
}
|