@adminforth/agent 3.1.2 → 3.1.5

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.
@@ -1,52 +1,5 @@
1
1
  <template>
2
- <div
3
- class="relative flex flex-col w-full group/msg"
4
- @mouseenter="showEditButtonOnHover"
5
- @mouseleave="hideEditButtonOnHover"
6
- >
7
- <div
8
- v-if="showActionsBar"
9
- class="absolute w-full h-[calc(100%+1.5rem)] pb-8"
10
- />
11
- <Transition
12
- enter-active-class="transition ease-out duration-200"
13
- enter-from-class="opacity-0 scale-95"
14
- enter-to-class="opacity-100 scale-100"
15
- leave-active-class="transition ease-in duration-150"
16
- leave-from-class="opacity-100 scale-100"
17
- leave-to-class="opacity-0 scale-95"
18
- >
19
- <div
20
- v-if="showActionsBar && showEditButton"
21
- class="absolute flex top-full -mt-1 p-1 z-20"
22
- :class="isUserMessage ? 'right-0 self-end mr-4' : 'left-0 self-start ml-4'"
23
- @mouseenter="showEditButtonOnHover"
24
- @mouseleave="hideEditButtonOnHover"
25
- >
26
- <Button
27
- v-if="canCopy"
28
- variant="ghost"
29
- size="sm"
30
- iconOnly
31
- :title="$t('Copy message')"
32
- :aria-label="$t('Copy message')"
33
- @click="copyMessageToClipboard"
34
- >
35
- <IconCopy />
36
- </Button>
37
- <Button
38
- v-if="canEdit"
39
- variant="ghost"
40
- size="sm"
41
- iconOnly
42
- :title="$t('Edit message')"
43
- :aria-label="$t('Edit message')"
44
- @click="agentStore.startEditMessage(message)"
45
- >
46
- <IconPencil />
47
- </Button>
48
- </div>
49
- </Transition>
2
+ <div class="relative flex flex-col w-full group/msg">
50
3
  <div
51
4
  v-if="message.role === 'user' && message.metadata?.steer && !isBeingEditedTurn"
52
5
  class="self-end mr-4 mb-0.5 text-xs italic text-lightInputPlaceholderText dark:text-darkInputPlaceholderText"
@@ -61,8 +14,11 @@
61
14
  v-for="(part, index) in getMessageParts(message)"
62
15
  :key="part.type"
63
16
  >
17
+ <!-- a text part drops the margin of its last block, so a part that follows another one (the stream
18
+ splits the text at every chart and tool call) brings back the gap between markdown blocks -->
64
19
  <TextRenderer
65
20
  v-if="part.type === 'text' && !checkIfMessageSystemMessage(part.text ?? '') && shouldBeShownWhileEditing"
21
+ class="[&+&]:mt-2"
66
22
  :message="isBeingEditedMessage ? agentStore.userMessageInput : part.text"
67
23
  :role="props.message.role"
68
24
  :editMode="isBeingEditedMessage"
@@ -77,7 +33,34 @@
77
33
  :message="part.text"
78
34
  />
79
35
  </template>
80
-
36
+ <div
37
+ v-if="reservesActionsRow"
38
+ class="flex h-7 opacity-0 transition-opacity duration-200 group-hover/msg:opacity-100 group-focus-within/msg:opacity-100"
39
+ :class="isUserMessage ? 'self-end mr-5' : 'self-start ml-5'"
40
+ >
41
+ <Button
42
+ v-if="canCopy"
43
+ variant="ghost"
44
+ size="sm"
45
+ iconOnly
46
+ :title="$t('Copy message')"
47
+ :aria-label="$t('Copy message')"
48
+ @click="copyMessageToClipboard"
49
+ >
50
+ <IconCopy />
51
+ </Button>
52
+ <Button
53
+ v-if="canEdit"
54
+ variant="ghost"
55
+ size="sm"
56
+ iconOnly
57
+ :title="$t('Edit message')"
58
+ :aria-label="$t('Edit message')"
59
+ @click="agentStore.startEditMessage(message)"
60
+ >
61
+ <IconPencil />
62
+ </Button>
63
+ </div>
81
64
  </div>
82
65
 
83
66
  </template>
@@ -86,7 +69,7 @@
86
69
 
87
70
 
88
71
  <script setup lang="ts">
89
- import { computed, ref } from 'vue';
72
+ import { computed } from 'vue';
90
73
  import { IconCopy, IconPencil } from '@iconify-prerendered/vue-lucide';
91
74
  import { Button } from '@/afcl';
92
75
  import TextRenderer from './TextRenderer.vue';
@@ -106,7 +89,6 @@
106
89
 
107
90
  const agentStore = useAgentStore();
