@adminforth/agent 3.3.0 → 3.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.
Files changed (38) hide show
  1. package/dist/application/runTurnUseCase.d.ts +5 -1
  2. package/dist/application/runTurnUseCase.js +41 -57
  3. package/dist/custom/ChatFooter.vue +76 -36
  4. package/dist/custom/ChatSurface.vue +64 -11
  5. package/dist/custom/ComposerAttachments.vue +36 -0
  6. package/dist/custom/composables/agentStore/constants.ts +13 -0
  7. package/dist/custom/composables/agentStore/useAgentAttachments.ts +163 -0
  8. package/dist/custom/composables/agentStore/useAgentChat.ts +19 -4
  9. package/dist/custom/composables/agentStore/useAgentSessions.ts +84 -20
  10. package/dist/custom/composables/useAgentStore.ts +67 -11
  11. package/dist/custom/conversation_area/MessageAttachments.vue +22 -0
  12. package/dist/custom/conversation_area/MessageRenderer.vue +15 -2
  13. package/dist/custom/types.ts +39 -0
  14. package/dist/custom/utils.ts +10 -0
  15. package/dist/domain/imageAttachments.d.ts +75 -0
  16. package/dist/domain/imageAttachments.js +71 -0
  17. package/dist/domain/turnTypes.d.ts +16 -0
  18. package/dist/index.d.ts +4 -2
  19. package/dist/index.js +30 -2
  20. package/dist/llm/agentRuntime.d.ts +14 -1
  21. package/dist/llm/agentRuntime.js +6 -1
  22. package/dist/llm/langGraphLlm.js +7 -1
  23. package/dist/llm/middleware/attachmentsMiddleware.d.ts +17 -0
  24. package/dist/llm/middleware/attachmentsMiddleware.js +148 -0
  25. package/dist/persistence/sessionStore.d.ts +11 -2
  26. package/dist/persistence/sessionStore.js +44 -9
  27. package/dist/persistence/turnAttachments.d.ts +41 -0
  28. package/dist/persistence/turnAttachments.js +112 -0
  29. package/dist/tools/navigateUser.d.ts +3 -3
  30. package/dist/tools/toolLabels.js +1 -0
  31. package/dist/tools/viewImage.d.ts +23 -0
  32. package/dist/tools/viewImage.js +108 -0
  33. package/dist/transport/http/context.d.ts +22 -3
  34. package/dist/transport/http/coreEndpoints.d.ts +36 -1
  35. package/dist/transport/http/coreEndpoints.js +104 -35
  36. package/dist/transport/http/sessionEndpoints.js +3 -4
  37. package/dist/types.d.ts +38 -0
  38. package/package.json +3 -3
@@ -1,5 +1,6 @@
1
1
  import { type AdminUser, type IAdminForth } from "adminforth";
2
2
  import type { AgentSessionStore } from "../persistence/sessionStore.js";
3
+ import type { TurnAttachments } from "../persistence/turnAttachments.js";
3
4
  import type { SteerBuffer } from "../domain/steerBuffer.js";
4
5
  import type { PluginOptions } from "../types.js";
5
6
  import type { LlmPort } from "./ports.js";
