@adminforth/agent 3.2.0 → 3.3.0

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.
@@ -52,7 +52,7 @@
52
52
  <script setup lang="ts">
53
53
  import { IconBot } from '@iconify-prerendered/vue-lucide';
54
54
  import { Button } from '@/afcl';
55
- import { useTemplateRef, onMounted, ref, onUnmounted } from 'vue';
55
+ import { useTemplateRef, onMounted, ref, onUnmounted, onBeforeUnmount, computed, watch, nextTick } from 'vue';
56
56
  import { onClickOutside } from '@vueuse/core'
57
57
  import ConversationArea from './conversation_area/ConversationArea.vue';
58
58
  import ChatHeader from './ChatHeader.vue';
@@ -60,7 +60,7 @@ import ChatFooter from './ChatFooter.vue';
60
60
  import { useAgentStore } from './composables/useAgentStore';
61
61
  import { useAgentTransitions } from './composables/useAgentTransitions';
62
62
  import { useCoreStore } from '@/stores/core';
63
- import { remToPx } from './utils';
63
+ import { remToPx, getLayoutElements } from './utils';
64
64
 
65
65
  const props = defineProps<{
66
66
  meta: {
@@ -87,6 +87,9 @@ const dvh = ref(window.visualViewport?.height || window.innerHeight);
87
87
  let startX = 0
88
88
  let startWidth = 0
89
89
 
90
+ const layoutPaddingRight = computed(() => agentStore.isTeleportedToBody && agentStore.isChatOpen ? `${remToPx(agentStore.chatWidth)}px` : '');
91
+ watch(layoutPaddingRight, setLayoutPaddingRight);
92
+
90
93
  onClickOutside(chatSurface as any, () => {if (!agentStore.isTeleportedToBody && !agentStore.isFullScreen) agentStore.setIsChatOpen(false);});
91
94
 
92
95
  onMounted(async () => {
@@ -108,9 +111,21 @@ onMounted(async () => {
108
111
  agentStore.setIsChatOpen(true);
109
112
  }
110
113
  }
114
+ // the header is re-created after a re-login, so the room for the chat is made on every mount
115
+ setLayoutPaddingRight(layoutPaddingRight.value);
116
+ nextTick(() => {
117
+ agentTransitions.setAppRootTransition(false);
118
+ agentTransitions.setChatSurfaceTransition(false);
119
+ });
111
120
  await agentStore.fetchSessionsList();
112
121
  });
113
122
 
123
+ // on logout the header goes away with this component, but #app stays and must not keep the room for the chat
124
+ onBeforeUnmount(() => {
125
+ agentTransitions.setAppRootTransition(true);
126
+ setLayoutPaddingRight('');
127
+ })
128
+
114
129
  onUnmounted(() => {
115
130
  window.removeEventListener('resize', updateHeight)
116
131
  })
@@ -139,16 +154,18 @@ const stopResize = () => {
139
154
  document.removeEventListener('mousemove', onResize)
140
155
  document.removeEventListener('mouseup', stopResize)
141
156
 
142
- const appRoot = document.getElementById('app');
143
- const header = document.getElementById('af-header-nav');
144
- if (appRoot && header) {
145
- agentTransitions.setAppRootTransition(false);
146
- agentTransitions.setChatSurfaceTransition(false);
147
- }
157
+ agentTransitions.setAppRootTransition(false);
158
+ agentTransitions.setChatSurfaceTransition(false);
148
159
  }
149
160
 
150
161
  function updateHeight() {
151
162
  dvh.value = Math.round(window.visualViewport?.height || window.innerHeight);
152
163
  }
153
164
 
165
+ function setLayoutPaddingRight(paddingRight: string) {
166
+ for (const element of getLayoutElements()) {
167
+ element.style.paddingRight = paddingRight;
168
+ }
169
+ }
170
+
154
171
  </script>
@@ -49,8 +49,6 @@ export const useAgentStore = defineStore('agent', () => {
49
49
  isTeleportedToBody.value = isTeleported;
50
50
  }
51
51
  const coreStore = useCoreStore();
52
- const appRoot = ref<HTMLElement | null>(null);
53
- const header = ref<HTMLElement | null>(null);
54
52
  const lastSessionId = ref<string | null>(null);
55
53
  const chatWidth = ref(DEFAULT_CHAT_WIDTH);
56
54
  const availableModes = ref<AgentMode[]>([]);
@@ -336,13 +334,6 @@ export const useAgentStore = defineStore('agent', () => {
336
334
  if (coreStore.isMobile) {
337
335
  setChatWidth(window.innerWidth);
338
336
  }
339
- appRoot.value = document.getElementById('app');
340
- header.value = document.getElementById('af-header-nav');
341
- if (appRoot.value && header.value) {
342
- nextTick(() => {
343
- agentTransitions.setAppRootTransition(false);
344
- });
345
- }
346
337
  })
347
338
 
348
339
  const isFullScreen = ref(false);
@@ -381,17 +372,6 @@ export const useAgentStore = defineStore('agent', () => {
381
372
  chatWidth.value = pxToRem(width);
382
373
 
383
374
  }
384
- watch([isTeleportedToBody, isChatOpen, chatWidth], ([newIsTeleportedToBody, newIsChatOpen, newChatWidth]: [boolean, boolean, number]) => {
385
- if (appRoot.value && header.value) {
386
- if (newIsTeleportedToBody && newIsChatOpen) {
387
- appRoot.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
388
- header.value.style.paddingRight = `${remToPx(chatWidth.value)}px`;
389
- } else {
390
- appRoot.value.style.paddingRight = '';
391
- header.value.style.paddingRight = '';
392
- }
393
- }
394
- })
395
375
 
396
376
  function setAvailableModes(modes: AgentMode[], defaultModeName?: string | null) {
397
377
  availableModes.value = modes;
@@ -1,53 +1,29 @@
1
1
  import { defineStore } from 'pinia';
2
- import { ref, nextTick,onMounted } from 'vue';
3
2
  import { useAgentStore } from './useAgentStore';
3
+ import { getLayoutElements } from '../utils';
4
4
 
5
5
 
6
6
  export const useAgentTransitions = defineStore('agentTransitions', () => {
7
7
  const TRANSITION_DURATION = 300;
8
8
 
9
9
  const agentStore = useAgentStore();
10
- const appRoot = ref<HTMLElement | null>(null);
11
- const header = ref<HTMLElement | null>(null);
12
10
 
13
- const chatRoot = ref<HTMLElement | null>(null);
14
-
15
- onMounted(() => {
16
- appRoot.value = document.getElementById('app');
17
- header.value = document.getElementById('af-header-nav');
18
- chatRoot.value = document.getElementById('adminforth-agent-chat-surface');
19
- if (appRoot.value && header.value) {
20
- nextTick(() => {
21
- setAppRootTransition(false);
22
- });
23
- }
24
- if (chatRoot.value) {
25
- nextTick(() => {
26
- setChatSurfaceTransition(false);
27
- });
28
- }
29
- });
11
+ // elements are looked up on every call, the header and the chat surface are re-created after a re-login
30
12
  function setAppRootTransition(blockTransition = true) {
31
- if (appRoot.value && header.value) {
32
- if (blockTransition) {
33
- appRoot.value.style.transition = '';
34
- header.value.style.transition = '';
35
- } else {
36
- appRoot.value.style.transition = `padding-right ${TRANSITION_DURATION}ms ease-in-out`;
37
- header.value.style.transition = `padding-right ${TRANSITION_DURATION}ms ease-in-out`;
38
- }
13
+ const transition = blockTransition ? '' : `padding-right ${TRANSITION_DURATION}ms ease-in-out`;
14
+ for (const element of getLayoutElements()) {
15
+ element.style.transition = transition;
39
16
  }
40
17
  }
41
18
  function setChatSurfaceTransition(blockTransition = true) {
42
- if (chatRoot.value) {
43
- if (blockTransition) {
44
- chatRoot.value.style.transition = '';
45
- } else {
46
- chatRoot.value.style.transition = `
47
- transform ${TRANSITION_DURATION}ms ease-in-out,
48
- width ${TRANSITION_DURATION}ms ease-in-out
49
- `;
50
- }
19
+ const chatRoot = document.getElementById('adminforth-agent-chat-surface')!;
20
+ if (blockTransition) {
21
+ chatRoot.style.transition = '';
22
+ } else {
23
+ chatRoot.style.transition = `
24
+ transform ${TRANSITION_DURATION}ms ease-in-out,
25
+ width ${TRANSITION_DURATION}ms ease-in-out
26
+ `;
51
27
  }
52
28
  }
53
29
  return {
@@ -10,6 +10,11 @@ export function pxToRem(px: number): number {
10
10
  return px / rootFontSize;
11
11
  }
12
12
 
13
+ // #app and the header make room for the docked chat, both exist while ChatSurface is mounted in the header
14
+ export function getLayoutElements(): HTMLElement[] {
15
+ return [document.getElementById('app')!, document.getElementById('af-header-nav')!];
16
+ }
17
+
13
18
 
14
19
  export function getMessageParts(message: IMessage): IPart[] {
15
20
  return message.parts?.length
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",