108
91
  const { alert } = useAdminforth();
109
- const showEditButton = ref(false);
110
92
  // A user message is editable once it carries a turnId (loaded from history or stamped
111
93
  // after its turn finished). Steer sub-messages and other roles are never editable, and
112
94
  // we hide the affordance entirely while another edit or a live turn is in flight.
@@ -137,29 +119,26 @@
137
119
  const canCopy = computed(() =>
138
120
  Boolean(copyableText.value.trim()) && !agentStore.isEditingMessage
139
121
  );
140
- const showActionsBar = computed(() =>
141
- canEdit.value || (!isUserMessage.value && canCopy.value)
142
- );
143
-
144
122
  // While editing, hide only the *other* user messages of the edited turn (its steer
145
123
  // sub-messages); the edited message itself and all non-user parts stay visible.
146
124
  const shouldBeShownWhileEditing = computed(() =>
147
125
  !(isBeingEditedTurn.value && isUserMessage.value && !isBeingEditedMessage.value)
148
126
  );
149
127
 
128
+ // The row under the message is reserved by what the message is, not by hover or transient
129
+ // state (a turnId stamped after the turn, an edit in progress), so the buttons appearing
130
+ // never shift the chat or change its scroll height.
131
+ const reservesActionsRow = computed(() =>
132
+ shouldBeShownWhileEditing.value
133
+ && Boolean(copyableText.value.trim())
134
+ && (!isUserMessage.value || agentStore.editingEnabled)
135
+ );
136
+
150
137
  function checkIfMessageSystemMessage(message: IMessage): boolean {
151
138
  const isReserved = Object.values(RESERVED_SYSTEM_MESSAGE_CONTENT).includes(message as RESERVED_SYSTEM_MESSAGE_CONTENT);
152
139
  return isReserved;
153
140
  }
154
141
 
155
- function showEditButtonOnHover() {
156
- showEditButton.value = true;
157
- }
158
-
159
- function hideEditButtonOnHover() {
160
- showEditButton.value = false;
161
- }
162
-
163
142
  function copyMessageToClipboard() {
164
143
  navigator.clipboard.writeText(copyableText.value)
165
144
  .then(() => {
@@ -1,5 +1,5 @@
1
- import { MicVAD, utils } from "@ricky0123/vad-web";
2
-
1
+ // @ricky0123/vad-web brings onnxruntime-web (about 170 KB gzip): it loads when the microphone starts, not with the chat
2
+ let vad: typeof import("@ricky0123/vad-web") | null = null;
3
3
  let VADInstance: any = null;
4
4
  let recordedAudioChunks: Float32Array[] = [];
5
5
  let onVoiceStopCallback: () => void = () => {};
@@ -7,7 +7,8 @@ let onVoiceStartCallback: () => void = () => {};
7
7
  let onUpdateCallback: (amplitude: number) => void = () => {};
8
8
 
9
9
  async function createVADInstance(){
10
- VADInstance = await MicVAD.new({
10
+ vad = await import("@ricky0123/vad-web");
11
+ VADInstance = await vad.MicVAD.new({
11
12
  onFrameProcessed: ({ isSpeech }) => {
12
13
  onUpdateCallback(isSpeech);
13
14
  },
@@ -55,7 +56,8 @@ export async function getRecord() {
55
56
  offset += chunk.length;
56
57
  }
57
58
 
58
- const wavBuffer = utils.encodeWAV(mergedAudio, 1, 16000, 1, 16);
59
+ // chunks are recorded only by a started VAD, so the module is loaded here
60
+ const wavBuffer = vad!.utils.encodeWAV(mergedAudio, 1, 16000, 1, 16);
59
61
  const recordToReturn = new Blob([wavBuffer], { type: 'audio/wav' });
60
62
  recordedAudioChunks = [];
61
63
  return recordToReturn;
package/dist/index.js CHANGED
@@ -112,20 +112,6 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
112
112
  editingEnabled: Boolean(this.options.checkpointResource && this.options.turnResource.checkpointIdField),
113
113
  }
114
114
  });
115
- if (!this.adminforth.config.customization.customHeadItems) {
116
- this.adminforth.config.customization.customHeadItems = [];
117
- }
118
- this.adminforth.config.customization.customHeadItems.push({
119
- tagName: 'script',
120
- attributes: {
121
- src: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/ort.wasm.min.js'
122
- }
123
- }, {
124
- tagName: 'script',
125
- attributes: {
126
- src: 'https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.29/dist/bundle.min.js'
127
- },
128
- });
129
115
  if (!this.options.sessionResource) {
130
116
  throw new Error("sessionResource is required for AdminForthAgentPlugin");
131
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "3.1.2",
3
+ "version": "3.1.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",