@@ -35,6 +36,7 @@ export declare function buildResumeValue(input: {
35
36
  export type RunTurnUseCaseDeps = {
36
37
  llm: LlmPort;
37
38
  sessions: AgentSessionStore;
39
+ attachments: TurnAttachments;
38
40
  /** Per-session buffer of mid-turn steering instructions; cleared when a turn ends unconsumed. */
39
41
  steerBuffer: SteerBuffer;
40
42
  modes: PluginOptions["modes"];
@@ -95,6 +97,8 @@ export declare class RunTurnUseCase {
95
97
  private handleInterrupt;
96
98
  private runAgentTurn;
97
99
  runAndPersistAgentResponse(input: RunAndPersistAgentResponseInput): Promise<RunAndPersistAgentResponseResult>;
100
+ /** Runs a turn on the event stream of the chat: turn-started, the turn itself, its result, finish. */
101
+ private runTurnWithEvents;
98
102
  handleTurn(input: HandleTurnInput): Promise<RunAndPersistAgentResponseResult>;
99
- handleEditTurn(input: HandleEditTurnInput): Promise<RunAndPersistAgentResponseResult>;
103
+ handleEditTurn({ turnId, ...input }: HandleEditTurnInput): Promise<RunAndPersistAgentResponseResult>;
100
104
  }
@@ -14,6 +14,17 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
14
14
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
15
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
16
  };
17
+ var __rest = (this && this.__rest) || function (s, e) {
18
+ var t = {};
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
20
+ t[p] = s[p];
21
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
22
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
23
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
24
+ t[p[i]] = s[p[i]];
25
+ }
26
+ return t;
27
+ };
17
28
  import { logger, Filters } from "adminforth";
18
29
  import { randomUUID } from "crypto";
19
30
  import { VegaLiteStreamBuffer } from "../domain/vegaLiteStreamBuffer.js";
@@ -169,6 +180,7 @@ export class RunTurnUseCase {
169
180
  */
170
181
  prepareEditTurn(input) {
171
182
  return __awaiter(this, void 0, void 0, function* () {
183
+ var _a;
172
184
  const sequenceDebugSink = this.deps.createDebugSink();
173
185
  const mode = this.resolveMode(input.modeName);
174
186
  const editTurnId = input.editTurnId;
@@ -180,6 +192,7 @@ export class RunTurnUseCase {
180
192
  if (targetIndex === -1) {
181
193
  throw new Error(`Turn "${editTurnId}" not found in session "${input.sessionId}".`);
182
194
  }
195
+ const attachments = yield this.deps.attachments.verify(input.sessionId, (_a = input.attachments) !== null && _a !== void 0 ? _a : [], agentTurns[targetIndex].attachments);
183
196
  const previous = agentTurns[targetIndex - 1];
184
197
  let branchFromCheckpointId;
185
198
  if (previous) {
@@ -208,10 +221,12 @@ export class RunTurnUseCase {
208
221
  sessionId: input.sessionId,
209
222
  turnId: editTurnId,
210
223
  newPrompt: input.prompt,
224
+ newAttachments: attachments,
211
225
  });
212
226
  yield this.deps.sessions.touchSession(input.sessionId);
213
227
  return {
214
228
  prompt: input.prompt,
229
+ attachments,
215
230
  sessionId: input.sessionId,
216
231
  turnId: editTurnId,
217
232
  previousUserMessages,
@@ -225,6 +240,7 @@ export class RunTurnUseCase {
225
240
  }
226
241
  prepareTurn(input) {
227
242
  return __awaiter(this, void 0, void 0, function* () {
243
+ var _a, _b;
228
244
  const sequenceDebugSink = this.deps.createDebugSink();
229
245
  const mode = this.resolveMode(input.modeName);
230
246
  const approvalDecision = getApprovalDecision(input);
@@ -236,6 +252,7 @@ export class RunTurnUseCase {
236
252
  return this.prepareEditTurn(input);
237
253
  }
238
254
  let turnId;
255
+ let attachments = [];
239
256
  let previousUserMessages = [];
240
257
  let initialResponse;
241
258
  let resume;
@@ -257,8 +274,13 @@ export class RunTurnUseCase {
257
274
  // the rejection. Reached whenever the approval UI is gone — after a page
258
275
  // reload, from a second tab, or from a chat surface.
259
276
  const pending = yield this.resolvePendingInterrupts(input.sessionId, mode, input.adminUser);
277
+ // The prompt rides along in the rejection of the pending call, which has no place for images.
278
+ if (pending.length > 0 && ((_a = input.attachments) === null || _a === void 0 ? void 0 : _a.length)) {
279
+ throw new Error("Answer the pending approval before sending images.");
280
+ }
281
+ attachments = yield this.deps.attachments.verify(input.sessionId, (_b = input.attachments) !== null && _b !== void 0 ? _b : []);
260
282
  previousUserMessages = yield this.deps.sessions.getPreviousUserMessages(input.sessionId);
261
- turnId = yield this.deps.sessions.createNewTurn(input.sessionId, input.prompt);
283
+ turnId = yield this.deps.sessions.createNewTurn(input.sessionId, input.prompt, attachments);
262
284
  yield this.deps.sessions.touchSession(input.sessionId);
263
285
  if (pending.length > 0) {
264
286
  resume = { decision: "reject", interrupts: pending };
@@ -266,6 +288,7 @@ export class RunTurnUseCase {
266
288
  }
267
289
  return {
268
290
  prompt: input.prompt,
291
+ attachments,
269
292
  sessionId: input.sessionId,
270
293
  turnId,
271
294
  previousUserMessages,
@@ -287,6 +310,10 @@ export class RunTurnUseCase {
287
310
  if (!prepared.freshPrompt) {
288
311
  return (_a = this.lastDetectedLanguage.get(prepared.sessionId)) !== null && _a !== void 0 ? _a : null;
289
312
  }
313
+ // an image-only message has no text to detect the language of, the default applies
314
+ if (!prepared.prompt) {
315
+ return null;
316
+ }
290
317
  const detected = yield this.deps.llm
291
318
  .detectLanguage({
292
319
  completionAdapter: prepared.mode.completionAdapter,
@@ -306,7 +333,7 @@ export class RunTurnUseCase {
306
333
  });
307
334
  }
308
335
  buildMessages(prepared) {
309
- return [{ role: "user", content: prepared.prompt }];
336
+ return [{ role: "user", content: prepared.prompt, attachments: prepared.attachments }];
310
337
  }
311
338
  handleInterrupt(prepared, interrupt, descriptors) {
312
339
  return __awaiter(this, void 0, void 0, function* () {
@@ -464,28 +491,14 @@ export class RunTurnUseCase {
464
491
  };
465
492
  });
466
493
  }
467
- handleTurn(input) {
494
+ /** Runs a turn on the event stream of the chat: turn-started, the turn itself, its result, finish. */
495
+ runTurnWithEvents(input) {
468
496
  return __awaiter(this, void 0, void 0, function* () {
469
- var _a, _b;
470
497
  yield input.emit({
471
498
  type: "turn-started",
472
499
  messageId: randomUUID(),
473
500
  });
474
- const agentResponse = yield this.runAndPersistAgentResponse({
475
- prompt: input.prompt,
476
- sessionId: input.sessionId,
477
- modeName: input.modeName,
478
- userTimeZone: input.userTimeZone,
479
- currentPage: input.currentPage,
480
- chatSurface: input.chatSurface,
481
- adminPublicOrigin: input.adminPublicOrigin,
482
- approvalDecision: input.approvalDecision,
483
- abortSignal: input.abortSignal,
484
- adminUser: input.adminUser,
485
- emit: input.emit,
486
- failureLogMessage: (_a = input.failureLogMessage) !== null && _a !== void 0 ? _a : "Agent response failed",
487
- abortLogMessage: (_b = input.abortLogMessage) !== null && _b !== void 0 ? _b : "Agent response aborted",
488
- });
501
+ const agentResponse = yield this.runAndPersistAgentResponse(input);
489
502
  if (agentResponse.failed) {
490
503
  yield input.emit({
491
504
  type: "error",
@@ -506,46 +519,17 @@ export class RunTurnUseCase {
506
519
  return agentResponse;
507
520
  });
508
521
  }
509
- handleEditTurn(input) {
522
+ handleTurn(input) {
510
523
  return __awaiter(this, void 0, void 0, function* () {
511
524
  var _a, _b;
512
- yield input.emit({
513
- type: "turn-started",
514
- messageId: randomUUID(),
515
- });
516
- const agentResponse = yield this.runAndPersistAgentResponse({
517
- prompt: input.prompt,
518
- sessionId: input.sessionId,
519
- modeName: input.modeName,
520
- userTimeZone: input.userTimeZone,
521
- currentPage: input.currentPage,
522
- chatSurface: input.chatSurface,
523
- adminPublicOrigin: input.adminPublicOrigin,
524
- editTurnId: input.turnId,
525
- abortSignal: input.abortSignal,
526
- adminUser: input.adminUser,
527
- emit: input.emit,
528
- failureLogMessage: (_a = input.failureLogMessage) !== null && _a !== void 0 ? _a : "Agent message edit failed",
529
- abortLogMessage: (_b = input.abortLogMessage) !== null && _b !== void 0 ? _b : "Agent message edit aborted",
530
- });
531
- if (agentResponse.failed) {
532
- yield input.emit({
533
- type: "error",
534
- error: agentResponse.text,
535
- });
536
- }
537
- else if (!agentResponse.aborted) {
538
- yield input.emit({
539
- type: "response",
540
- text: agentResponse.text,
541
- sessionId: input.sessionId,
542
- turnId: agentResponse.turnId,
543
- });
544
- }
545
- yield input.emit({
546
- type: "finish",
547
- });
548
- return agentResponse;
525
+ return this.runTurnWithEvents(Object.assign(Object.assign({}, input), { failureLogMessage: (_a = input.failureLogMessage) !== null && _a !== void 0 ? _a : "Agent response failed", abortLogMessage: (_b = input.abortLogMessage) !== null && _b !== void 0 ? _b : "Agent response aborted" }));
526
+ });
527
+ }
528
+ handleEditTurn(_a) {
529
+ return __awaiter(this, void 0, void 0, function* () {
530
+ var _b, _c;
531
+ var { turnId } = _a, input = __rest(_a, ["turnId"]);
532
+ return this.runTurnWithEvents(Object.assign(Object.assign({}, input), { editTurnId: turnId, failureLogMessage: (_b = input.failureLogMessage) !== null && _b !== void 0 ? _b : "Agent message edit failed", abortLogMessage: (_c = input.abortLogMessage) !== null && _c !== void 0 ? _c : "Agent message edit aborted" }));
549
533
  });
550
534
  }
551
535
  }
@@ -15,6 +15,7 @@
15
15
  dark:border-darkInputBorder dark:bg-darkInputBackground dark:hover:border-darkInputBorderHover
16
16
  dark:focus-within:border-darkInputFocusBorder dark:focus-within:ring-darkInputFocusRing"
17
17
  >
18
+ <ComposerAttachments v-if="!agentStore.isAudioChatMode" />
18
19
  <textarea
19
20
  v-if="!agentStore.isAudioChatMode"
20
21
  v-model="agentStore.userMessageInput"
@@ -30,44 +31,70 @@
30
31
  :placeholder="placeholderText"
31
32
  @keydown.enter.exact.prevent="sendMessage"
32
33
  @keydown.esc="onEscape"
34
+ @paste="onPaste"
33
35
  />
34
36
  <!-- in audio chat mode the voice button is centered between the mode picker and an empty column -->
35
37
  <div
36
38
  class="items-center gap-1 px-2 pb-2"
37
39
  :class="agentStore.isAudioChatMode ? 'grid grid-cols-[1fr_auto_1fr] pt-2' : 'flex pt-1'"
38
40
  >
39
- <DropdownMenu
40
- v-if="agentStore.availableModes.length > 1"
41
- v-model:open="isModeMenuOpen"
42
- class="af-agent-mode-menu justify-self-start"
43
- teleportToBody
44
- >
45
- <template #trigger="{ open }">
41
+ <div class="flex items-center gap-1 justify-self-start">
42
+ <template v-if="agentStore.canAttachImages">
46
43
  <Button
47
44
  variant="ghost"
48
45
  size="sm"
46
+ iconOnly
49
47
  type="button"
50
- :class="open && 'bg-lightSecondaryDarken text-lightInputText dark:bg-darkSecondaryLighten dark:text-darkInputText'"
51
- :aria-label="$t('Select mode')"
52
- :aria-expanded="open"
53
- :title="$t('Select mode')"
48
+ class="af-agent-attach-button"
49
+ :disabled="agentStore.isUploadingAttachments"
50
+ :title="$t('Attach image')"
51
+ :aria-label="$t('Attach image')"
52
+ @click="fileInput?.click()"
54
53
  >
55
- <IconSparkles class="w-4 h-4" />
56
- {{ agentStore.activeModeName }}
57
- <IconChevronDown class="w-3.5 h-3.5 transition-transform duration-200" :class="open && 'rotate-180'" />
54
+ <IconPaperclip />
58
55
  </Button>
56
+ <input
57
+ ref="fileInput"
58
+ type="file"
59
+ class="hidden"
60
+ multiple
61
+ :accept="acceptedImageTypes"
62
+ @change="onFilesPicked"
63
+ />
59
64
  </template>
60
- <DropdownMenuItem
61
- v-for="mode in agentStore.availableModes"
62
- :key="mode.name"
63
- @click="agentStore.setActiveMode(mode.name)"
65
+ <DropdownMenu
66
+ v-if="agentStore.availableModes.length > 1"
67
+ v-model:open="isModeMenuOpen"
68
+ class="af-agent-mode-menu"
69
+ teleportToBody
64
70
  >
65
- {{ mode.name }}
66
- <template v-if="mode.name === agentStore.activeModeName" #suffix>
67
- <IconCheck class="w-4 h-4 text-lightPrimary dark:text-darkPrimary" />
71
+ <template #trigger="{ open }">
72
+ <Button
73
+ variant="ghost"
74
+ size="sm"
75
+ type="button"
76
+ :class="open && 'bg-lightSecondaryDarken text-lightInputText dark:bg-darkSecondaryLighten dark:text-darkInputText'"
77
+ :aria-label="$t('Select mode')"
78
+ :aria-expanded="open"
79
+ :title="$t('Select mode')"
80
+ >
81
+ <IconSparkles class="w-4 h-4" />
82
+ {{ agentStore.activeModeName }}
83
+ <IconChevronDown class="w-3.5 h-3.5 transition-transform duration-200" :class="open && 'rotate-180'" />
84
+ </Button>
68
85
  </template>
69
- </DropdownMenuItem>
70
- </DropdownMenu>
86
+ <DropdownMenuItem
87
+ v-for="mode in agentStore.availableModes"
88
+ :key="mode.name"
89
+ @click="agentStore.setActiveMode(mode.name)"
90
+ >
91
+ {{ mode.name }}
92
+ <template v-if="mode.name === agentStore.activeModeName" #suffix>
93
+ <IconCheck class="w-4 h-4 text-lightPrimary dark:text-darkPrimary" />
94
+ </template>
95
+ </DropdownMenuItem>
96
+ </DropdownMenu>
97
+ </div>
71
98
  <div
72
99
  class="ml-auto flex items-center gap-1"
73
100
  :class="agentStore.isAudioChatMode ? 'col-start-2' : ''"
@@ -78,7 +105,7 @@
78
105
  <template v-if="!agentStore.isAudioChatMode">
79
106
  <EditActionButtons
80
107
  v-if="agentStore.isEditingMessage"
81
- :confirm-disabled="!agentStore.trimmedUserMessage"
108
+ :confirm-disabled="(!agentStore.trimmedUserMessage && !agentStore.attachments.length) || agentStore.isUploadingAttachments"
82
109
  @cancel="cancelEdit"
83
110
  @confirm="sendMessage"
84
111
  />
@@ -87,7 +114,7 @@
87
114
  type="button"
88
115
  iconOnly
89
116
  class="rounded-full"
90
- :disabled="!agentStore.trimmedUserMessage"
117
+ :disabled="!agentStore.canSubmitUserMessage"
91
118
  :title="$t('Send message')"
92
119
  :aria-label="$t('Send message')"
93
120
  @click="sendMessage"
@@ -113,7 +140,7 @@
113
140
  </template>
114
141
 
115
142
  <script setup lang="ts">
116
- import { IconArrowUp, IconCheck, IconChevronDown, IconSparkles } from '@iconify-prerendered/vue-lucide';
143
+ import { IconArrowUp, IconCheck, IconChevronDown, IconPaperclip, IconSparkles } from '@iconify-prerendered/vue-lucide';
117
144
  import { useTemplateRef, onMounted, ref, watch, computed } from 'vue';
118
145
  import { Button, DropdownMenu, DropdownMenuItem } from '@/afcl';
119
146
  import { useAgentStore } from './composables/useAgentStore';
@@ -123,23 +150,17 @@ import { remToPx } from './utils';
123
150
  import MicrophoneButton from './speech_recognition_frontend/MicrophoneButon.vue';
124
151
  import SteerQueue from './SteerQueue.vue';
125
152
  import EditActionButtons from './EditActionButtons.vue';
153
+ import ComposerAttachments from './ComposerAttachments.vue';
154
+ import type { IChatSurfaceMeta } from './types';
126
155
 
127
156
  const props = defineProps<{
128
- meta: {
129
- pluginInstanceId: string;
130
- modes: Array<{
131
- name: string;
132
- }>;
133
- defaultModeName: string | null;
134
- stickByDefault: boolean;
135
- hasAudioAdapter: boolean;
136
- editingEnabled: boolean;
137
- }
157
+ meta: IChatSurfaceMeta
138
158
  adminUser: any
139
159
  conversationAreaRef: any
140
160
  }>();
141
161
 
142
162
  const textInput = useTemplateRef('textInput');
163
+ const fileInput = useTemplateRef('fileInput');
143
164
  const agentStore = useAgentStore();
144
165
  const agentTransitions = useAgentTransitions();
145
166
  const coreStore = useCoreStore();
@@ -156,6 +177,7 @@ onMounted(async () => {
156
177
  agentStore.setAvailableModes(props.meta.modes, props.meta.defaultModeName);
157
178
  agentStore.setCurrentGenerationModeFromLocalStorage();
158
179
  agentStore.setEditingEnabled(props.meta.editingEnabled);
180
+ agentStore.setAttachmentsConfig(props.meta.attachments);
159
181
  textInput.value?.focus();
160
182
  autoResize();
161
183
  });
@@ -219,6 +241,24 @@ function onEscape(event: KeyboardEvent) {
219
241
  cancelEdit();
220
242
  }
221
243
 
244
+ const acceptedImageTypes = props.meta.attachments?.mimeTypes.join(',');
245
+
246
+ function onPaste(event: ClipboardEvent) {
247
+ const files = [...event.clipboardData!.files];
248
+ if (!agentStore.canAttachImages || files.length === 0) {
249
+ return;
250
+ }
251
+ event.preventDefault();
252
+ agentStore.addAttachmentFiles(files);
253
+ }
254
+
255
+ function onFilesPicked(event: Event) {
256
+ const input = event.target as HTMLInputElement;
257
+ agentStore.addAttachmentFiles([...input.files!]);
258
+ // picking the same file again must trigger `change` again
259
+ input.value = '';
260
+ }
261
+
222
262
  function stopCurrentRequest() {
223
263
  agentStore.abortCurrentChatRequestAndAddSystemMessage();
224
264
  }
@@ -16,7 +16,29 @@
16
16
  class="fixed top-0 right-0 z-40 flex h-screen border-l border-lightNavbarBorder bg-lightNavbar dark:border-darkNavbarBorder dark:bg-darkNavbar"
17
17
  :class="[agentStore.isChatOpen ? 'translate-x-0' : 'translate-x-full', !agentStore.isTeleportedToBody && !agentStore.isFullScreen ? 'shadow-popover dark:shadow-darkPopover' : '']"
18
18
  :style="{ width: agentStore.isFullScreen ? '100%' : agentStore.chatWidth + 'rem' }"
19
+ @dragenter="onFileDragEnter"
20
+ @dragover="onFileDragOver"
21
+ @dragleave="onFileDragLeave"
22
+ @drop="onFileDrop"
19
23
  >
24
+ <div
25
+ v-if="isDraggingFiles"
26
+ class="af-agent-drop-overlay pointer-events-none absolute inset-0 z-50 p-2 bg-lightNavbar dark:bg-darkNavbar"
27
+ >
28
+ <div
29
+ class="h-full flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed text-sm
30
+ border-lightDropzoneBorderDragging bg-lightDropzoneBackgroundDragging text-lightDropzoneIcon
31
+ dark:border-darkDropzoneBorderDragging dark:bg-darkDropzoneBackgroundDragging dark:text-darkDropzoneIcon"
32
+ >
33
+ <span
34
+ class="flex items-center justify-center w-9 h-9 rounded-lg border
35
+ border-lightDropzoneBorder bg-lightDropzoneBackgroundHover dark:border-darkDropzoneBorder dark:bg-darkDropzoneBackgroundHover"
36
+ >
37
+ <IconImagePlus class="w-5 h-5" />
38
+ </span>
39
+ {{ $t('Drop images to attach them') }}
40
+ </div>
41
+ </div>
20
42
  <div
21
43
  v-if="!(coreStore.isMobile || agentStore.isFullScreen)"
22
44
  class="w-2 cursor-ew-resize absolute left-0 h-full top-0 z-30"
@@ -50,7 +72,7 @@
50
72
  </template>
51
73
 
52
74
  <script setup lang="ts">
53
- import { IconBot } from '@iconify-prerendered/vue-lucide';
75
+ import { IconBot, IconImagePlus } from '@iconify-prerendered/vue-lucide';
54
76
  import { Button } from '@/afcl';
55
77
  import { useTemplateRef, onMounted, ref, onUnmounted, onBeforeUnmount, computed, watch, nextTick } from 'vue';
56
78
  import { onClickOutside } from '@vueuse/core'
@@ -60,19 +82,11 @@ import ChatFooter from './ChatFooter.vue';
60
82
  import { useAgentStore } from './composables/useAgentStore';
61
83
  import { useAgentTransitions } from './composables/useAgentTransitions';
62
84
  import { useCoreStore } from '@/stores/core';
85
+ import type { IChatSurfaceMeta } from './types';
63
86
  import { remToPx, getLayoutElements } from './utils';
64
87
 
65
88
  const props = defineProps<{
66
- meta: {
67
- pluginInstanceId: string;
68
- modes: Array<{
69
- name: string;
70
- }>;
71
- defaultModeName: string | null;
72
- stickByDefault: boolean;
73
- hasAudioAdapter: boolean;
74
- editingEnabled: boolean;
75
- }
89
+ meta: IChatSurfaceMeta
76
90
  adminUser: any
77
91
  }>();
78
92
 
@@ -168,4 +182,43 @@ function setLayoutPaddingRight(paddingRight: string) {
168
182
  }
169
183
  }
170
184
 
185
+
186
+ // Images can be dropped anywhere on the chat. A drop target has to cancel both dragenter and
187
+ // dragover: otherwise the browser takes the body as the target and opens the dropped file.
188
+ // dragenter and dragleave come for every element inside the chat the drag crosses, so the drag is
189
+ // over the chat while more of them were entered than left
190
+ const fileDragDepth = ref(0);
191
+ const isDraggingFiles = computed(() => fileDragDepth.value > 0);
192
+
193
+ function isFileDrag(event: DragEvent) {
194
+ return agentStore.canAttachImages && event.dataTransfer!.types.includes('Files');
195
+ }
196
+
197
+ function onFileDragEnter(event: DragEvent) {
198
+ if (isFileDrag(event)) {
199
+ event.preventDefault();
200
+ fileDragDepth.value += 1;
201
+ }
202
+ }
203
+
204
+ function onFileDragOver(event: DragEvent) {
205
+ if (isFileDrag(event)) {
206
+ event.preventDefault();
207
+ }
208
+ }
209
+
210
+ function onFileDragLeave(event: DragEvent) {
211
+ if (isFileDrag(event)) {
212
+ fileDragDepth.value -= 1;
213
+ }
214
+ }
215
+
216
+ function onFileDrop(event: DragEvent) {
217
+ fileDragDepth.value = 0;
218
+ if (!agentStore.canAttachImages || event.dataTransfer!.files.length === 0) {
219
+ return;
220
+ }
221
+ event.preventDefault();
222
+ agentStore.addAttachmentFiles([...event.dataTransfer!.files]);
223
+ }
171
224
  </script>
@@ -0,0 +1,36 @@
1
+ <template>
2
+ <div v-if="agentStore.attachments.length" class="af-agent-composer-attachments flex flex-wrap gap-2 px-3 pt-3">
3
+ <div
4
+ v-for="attachment in agentStore.attachments"
5
+ :key="attachment.id"
6
+ class="af-agent-composer-attachment relative"
7
+ >
8
+ <!-- natural proportions: a cropped square would be zoomed cropped too -->
9
+ <ZoomableImage
10
+ :src="attachment.url"
11
+ class="block max-h-14 max-w-28 rounded-default border border-lightInputBorder dark:border-darkInputBorder"
12
+ />
13
+ <Button
14
+ variant="secondary"
15
+ size="sm"
16
+ iconOnly
17
+ type="button"
18
+ class="af-agent-composer-attachment-remove absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full [&>svg]:w-3 [&>svg]:h-3"
19
+ :disabled="agentStore.isUploadingAttachments"
20
+ :title="$t('Remove image')"
21
+ :aria-label="$t('Remove image')"
22
+ @click="agentStore.removeAttachment(attachment.id)"
23
+ >
24
+ <IconX />
25
+ </Button>
26
+ </div>
27
+ </div>
28
+ </template>
29
+
30
+ <script setup lang="ts">
31
+ import { IconX } from '@iconify-prerendered/vue-lucide';
32
+ import { Button, ZoomableImage } from '@/afcl';
33
+ import { useAgentStore } from './composables/useAgentStore';
34
+
35
+ const agentStore = useAgentStore();
36
+ </script>
@@ -13,6 +13,19 @@ export const PLACEHOLDER_HOLD_DELAY_MS = 3000;
13
13
  export const PRE_SESSION_ID = 'pre-session';
14
14
  export const STEER_PERSIST_PREFIX = '__adminforth_steer__:';
15
15
 
16
+ // Full HD in any orientation: the long side up to 1920px, the short one up to 1080px.
17
+ export const MAX_IMAGE_LONG_SIDE = 1920;
18
+ export const MAX_IMAGE_SHORT_SIDE = 1080;
19
+ // A Full HD WebP or JPEG of this quality stays well under the size limit of the server (3.75 MB)
20
+ // even for a photo, which a PNG of the same size can exceed.
21
+ export const IMAGE_ENCODE_QUALITY = 0.85;
22
+ // images are uploaded as WebP, as JPEG from a browser which can not encode WebP (Safari)
23
+ export const IMAGE_UPLOAD_FORMAT = { type: 'image/webp', extension: 'webp' };
24
+ export const IMAGE_UPLOAD_FALLBACK_FORMAT = { type: 'image/jpeg', extension: 'jpg' };
25
+ // JPEG has no transparency, transparent pixels would turn black
26
+ export const IMAGE_UPLOAD_FALLBACK_BACKGROUND = '#fff';
27
+ export const ATTACHMENT_URLS_REFRESH_INTERVAL_MS = 60_000;
28
+
16
29
  export enum RESERVED_SYSTEM_MESSAGE_CONTENT {
17
30
  START_AUDIO_CHAT = 'START_AUDIO_CHAT',
18
31
  END_AUDIO_CHAT = 'END_AUDIO_CHAT',