@adminforth/agent 2.4.0 → 2.5.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.
@@ -25,6 +25,7 @@
25
25
  ]"
26
26
  :placeholder="placeholderText"
27
27
  @keydown.enter.exact.prevent="sendMessage"
28
+ @keydown.esc="onEscape"
28
29
  />
29
30
  <div class="flex items-center justify-between px-2 py-1">
30
31
  <div
@@ -74,10 +75,9 @@
74
75
  </div>
75
76
  </Transition>
76
77
  </div>
77
- <MicrophoneButton
78
- v-if="props.meta.hasAudioAdapter"
79
- v-show="!agentStore.isEditingMessage"
80
- />
78
+ <div v-if="props.meta.hasAudioAdapter" v-show="!agentStore.isEditingMessage" class="contents">
79
+ <MicrophoneButton />
80
+ </div>
81
81
  <template v-if="!agentStore.isAudioChatMode">
82
82
  <template v-if="agentStore.isEditingMessage">
83
83
  <EditActionButtons
@@ -222,6 +222,16 @@ function cancelEdit() {
222
222
  autoResize();
223
223
  }
224
224
 
225
+ // Esc discards an in-progress message edit; when not editing it does nothing so the
226
+ // keystroke keeps its default textarea behaviour.
227
+ function onEscape(event: KeyboardEvent) {
228
+ if (!agentStore.isEditingMessage) {
229
+ return;
230
+ }
231
+ event.preventDefault();
232
+ cancelEdit();
233
+ }
234
+
225
235
  function stopCurrentRequest() {
226
236
  agentStore.abortCurrentChatRequestAndAddSystemMessage();
227
237
  }
@@ -2,11 +2,11 @@
2
2
  <div
3
3
  class="relative flex flex-col w-full group/msg"
4
4
  >
5
- <div
6
- v-if="canEdit"
5
+ <div
6
+ v-if="showActionsBar"
7
7
  class="absolute w-full h-[calc(100%+1.5rem)] pb-8"
8
- @mouseenter="showEditButtonOnHover"
9
- @mouseleave="hideEditButtonOnHover"
8
+ @mouseenter="showEditButtonOnHover"
9
+ @mouseleave="hideEditButtonOnHover"
10
10
  />
11
11
  <Transition
12
12
  enter-active-class="transition ease-out duration-200"
@@ -17,20 +17,23 @@
17
17
  leave-to-class="opacity-0 scale-95"
18
18
  >
19
19
  <div
20
- v-if="canEdit && showEditButton"
21
- class="absolute flex -bottom-6 right-0 self-end p-1 mr-4 mt-0.5 z-20"
22
- @mouseenter="showEditButtonOnHover"
23
- @mouseleave="hideEditButtonOnHover"
20
+ v-if="showActionsBar && showEditButton"
21
+ class="absolute flex -bottom-6 p-1 mt-0.5 z-20"
22
+ :class="isUserMessage ? 'right-0 self-end mr-4' : 'left-0 self-start ml-4'"
23
+ @mouseenter="showEditButtonOnHover"
24
+ @mouseleave="hideEditButtonOnHover"
24
25
  >
25
26
  <button
27
+ v-if="canCopy"
26
28
  type="button"
27
29
  class="flex items-center justify-center w-8 h-8 rounded-md text-gray-400 hover:text-lightPrimary dark:hover:text-darkPrimary opacity-60 group-hover/msg:opacity-100 transition-opacity duration-150 hover:scale-110"
28
30
  :title="$t('Copy message')"
29
- @click="copyMessageToClipboard(message)"
31
+ @click="copyMessageToClipboard"
30
32
  >
31
33
  <IconFileCopySolid class="w-5 h-5" />
32
34
  </button>
33
35
  <button
36
+ v-if="canEdit"
34
37
  type="button"
35
38
  class="flex items-center justify-center w-8 h-8 rounded-md text-gray-400 hover:text-lightPrimary dark:hover:text-darkPrimary opacity-60 group-hover/msg:opacity-100 transition-opacity duration-150 hover:scale-110"
36
39
  :title="$t('Edit message')"
@@ -120,6 +123,19 @@
120
123
 
121
124
  const isUserMessage = computed(() => props.message.role === 'user');
122
125
 
126
+ const copyableText = computed(() =>
127
+ (props.message.parts ?? [])
128
+ .filter((part: any) => part.type === 'text' && !checkIfMessageSystemMessage(part.text ?? ''))
129
+ .map((part: any) => part.text ?? '')
130
+ .join('')
131
+ );
132
+ const canCopy = computed(() =>
133
+ Boolean(copyableText.value.trim()) && !agentStore.isEditingMessage
134
+ );
135
+ const showActionsBar = computed(() =>
136
+ canEdit.value || (!isUserMessage.value && canCopy.value)
137
+ );
138
+
123
139
  // While editing, hide only the *other* user messages of the edited turn (its steer
124
140
  // sub-messages); the edited message itself and all non-user parts stay visible.
125
141
  const shouldBeShownWhileEditing = computed(() =>
@@ -139,8 +155,8 @@
139
155
  showEditButton.value = false;
140
156
  }
141
157
 
142
- function copyMessageToClipboard(message: IMessage) {
143
- navigator.clipboard.writeText(message.parts[0].text ?? '')
158
+ function copyMessageToClipboard() {
159
+ navigator.clipboard.writeText(copyableText.value)
144
160
  .then(() => {
145
161
  alert({ message: 'Message copied to clipboard', variant: 'success' });
146
162
  })
@@ -25,6 +25,7 @@
25
25
  <textarea
26
26
  v-model="agentStore.userMessageInput"
27
27
  class="w-full min-h-24 resize-y bg-transparent text-sm text-gray-900 dark:text-gray-100 border-none focus:outline-none focus:ring-0 p-0"
28
+ @keydown.esc.prevent="agentStore.cancelEditMessage"
28
29
  />
29
30
  <EditActionButtons
30
31
  class="mt-2 self-end"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",