@sveda-ai/vue 0.1.0 → 0.1.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/README.md +2 -0
- package/dist/appearance.d.ts +13 -0
- package/dist/appearance.d.ts.map +1 -1
- package/dist/components/chat/ChatInput.vue.d.ts.map +1 -1
- package/dist/components/shell/SvedaFrameTicks.vue.d.ts +3 -0
- package/dist/components/shell/SvedaFrameTicks.vue.d.ts.map +1 -0
- package/dist/components/shell/SvedaResizeHandles.vue.d.ts +2 -2
- package/dist/components/shell/SvedaToolbar.vue.d.ts +2 -2
- package/dist/composables/useSvedaChatLayout.d.ts +5 -5
- package/dist/composables/useSvedaChatLayout.d.ts.map +1 -1
- package/dist/composables/useSvedaChatPage.d.ts +2 -2
- package/dist/composables/useSvedaChatPage.d.ts.map +1 -1
- package/dist/composables/useSvedaMessaging.d.ts.map +1 -1
- package/dist/composables/useSvedaModel.d.ts.map +1 -1
- package/dist/composables/useSvedaShell.d.ts +2 -2
- package/dist/composables/useSvedaShell.d.ts.map +1 -1
- package/dist/composables/useSvedaStreaming.d.ts.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2755 -2547
- package/dist/lib/chatResize.d.ts +42 -0
- package/dist/lib/chatResize.d.ts.map +1 -0
- package/dist/lib/chatUiStorage.d.ts +2 -0
- package/dist/lib/chatUiStorage.d.ts.map +1 -1
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/styles.css +2 -4
- package/dist/vue.css +1 -1
- package/package.json +29 -18
- package/src/appearance.ts +147 -40
- package/src/components/chat/ChatHistoryDropdown.vue +6 -5
- package/src/components/chat/ChatInput.vue +8 -8
- package/src/components/chat/ChatMessageItem.vue +7 -7
- package/src/components/chat/ChatPendingIndicator.vue +1 -1
- package/src/components/shell/SvedaChat.vue +12 -9
- package/src/components/shell/SvedaFrameTicks.vue +18 -0
- package/src/components/shell/SvedaMinimizedTrigger.vue +2 -2
- package/src/components/shell/SvedaModelControls.vue +13 -3
- package/src/components/shell/SvedaModelSelect.vue +1 -1
- package/src/components/shell/SvedaResizeHandles.vue +8 -8
- package/src/components/shell/SvedaTabs.vue +3 -3
- package/src/components/shell/SvedaToolbar.vue +3 -3
- package/src/composables/useSvedaChatLayout.ts +203 -93
- package/src/composables/useSvedaChatPage.ts +4 -2
- package/src/composables/useSvedaMessaging.ts +12 -1
- package/src/composables/useSvedaModel.ts +3 -1
- package/src/composables/useSvedaShell.ts +12 -9
- package/src/composables/useSvedaStreaming.ts +9 -1
- package/src/index.ts +12 -0
- package/src/lib/chatResize.ts +123 -0
- package/src/lib/chatUiStorage.ts +46 -10
- package/src/plugin.ts +45 -1
- package/src/theme.css +56 -43
- package/src/theme.test.mjs +33 -1
- package/src/ui/button/index.ts +7 -7
- package/src/ui/card/Card.vue +1 -1
- package/src/ui/switch/Switch.vue +2 -2
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
import { useMediaQuery, useWindowSize } from '@vueuse/core';
|
|
2
2
|
import { computed, inject, onBeforeUnmount, onMounted, ref, watch, type ComputedRef, type Ref } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
applyFixedLeftResize,
|
|
5
|
+
applyFloatingResize,
|
|
6
|
+
pointerScreenDelta,
|
|
7
|
+
resolveEmbedHostSize,
|
|
8
|
+
SVEDA_CHAT_LAYOUT_MAX_HEIGHT,
|
|
9
|
+
SVEDA_CHAT_LAYOUT_MAX_WIDTH,
|
|
10
|
+
SVEDA_CHAT_LAYOUT_MIN_HEIGHT,
|
|
11
|
+
SVEDA_CHAT_LAYOUT_MIN_WIDTH,
|
|
12
|
+
SVEDA_HISTORY_SIDEBAR_WIDTH,
|
|
13
|
+
} from '../lib/chatResize';
|
|
3
14
|
import { SvedaFillHostKey, SvedaHostEmbedKey } from '../plugin';
|
|
4
15
|
|
|
5
16
|
const CHAT_STORAGE_KEY = 'sveda.chat-dimensions';
|
|
6
17
|
const VIEW_MODE_STORAGE_KEY = 'sveda.chat-view-mode';
|
|
7
18
|
const FIXED_WIDTH_STORAGE_KEY = 'sveda.chat-fixed-width';
|
|
8
19
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
export {
|
|
21
|
+
SVEDA_CHAT_LAYOUT_MIN_WIDTH,
|
|
22
|
+
SVEDA_CHAT_LAYOUT_MIN_HEIGHT,
|
|
23
|
+
SVEDA_CHAT_LAYOUT_MAX_WIDTH,
|
|
24
|
+
SVEDA_CHAT_LAYOUT_MAX_HEIGHT,
|
|
25
|
+
SVEDA_HISTORY_SIDEBAR_WIDTH,
|
|
26
|
+
resolveEmbedHostSize,
|
|
27
|
+
};
|
|
28
|
+
|
|
13
29
|
export const SVEDA_CHAT_MAIN_CONTENT_MIN_WIDTH = 768;
|
|
14
30
|
|
|
15
31
|
const MIN_WIDTH = SVEDA_CHAT_LAYOUT_MIN_WIDTH;
|
|
@@ -29,13 +45,17 @@ const IMMERSIVE_MODE_TRANSITION_MS = 300;
|
|
|
29
45
|
|
|
30
46
|
export type SvedaChatViewMode = 'floating' | 'fixed' | 'immersive';
|
|
31
47
|
|
|
32
|
-
export const useSvedaChatLayout = (
|
|
48
|
+
export const useSvedaChatLayout = (
|
|
49
|
+
isMinimized: ComputedRef<boolean>,
|
|
50
|
+
options?: { historySidebarVisible?: Ref<boolean> }
|
|
51
|
+
) => {
|
|
33
52
|
const hostEmbed = inject(SvedaHostEmbedKey, false);
|
|
34
53
|
const fillHost = inject(SvedaFillHostKey, false);
|
|
54
|
+
const historySidebarVisible = computed(() => Boolean(options?.historySidebarVisible?.value));
|
|
35
55
|
const isViewportMobile = useMediaQuery('(max-width: 768px)');
|
|
36
56
|
const { width: windowWidth, height: windowHeight } = useWindowSize();
|
|
37
57
|
|
|
38
|
-
const isMobile = computed(() => isViewportMobile.value);
|
|
58
|
+
const isMobile = computed(() => (hostEmbed ? false : isViewportMobile.value));
|
|
39
59
|
|
|
40
60
|
const chatWidth = ref(DEFAULT_WIDTH);
|
|
41
61
|
const chatHeight = ref(DEFAULT_HEIGHT);
|
|
@@ -134,13 +154,70 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
134
154
|
return undefined;
|
|
135
155
|
});
|
|
136
156
|
|
|
157
|
+
const embedSizeTargets = (): HTMLElement[] => {
|
|
158
|
+
const targets: HTMLElement[] = [document.documentElement];
|
|
159
|
+
document.querySelectorAll('sveda-chat').forEach(el => {
|
|
160
|
+
if (el instanceof HTMLElement) {
|
|
161
|
+
targets.push(el);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return targets;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const writeEmbedSizeVars = (size: { width: number; height: number } | null) => {
|
|
168
|
+
// Keep vars on <sveda-chat> too: Astro view transitions replace <html> attributes.
|
|
169
|
+
for (const el of embedSizeTargets()) {
|
|
170
|
+
if (size == null) {
|
|
171
|
+
el.style.removeProperty(EMBED_WIDTH_CSS_VAR);
|
|
172
|
+
el.style.removeProperty(EMBED_HEIGHT_CSS_VAR);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
el.style.setProperty(EMBED_WIDTH_CSS_VAR, `${size.width}px`);
|
|
176
|
+
el.style.setProperty(EMBED_HEIGHT_CSS_VAR, `${size.height}px`);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const syncEmbedHostAttributes = (size: { immersive: boolean; fixed: boolean }) => {
|
|
181
|
+
if (typeof document === 'undefined') {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
document.querySelectorAll('sveda-chat').forEach(el => {
|
|
186
|
+
if (size.immersive) {
|
|
187
|
+
el.setAttribute('data-sveda-immersive', 'true');
|
|
188
|
+
} else {
|
|
189
|
+
el.removeAttribute('data-sveda-immersive');
|
|
190
|
+
}
|
|
191
|
+
if (size.fixed) {
|
|
192
|
+
el.setAttribute('data-sveda-fixed', 'true');
|
|
193
|
+
} else {
|
|
194
|
+
el.removeAttribute('data-sveda-fixed');
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
137
199
|
const applyEmbedHostSize = () => {
|
|
138
200
|
if (typeof document === 'undefined' || !fillHost) {
|
|
139
201
|
return;
|
|
140
202
|
}
|
|
141
203
|
|
|
142
|
-
|
|
143
|
-
|
|
204
|
+
const size = resolveEmbedHostSize({
|
|
205
|
+
chatWidth: chatWidth.value,
|
|
206
|
+
chatHeight: chatHeight.value,
|
|
207
|
+
fixedWidth: fixedWidth.value,
|
|
208
|
+
historyOpen: historySidebarVisible.value && viewMode.value !== 'immersive' && !isMobile.value,
|
|
209
|
+
viewMode: isMinimized.value ? 'floating' : viewMode.value,
|
|
210
|
+
viewportWidth: typeof window === 'undefined' ? chatWidth.value : window.innerWidth,
|
|
211
|
+
viewportHeight: typeof window === 'undefined' ? chatHeight.value : window.innerHeight,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
writeEmbedSizeVars(size);
|
|
215
|
+
syncEmbedHostAttributes(size);
|
|
216
|
+
window.dispatchEvent(
|
|
217
|
+
new CustomEvent('sveda:embed-host-size', {
|
|
218
|
+
detail: size,
|
|
219
|
+
})
|
|
220
|
+
);
|
|
144
221
|
};
|
|
145
222
|
|
|
146
223
|
const clearEmbedHostSize = () => {
|
|
@@ -148,8 +225,8 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
148
225
|
return;
|
|
149
226
|
}
|
|
150
227
|
|
|
151
|
-
|
|
152
|
-
|
|
228
|
+
writeEmbedSizeVars(null);
|
|
229
|
+
syncEmbedHostAttributes({ immersive: false, fixed: false });
|
|
153
230
|
};
|
|
154
231
|
|
|
155
232
|
const loadChatDimensions = () => {
|
|
@@ -164,21 +241,19 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
164
241
|
console.warn('Failed to load chat dimensions:', error);
|
|
165
242
|
}
|
|
166
243
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
lastNonImmersiveViewMode.value = savedMode;
|
|
177
|
-
}
|
|
244
|
+
try {
|
|
245
|
+
const savedMode = localStorage.getItem(VIEW_MODE_STORAGE_KEY);
|
|
246
|
+
if (
|
|
247
|
+
savedMode &&
|
|
248
|
+
(savedMode === 'floating' || savedMode === 'fixed' || savedMode === 'immersive')
|
|
249
|
+
) {
|
|
250
|
+
viewMode.value = savedMode;
|
|
251
|
+
if (savedMode === 'floating' || savedMode === 'fixed') {
|
|
252
|
+
lastNonImmersiveViewMode.value = savedMode;
|
|
178
253
|
}
|
|
179
|
-
} catch (error) {
|
|
180
|
-
console.warn('Failed to load view mode:', error);
|
|
181
254
|
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.warn('Failed to load view mode:', error);
|
|
182
257
|
}
|
|
183
258
|
|
|
184
259
|
try {
|
|
@@ -213,10 +288,6 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
213
288
|
};
|
|
214
289
|
|
|
215
290
|
const saveViewMode = () => {
|
|
216
|
-
if (hostEmbed) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
291
|
try {
|
|
221
292
|
localStorage.setItem(VIEW_MODE_STORAGE_KEY, viewMode.value);
|
|
222
293
|
} catch (error) {
|
|
@@ -269,6 +340,11 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
269
340
|
}
|
|
270
341
|
};
|
|
271
342
|
|
|
343
|
+
const onHostDocumentSwap = () => {
|
|
344
|
+
applyEmbedHostSize();
|
|
345
|
+
updateBodyClass();
|
|
346
|
+
};
|
|
347
|
+
|
|
272
348
|
const toggleViewMode = () => {
|
|
273
349
|
if (viewMode.value === 'immersive') {
|
|
274
350
|
return;
|
|
@@ -325,73 +401,87 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
325
401
|
|
|
326
402
|
const pointerCaptureEl =
|
|
327
403
|
event.currentTarget instanceof HTMLElement ? event.currentTarget : null;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
} catch {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
404
|
+
const pointerId =
|
|
405
|
+
'pointerId' in event && Number.isFinite((event as PointerEvent).pointerId)
|
|
406
|
+
? (event as PointerEvent).pointerId
|
|
407
|
+
: null;
|
|
408
|
+
|
|
409
|
+
if (pointerCaptureEl && pointerId !== null) {
|
|
410
|
+
try {
|
|
411
|
+
pointerCaptureEl.setPointerCapture(pointerId);
|
|
412
|
+
} catch {
|
|
413
|
+
// Capture is best-effort so drag still works without it.
|
|
341
414
|
}
|
|
342
415
|
}
|
|
343
416
|
|
|
344
417
|
const releasePointerCaptureIfAny = () => {
|
|
345
|
-
if (
|
|
346
|
-
pointerCaptureEl &&
|
|
347
|
-
pointerCaptureId !== null &&
|
|
348
|
-
typeof pointerCaptureEl.releasePointerCapture === 'function'
|
|
349
|
-
) {
|
|
418
|
+
if (pointerCaptureEl && pointerId !== null) {
|
|
350
419
|
try {
|
|
351
|
-
pointerCaptureEl.releasePointerCapture(
|
|
420
|
+
pointerCaptureEl.releasePointerCapture(pointerId);
|
|
352
421
|
} catch {
|
|
353
|
-
pointerCaptureId = null;
|
|
354
422
|
return;
|
|
355
423
|
}
|
|
356
424
|
}
|
|
357
|
-
pointerCaptureId = null;
|
|
358
425
|
};
|
|
359
426
|
|
|
360
|
-
const startX = event.
|
|
361
|
-
const startY = event.
|
|
427
|
+
const startX = event.screenX;
|
|
428
|
+
const startY = event.screenY;
|
|
362
429
|
const startWidth = viewMode.value === 'fixed' ? fixedWidth.value : chatWidth.value;
|
|
363
430
|
const startHeight = chatHeight.value;
|
|
431
|
+
const moveEvent = pointerId !== null ? 'pointermove' : 'mousemove';
|
|
432
|
+
const upEvent = pointerId !== null ? 'pointerup' : 'mouseup';
|
|
433
|
+
let finished = false;
|
|
434
|
+
|
|
435
|
+
const stopListening = (move: (e: MouseEvent) => void, up: () => void) => {
|
|
436
|
+
window.removeEventListener(moveEvent, move);
|
|
437
|
+
window.removeEventListener(upEvent, up);
|
|
438
|
+
window.removeEventListener('pointercancel', up);
|
|
439
|
+
pointerCaptureEl?.removeEventListener('lostpointercapture', up);
|
|
440
|
+
};
|
|
364
441
|
|
|
365
442
|
if (viewMode.value === 'fixed' && direction === 'fixed-left') {
|
|
366
|
-
|
|
443
|
+
if (!fillHost) {
|
|
444
|
+
document.body.classList.add(FIXED_RESIZE_BODY_CLASS);
|
|
445
|
+
}
|
|
367
446
|
let dragFixedWidth = startWidth;
|
|
368
|
-
const reservePx =
|
|
447
|
+
const reservePx = fillHost
|
|
448
|
+
? historySidebarVisible.value
|
|
449
|
+
? SVEDA_HISTORY_SIDEBAR_WIDTH
|
|
450
|
+
: 0
|
|
451
|
+
: SVEDA_CHAT_MAIN_CONTENT_MIN_WIDTH;
|
|
369
452
|
const handleMouseMoveFixed = (e: MouseEvent) => {
|
|
370
453
|
if (!isResizing.value) return;
|
|
371
|
-
const deltaX = e
|
|
372
|
-
const
|
|
373
|
-
const
|
|
454
|
+
const { deltaX } = pointerScreenDelta(e, startX, startY);
|
|
455
|
+
const maxChat = Math.max(MIN_WIDTH, window.innerWidth - reservePx);
|
|
456
|
+
const result = applyFixedLeftResize(startWidth, deltaX, maxChat);
|
|
374
457
|
const endFixedResize = () => {
|
|
458
|
+
if (finished) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
finished = true;
|
|
375
462
|
releasePointerCaptureIfAny();
|
|
376
463
|
isResizing.value = false;
|
|
377
464
|
resizeDirection.value = null;
|
|
378
465
|
clearFixedResizeBodyClass();
|
|
379
466
|
saveFixedWidth();
|
|
380
|
-
|
|
381
|
-
document.removeEventListener('mouseup', handleMouseUpFixed);
|
|
467
|
+
stopListening(handleMouseMoveFixed, handleMouseUpFixed);
|
|
382
468
|
};
|
|
383
|
-
if (
|
|
384
|
-
dragFixedWidth =
|
|
385
|
-
fixedWidth.value =
|
|
469
|
+
if (result.enterImmersive) {
|
|
470
|
+
dragFixedWidth = result.width;
|
|
471
|
+
fixedWidth.value = result.width;
|
|
386
472
|
lastNonImmersiveViewMode.value = 'fixed';
|
|
387
|
-
|
|
473
|
+
if (!fillHost) {
|
|
474
|
+
applyChatWidthVar(result.width);
|
|
475
|
+
}
|
|
388
476
|
clearFixedResizeBodyClass();
|
|
389
477
|
isEnteringImmersiveFromDrag.value = true;
|
|
390
478
|
endFixedResize();
|
|
391
|
-
const targetW = typeof window !== 'undefined' ? window.innerWidth :
|
|
479
|
+
const targetW = typeof window !== 'undefined' ? window.innerWidth : result.width;
|
|
392
480
|
requestAnimationFrame(() => {
|
|
393
481
|
requestAnimationFrame(() => {
|
|
394
|
-
|
|
482
|
+
if (!fillHost) {
|
|
483
|
+
applyChatWidthVar(targetW);
|
|
484
|
+
}
|
|
395
485
|
});
|
|
396
486
|
});
|
|
397
487
|
clearImmersiveFromDragTimer();
|
|
@@ -404,12 +494,18 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
404
494
|
}, 320);
|
|
405
495
|
return;
|
|
406
496
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
497
|
+
dragFixedWidth = result.width;
|
|
498
|
+
fixedWidth.value = dragFixedWidth;
|
|
499
|
+
if (!fillHost) {
|
|
500
|
+
applyChatWidthVar(dragFixedWidth);
|
|
501
|
+
}
|
|
410
502
|
};
|
|
411
503
|
|
|
412
504
|
const handleMouseUpFixed = () => {
|
|
505
|
+
if (finished) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
finished = true;
|
|
413
509
|
releasePointerCaptureIfAny();
|
|
414
510
|
fixedWidth.value = dragFixedWidth;
|
|
415
511
|
isResizing.value = false;
|
|
@@ -417,56 +513,59 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
417
513
|
clearFixedResizeBodyClass();
|
|
418
514
|
saveFixedWidth();
|
|
419
515
|
updateBodyClass();
|
|
420
|
-
|
|
421
|
-
document.removeEventListener('mouseup', handleMouseUpFixed);
|
|
516
|
+
stopListening(handleMouseMoveFixed, handleMouseUpFixed);
|
|
422
517
|
};
|
|
423
518
|
|
|
424
|
-
|
|
425
|
-
|
|
519
|
+
window.addEventListener(moveEvent, handleMouseMoveFixed);
|
|
520
|
+
window.addEventListener(upEvent, handleMouseUpFixed);
|
|
521
|
+
window.addEventListener('pointercancel', handleMouseUpFixed);
|
|
522
|
+
pointerCaptureEl?.addEventListener('lostpointercapture', handleMouseUpFixed);
|
|
426
523
|
return;
|
|
427
524
|
}
|
|
428
525
|
|
|
429
526
|
const handleMouseMove = (e: MouseEvent) => {
|
|
430
|
-
if (!isResizing.value) return;
|
|
527
|
+
if (!isResizing.value || !resizeDirection.value) return;
|
|
431
528
|
|
|
432
|
-
const deltaX = e
|
|
433
|
-
const deltaY = e.clientY - startY;
|
|
529
|
+
const { deltaX, deltaY } = pointerScreenDelta(e, startX, startY);
|
|
434
530
|
|
|
435
|
-
if (viewMode.value === 'floating'
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (resizeDirection.value.includes('top')) {
|
|
446
|
-
chatHeight.value = Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, startHeight - deltaY));
|
|
447
|
-
}
|
|
531
|
+
if (viewMode.value === 'floating') {
|
|
532
|
+
const next = applyFloatingResize(
|
|
533
|
+
resizeDirection.value,
|
|
534
|
+
startWidth,
|
|
535
|
+
startHeight,
|
|
536
|
+
deltaX,
|
|
537
|
+
deltaY
|
|
538
|
+
);
|
|
539
|
+
chatWidth.value = next.width;
|
|
540
|
+
chatHeight.value = next.height;
|
|
448
541
|
}
|
|
449
542
|
};
|
|
450
543
|
|
|
451
544
|
const handleMouseUp = () => {
|
|
545
|
+
if (finished) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
finished = true;
|
|
452
549
|
releasePointerCaptureIfAny();
|
|
453
550
|
isResizing.value = false;
|
|
454
551
|
resizeDirection.value = null;
|
|
455
552
|
if (viewMode.value === 'floating') {
|
|
456
553
|
saveChatDimensions();
|
|
457
554
|
}
|
|
458
|
-
|
|
459
|
-
document.removeEventListener('mouseup', handleMouseUp);
|
|
555
|
+
stopListening(handleMouseMove, handleMouseUp);
|
|
460
556
|
};
|
|
461
557
|
|
|
462
|
-
|
|
463
|
-
|
|
558
|
+
window.addEventListener(moveEvent, handleMouseMove);
|
|
559
|
+
window.addEventListener(upEvent, handleMouseUp);
|
|
560
|
+
window.addEventListener('pointercancel', handleMouseUp);
|
|
561
|
+
pointerCaptureEl?.addEventListener('lostpointercapture', handleMouseUp);
|
|
464
562
|
};
|
|
465
563
|
|
|
466
564
|
if (typeof window !== 'undefined') {
|
|
467
565
|
loadChatDimensions();
|
|
468
566
|
updateBodyClass();
|
|
469
567
|
applyEmbedHostSize();
|
|
568
|
+
document.addEventListener('astro:after-swap', onHostDocumentSwap);
|
|
470
569
|
}
|
|
471
570
|
|
|
472
571
|
onMounted(() => {
|
|
@@ -475,6 +574,7 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
475
574
|
});
|
|
476
575
|
|
|
477
576
|
onBeforeUnmount(() => {
|
|
577
|
+
document.removeEventListener('astro:after-swap', onHostDocumentSwap);
|
|
478
578
|
clearImmersiveFromDragTimer();
|
|
479
579
|
finishImmersiveModeTransition();
|
|
480
580
|
isEnteringImmersiveFromDrag.value = false;
|
|
@@ -484,9 +584,19 @@ export const useSvedaChatLayout = (isMinimized: ComputedRef<boolean>) => {
|
|
|
484
584
|
clearEmbedHostSize();
|
|
485
585
|
});
|
|
486
586
|
|
|
487
|
-
watch(
|
|
488
|
-
|
|
489
|
-
|
|
587
|
+
watch(
|
|
588
|
+
[
|
|
589
|
+
chatWidth,
|
|
590
|
+
chatHeight,
|
|
591
|
+
fixedWidth,
|
|
592
|
+
historySidebarVisible,
|
|
593
|
+
() => viewMode.value,
|
|
594
|
+
() => isMinimized.value,
|
|
595
|
+
],
|
|
596
|
+
() => {
|
|
597
|
+
applyEmbedHostSize();
|
|
598
|
+
}
|
|
599
|
+
);
|
|
490
600
|
|
|
491
601
|
watch([maxFixedSplitWidth, () => viewMode.value, () => isMinimized.value], () => {
|
|
492
602
|
if (viewMode.value !== 'fixed' || isMinimized.value || isMobile.value) {
|
|
@@ -72,7 +72,10 @@ export function useSvedaChatPage(options: SvedaChatPageOptions, elementRefs: Sve
|
|
|
72
72
|
setLoading,
|
|
73
73
|
} = chatStore;
|
|
74
74
|
|
|
75
|
-
const
|
|
75
|
+
const showHistorySidebar = ref(false);
|
|
76
|
+
const layout = useSvedaChatLayout(isMinimized, {
|
|
77
|
+
historySidebarVisible: showHistorySidebar,
|
|
78
|
+
});
|
|
76
79
|
|
|
77
80
|
const model = useSvedaModel(options.models ?? computed(() => []));
|
|
78
81
|
const documents = useSvedaDocuments({
|
|
@@ -89,7 +92,6 @@ export function useSvedaChatPage(options: SvedaChatPageOptions, elementRefs: Sve
|
|
|
89
92
|
useSvedaAgentTasks({ subscribe: options.agentTasksSubscribe });
|
|
90
93
|
|
|
91
94
|
const { messagesContainerRef } = elementRefs;
|
|
92
|
-
const showHistorySidebar = ref(false);
|
|
93
95
|
|
|
94
96
|
const scrollBridge: {
|
|
95
97
|
scrollToBottom?: (options?: { behavior?: string; onlyIfNearBottom?: boolean }) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ref, type ComputedRef, type Ref } from 'vue';
|
|
1
|
+
import { inject, ref, type ComputedRef, type Ref } from 'vue';
|
|
2
|
+
import { SvedaBeforeSendKey } from '../plugin';
|
|
2
3
|
import type { SvedaExtractedDocumentItem } from './useSvedaDocuments';
|
|
3
4
|
|
|
4
5
|
type SendMessageStreaming = (
|
|
@@ -23,6 +24,7 @@ export function useSvedaMessaging(deps: {
|
|
|
23
24
|
}) {
|
|
24
25
|
const inputMessage = ref('');
|
|
25
26
|
const pendingChatFiles = ref<File[]>([]);
|
|
27
|
+
const beforeSend = inject(SvedaBeforeSendKey, null);
|
|
26
28
|
|
|
27
29
|
const sendMessage = async () => {
|
|
28
30
|
if (deps.isLoading.value || !deps.currentChat.value) {
|
|
@@ -34,6 +36,15 @@ export function useSvedaMessaging(deps: {
|
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
try {
|
|
40
|
+
deps.setLoading(true);
|
|
41
|
+
await beforeSend?.();
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
} finally {
|
|
45
|
+
deps.setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
deps.resetAgentCompletedNotice();
|
|
38
49
|
deps.resetMaxStepsContinueNotice?.(deps.currentChat.value?.id);
|
|
39
50
|
deps.clearAgentTasks?.();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SvedaSendOptions } from '@sveda-ai/core';
|
|
2
2
|
import { computed, ref, watch, type ComputedRef } from 'vue';
|
|
3
|
+
import { useSvedaChrome } from '../appearance';
|
|
3
4
|
import { useSvedaT } from '../i18n/index';
|
|
4
5
|
|
|
5
6
|
const SVEDA_CHAT_MODEL_STORAGE_KEY = 'sveda.chat-model';
|
|
@@ -13,6 +14,7 @@ export interface SvedaChatModelOption {
|
|
|
13
14
|
|
|
14
15
|
export function useSvedaModel(models: ComputedRef<SvedaChatModelOption[]>) {
|
|
15
16
|
const t = useSvedaT();
|
|
17
|
+
const chrome = useSvedaChrome();
|
|
16
18
|
|
|
17
19
|
const readStoredModel = (): string => {
|
|
18
20
|
if (typeof window === 'undefined') {
|
|
@@ -70,7 +72,7 @@ export function useSvedaModel(models: ComputedRef<SvedaChatModelOption[]>) {
|
|
|
70
72
|
const resolveStreamingSendOptions = (): Pick<SvedaSendOptions, 'model' | 'options'> => ({
|
|
71
73
|
model: selectedChatModel.value || undefined,
|
|
72
74
|
options: {
|
|
73
|
-
thinking: Boolean(selectedModelSupportsThinking.value && thinkingEnabled.value),
|
|
75
|
+
thinking: Boolean(chrome.thinking && selectedModelSupportsThinking.value && thinkingEnabled.value),
|
|
74
76
|
},
|
|
75
77
|
});
|
|
76
78
|
|
|
@@ -50,30 +50,33 @@ export function useSvedaShell(
|
|
|
50
50
|
return 'relative flex h-full min-h-0 min-w-0 flex-1 flex-row';
|
|
51
51
|
}
|
|
52
52
|
if (layout.fillHost) {
|
|
53
|
-
return 'flex h-full min-h-0 min-w-0 w-full flex-row items-stretch';
|
|
53
|
+
return 'relative flex h-full min-h-0 min-w-0 w-full flex-row items-stretch overflow-hidden';
|
|
54
54
|
}
|
|
55
|
-
return 'flex min-h-0 flex-row items-stretch gap-2';
|
|
55
|
+
return 'relative flex min-h-0 flex-row items-stretch gap-2';
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
const historyAsideSurfaceClass = computed(() => {
|
|
59
59
|
const base =
|
|
60
|
-
'sveda-chat-surface flex min-h-0 shrink-0 flex-col overflow-hidden bg-background';
|
|
60
|
+
'sveda-chat-surface flex min-h-0 w-80 shrink-0 flex-col overflow-hidden bg-background';
|
|
61
61
|
if (layout.isMobile.value) {
|
|
62
|
-
return `${base} h-full w-[
|
|
62
|
+
return `${base} h-full max-w-[88vw] border-r border-border`;
|
|
63
|
+
}
|
|
64
|
+
if (layout.fillHost) {
|
|
65
|
+
return `${base} h-full border-r border-border`;
|
|
63
66
|
}
|
|
64
67
|
if (layout.viewMode.value === 'fixed') {
|
|
65
|
-
return `${base} absolute right-full top-0 z-10 h-full
|
|
68
|
+
return `${base} absolute right-full top-0 z-10 h-full border-r border-border`;
|
|
66
69
|
}
|
|
67
|
-
return `${base} h-full
|
|
70
|
+
return `${base} h-full rounded-[var(--sveda-radius)] border border-border`;
|
|
68
71
|
});
|
|
69
72
|
|
|
70
73
|
const floatNonImmersiveShellStyle = computed(() => {
|
|
71
|
-
if (layout.isMobile.value || layout.viewMode.value !== 'floating') {
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
74
|
if (layout.fillHost) {
|
|
75
75
|
return { height: '100%', minHeight: 0 };
|
|
76
76
|
}
|
|
77
|
+
if (layout.isMobile.value || layout.viewMode.value !== 'floating') {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
77
80
|
return { height: `${layout.chatHeight.value}px`, minHeight: 0 };
|
|
78
81
|
});
|
|
79
82
|
|
|
@@ -10,7 +10,7 @@ import type { SvedaContextUsageEvent, SvedaMaxStepsEvent, SvedaToolProgressEvent
|
|
|
10
10
|
import { computed, inject, nextTick, onUnmounted, ref, watch, type Ref } from 'vue';
|
|
11
11
|
import { useSvedaT } from '../i18n/index';
|
|
12
12
|
import { deriveProvisionalChatTitle, isChatTitlePlaceholder } from '../lib/chatTitle';
|
|
13
|
-
import { SvedaClientKey } from '../plugin';
|
|
13
|
+
import { SvedaBeforeSendKey, SvedaClientKey } from '../plugin';
|
|
14
14
|
|
|
15
15
|
export interface SvedaStreamingStore {
|
|
16
16
|
currentChat: Ref<{
|
|
@@ -53,6 +53,7 @@ export function useSvedaStreaming(
|
|
|
53
53
|
if (!client) {
|
|
54
54
|
throw new Error('[sveda] useSvedaStreaming requires the Sveda plugin to be installed.');
|
|
55
55
|
}
|
|
56
|
+
const beforeSend = inject(SvedaBeforeSendKey, null);
|
|
56
57
|
|
|
57
58
|
const isThinking = ref(false);
|
|
58
59
|
const thinkingMessage = ref('');
|
|
@@ -327,6 +328,13 @@ export function useSvedaStreaming(
|
|
|
327
328
|
return;
|
|
328
329
|
}
|
|
329
330
|
|
|
331
|
+
try {
|
|
332
|
+
await beforeSend?.();
|
|
333
|
+
} catch (error) {
|
|
334
|
+
options.onError?.(store.currentChat.value.id, error);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
330
338
|
const chatId = store.currentChat.value.id;
|
|
331
339
|
applyProvisionalChatTitle(chatId, promptText || displayText);
|
|
332
340
|
const session = ensureSession(chatId);
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export {
|
|
|
10
10
|
SvedaHostEmbedKey,
|
|
11
11
|
SvedaFillHostKey,
|
|
12
12
|
SvedaHideLauncherKey,
|
|
13
|
+
SvedaBeforeSendKey,
|
|
13
14
|
} from './plugin';
|
|
14
15
|
export type {
|
|
15
16
|
SvedaPluginOptions,
|
|
@@ -18,6 +19,7 @@ export type {
|
|
|
18
19
|
SvedaBrand,
|
|
19
20
|
SvedaModelOption,
|
|
20
21
|
SvedaQuickPrompt,
|
|
22
|
+
SvedaBeforeSend,
|
|
21
23
|
} from './plugin';
|
|
22
24
|
|
|
23
25
|
export {
|
|
@@ -26,14 +28,19 @@ export {
|
|
|
26
28
|
formatRadiusPx,
|
|
27
29
|
hexToHsl,
|
|
28
30
|
hslToHex,
|
|
31
|
+
isSvedaAppearanceProvided,
|
|
29
32
|
isSvedaHsl,
|
|
33
|
+
mergeSvedaAppearance,
|
|
30
34
|
parseRadiusPx,
|
|
31
35
|
resolveSvedaAppearance,
|
|
36
|
+
sanitizeSvedaChrome,
|
|
32
37
|
sanitizeSvedaLauncher,
|
|
33
38
|
sanitizeSvedaLauncherImage,
|
|
34
39
|
sanitizeSvedaRadius,
|
|
35
40
|
sanitizeSvedaTheme,
|
|
41
|
+
useSvedaChrome,
|
|
36
42
|
useSvedaLauncher,
|
|
43
|
+
svedaChrome,
|
|
37
44
|
svedaLauncher,
|
|
38
45
|
SVEDA_APPEARANCE_PRESET_IDS,
|
|
39
46
|
SVEDA_APPEARANCE_PRESETS,
|
|
@@ -46,6 +53,7 @@ export {
|
|
|
46
53
|
} from './appearance';
|
|
47
54
|
export type {
|
|
48
55
|
SvedaAppearance,
|
|
56
|
+
SvedaAppearanceChrome,
|
|
49
57
|
SvedaAppearanceLauncher,
|
|
50
58
|
SvedaAppearancePresetId,
|
|
51
59
|
SvedaAppearanceTheme,
|
|
@@ -91,6 +99,8 @@ export {
|
|
|
91
99
|
SVEDA_CHAT_LAYOUT_MAX_WIDTH,
|
|
92
100
|
SVEDA_CHAT_LAYOUT_MAX_HEIGHT,
|
|
93
101
|
SVEDA_CHAT_MAIN_CONTENT_MIN_WIDTH,
|
|
102
|
+
SVEDA_HISTORY_SIDEBAR_WIDTH,
|
|
103
|
+
resolveEmbedHostSize,
|
|
94
104
|
} from './composables/useSvedaChatLayout';
|
|
95
105
|
export type { SvedaChatViewMode } from './composables/useSvedaChatLayout';
|
|
96
106
|
export { useSvedaAgentTasks } from './composables/useSvedaAgentTasks';
|
|
@@ -126,6 +136,8 @@ export { isChatTitlePlaceholder, deriveProvisionalChatTitle } from './lib/chatTi
|
|
|
126
136
|
export {
|
|
127
137
|
SVEDA_CHAT_MINIMIZED_STORAGE_KEY,
|
|
128
138
|
readPersistedMinimized,
|
|
139
|
+
readPersistedMinimizedPreference,
|
|
140
|
+
isPersistedSessionChatOpen,
|
|
129
141
|
writePersistedMinimized,
|
|
130
142
|
} from './lib/chatUiStorage';
|
|
131
143
|
export { humanizeModelId, getSvedaModelDisplayName } from './lib/modelLabels';
|