@widgetic/chat 0.1.6 → 0.1.8
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/dist/adapters/widgeticAdapter.js +2 -5
- package/dist/components/ActionBar.svelte +26 -47
- package/dist/components/ActionBar.svelte.d.ts +13 -24
- package/dist/components/AttachmentDisplay.svelte +16 -5
- package/dist/components/Chat.svelte +525 -213
- package/dist/components/Chat.svelte.d.ts +10 -1
- package/dist/components/ChatInput.svelte +155 -26
- package/dist/components/ChatInput.svelte.d.ts +11 -0
- package/dist/components/ChatMessages.svelte +274 -113
- package/dist/components/ChatMessages.svelte.d.ts +7 -1
- package/dist/components/CodeBlock.svelte +146 -19
- package/dist/components/SuggestionButtons.svelte +1 -1
- package/dist/services/chatService.js +11 -11
- package/dist/stores/chatStore.js +4 -6
- package/dist/utils/logger.js +2 -3
- package/package.json +7 -6
|
@@ -45,7 +45,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
import { chatLog } from '../utils/logger.js';
|
|
49
48
|
import { ContextType } from '../types/index.js';
|
|
50
49
|
/**
|
|
51
50
|
* Widgetic Canvas Platform Adapter
|
|
@@ -230,7 +229,7 @@ var WidgeticCanvasAdapter = /** @class */ (function () {
|
|
|
230
229
|
return __awaiter(this, void 0, Promise, function () {
|
|
231
230
|
return __generator(this, function (_a) {
|
|
232
231
|
try {
|
|
233
|
-
chatLog(
|
|
232
|
+
// chatLog(`Starting recording for frame: ${frameId}`);
|
|
234
233
|
// Implementation would integrate with the canvas recording system
|
|
235
234
|
// For now, just log the action
|
|
236
235
|
}
|
|
@@ -269,7 +268,7 @@ var WidgeticCanvasAdapter = /** @class */ (function () {
|
|
|
269
268
|
return __awaiter(this, void 0, Promise, function () {
|
|
270
269
|
return __generator(this, function (_a) {
|
|
271
270
|
// Implementation would stop the recording and return the video blob
|
|
272
|
-
chatLog('Stopping recording...');
|
|
271
|
+
// chatLog('Stopping recording...');
|
|
273
272
|
return [2 /*return*/, new Blob([], { type: 'video/webm' })];
|
|
274
273
|
});
|
|
275
274
|
});
|
|
@@ -552,7 +551,6 @@ var WidgeticCanvasAdapter = /** @class */ (function () {
|
|
|
552
551
|
var _this = this;
|
|
553
552
|
return __generator(this, function (_a) {
|
|
554
553
|
try {
|
|
555
|
-
chatLog("Enabling element selection for frame: ".concat(frameId));
|
|
556
554
|
frameElement = document.querySelector("[data-frame-id=\"".concat(frameId, "\"]"));
|
|
557
555
|
if (frameElement) {
|
|
558
556
|
frameElement.classList.add('element-selection-mode');
|
|
@@ -612,7 +610,6 @@ var WidgeticCanvasAdapter = /** @class */ (function () {
|
|
|
612
610
|
switch (_b.label) {
|
|
613
611
|
case 0:
|
|
614
612
|
_b.trys.push([0, 2, , 3]);
|
|
615
|
-
chatLog("Selected element ".concat(elementId, " in frame ").concat(frameId));
|
|
616
613
|
frameElement = document.querySelector("[data-frame-id=\"".concat(frameId, "\"]"));
|
|
617
614
|
if (frameElement) {
|
|
618
615
|
frameElement.querySelectorAll('.element-selected').forEach(function (el) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { createEventDispatcher } from 'svelte';
|
|
3
|
-
import { chatLog } from '../utils/logger.js';
|
|
4
2
|
import type { ChatContext } from '../types/context.js';
|
|
5
3
|
|
|
6
4
|
// Props
|
|
@@ -14,6 +12,12 @@
|
|
|
14
12
|
showRecord?: boolean;
|
|
15
13
|
showUpload?: boolean;
|
|
16
14
|
showComplete?: boolean;
|
|
15
|
+
onScreenshot?: () => void;
|
|
16
|
+
onUpload?: () => void;
|
|
17
|
+
onRecordStart?: () => void;
|
|
18
|
+
onRecordStop?: () => void;
|
|
19
|
+
onComplete?: (detail: { completed: boolean }) => void;
|
|
20
|
+
onError?: (detail: { type: string; error: unknown }) => void;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
let {
|
|
@@ -26,20 +30,23 @@
|
|
|
26
30
|
showRecord = true,
|
|
27
31
|
showUpload = true,
|
|
28
32
|
showComplete = true,
|
|
33
|
+
onScreenshot,
|
|
34
|
+
onUpload,
|
|
35
|
+
onRecordStart,
|
|
36
|
+
onRecordStop,
|
|
37
|
+
onComplete,
|
|
38
|
+
onError,
|
|
29
39
|
}: Props = $props();
|
|
30
40
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Handle screenshot capture
|
|
41
|
+
// Handle screenshot capture — attachments do not require an existing conversation.
|
|
34
42
|
async function handleScreenshot() {
|
|
35
|
-
if (disabled
|
|
43
|
+
if (disabled) return;
|
|
36
44
|
|
|
37
45
|
try {
|
|
38
|
-
|
|
39
|
-
dispatch('screenshot', { contextId: context.id });
|
|
46
|
+
onScreenshot?.();
|
|
40
47
|
} catch (error) {
|
|
41
48
|
console.error('Screenshot failed:', error);
|
|
42
|
-
|
|
49
|
+
onError?.({ type: 'screenshot', error });
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
|
|
@@ -49,56 +56,28 @@
|
|
|
49
56
|
|
|
50
57
|
try {
|
|
51
58
|
if (isRecording) {
|
|
52
|
-
|
|
53
|
-
dispatch('recordStop', { contextId: context.id });
|
|
59
|
+
onRecordStop?.();
|
|
54
60
|
} else {
|
|
55
|
-
|
|
56
|
-
dispatch('recordStart', { contextId: context.id });
|
|
61
|
+
onRecordStart?.();
|
|
57
62
|
}
|
|
58
63
|
} catch (error) {
|
|
59
64
|
console.error('Recording action failed:', error);
|
|
60
|
-
|
|
65
|
+
onError?.({ type: 'recording', error });
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
// Handle file upload
|
|
69
|
+
// Handle file upload — same as screenshot: works before conversation exists.
|
|
65
70
|
function handleUpload() {
|
|
66
|
-
if (disabled
|
|
71
|
+
if (disabled) return;
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
dispatch('upload');
|
|
73
|
+
onUpload?.();
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// Handle completion toggle
|
|
73
77
|
function handleCompletionToggle() {
|
|
74
78
|
if (disabled || !conversationId) return;
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
dispatch('complete', { completed: !isCompleted });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Get context-specific suggestions
|
|
81
|
-
function getContextSuggestions(): string[] {
|
|
82
|
-
switch (context.type) {
|
|
83
|
-
case 'frame':
|
|
84
|
-
return [
|
|
85
|
-
'Generate code from this design',
|
|
86
|
-
'Explain this component structure',
|
|
87
|
-
'Suggest improvements for this layout'
|
|
88
|
-
];
|
|
89
|
-
case 'text':
|
|
90
|
-
return [
|
|
91
|
-
'Help improve this writing',
|
|
92
|
-
'Check grammar and style',
|
|
93
|
-
'Suggest alternative phrasing'
|
|
94
|
-
];
|
|
95
|
-
default:
|
|
96
|
-
return [
|
|
97
|
-
'Ask a question about this content',
|
|
98
|
-
'Get suggestions for improvement',
|
|
99
|
-
'Explain what you see here'
|
|
100
|
-
];
|
|
101
|
-
}
|
|
80
|
+
onComplete?.({ completed: !isCompleted });
|
|
102
81
|
}
|
|
103
82
|
</script>
|
|
104
83
|
|
|
@@ -108,7 +87,7 @@
|
|
|
108
87
|
<button
|
|
109
88
|
class="action-button screenshot-button"
|
|
110
89
|
onclick={handleScreenshot}
|
|
111
|
-
disabled={disabled
|
|
90
|
+
disabled={disabled}
|
|
112
91
|
title="Take Screenshot"
|
|
113
92
|
aria-label="Take screenshot of current content"
|
|
114
93
|
>
|
|
@@ -151,7 +130,7 @@
|
|
|
151
130
|
<button
|
|
152
131
|
class="action-button upload-button"
|
|
153
132
|
onclick={handleUpload}
|
|
154
|
-
disabled={disabled
|
|
133
|
+
disabled={disabled}
|
|
155
134
|
title="Upload File"
|
|
156
135
|
aria-label="Upload file"
|
|
157
136
|
>
|
|
@@ -339,4 +318,4 @@
|
|
|
339
318
|
height: 1.5rem;
|
|
340
319
|
}
|
|
341
320
|
}
|
|
342
|
-
</style>
|
|
321
|
+
</style>
|
|
@@ -9,29 +9,18 @@ interface Props {
|
|
|
9
9
|
showRecord?: boolean;
|
|
10
10
|
showUpload?: boolean;
|
|
11
11
|
showComplete?: boolean;
|
|
12
|
+
onScreenshot?: () => void;
|
|
13
|
+
onUpload?: () => void;
|
|
14
|
+
onRecordStart?: () => void;
|
|
15
|
+
onRecordStop?: () => void;
|
|
16
|
+
onComplete?: (detail: {
|
|
17
|
+
completed: boolean;
|
|
18
|
+
}) => void;
|
|
19
|
+
onError?: (detail: {
|
|
20
|
+
type: string;
|
|
21
|
+
error: unknown;
|
|
22
|
+
}) => void;
|
|
12
23
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
$$bindings?: Bindings;
|
|
16
|
-
} & Exports;
|
|
17
|
-
(internal: unknown, props: Props & {
|
|
18
|
-
$$events?: Events;
|
|
19
|
-
$$slots?: Slots;
|
|
20
|
-
}): Exports & {
|
|
21
|
-
$set?: any;
|
|
22
|
-
$on?: any;
|
|
23
|
-
};
|
|
24
|
-
z_$$bindings?: Bindings;
|
|
25
|
-
}
|
|
26
|
-
declare const ActionBar: $$__sveltets_2_IsomorphicComponent<Props, {
|
|
27
|
-
screenshot: CustomEvent<any>;
|
|
28
|
-
error: CustomEvent<any>;
|
|
29
|
-
recordStop: CustomEvent<any>;
|
|
30
|
-
recordStart: CustomEvent<any>;
|
|
31
|
-
upload: CustomEvent<any>;
|
|
32
|
-
complete: CustomEvent<any>;
|
|
33
|
-
} & {
|
|
34
|
-
[evt: string]: CustomEvent<any>;
|
|
35
|
-
}, {}, {}, "">;
|
|
36
|
-
type ActionBar = InstanceType<typeof ActionBar>;
|
|
24
|
+
declare const ActionBar: import("svelte").Component<Props, {}, "">;
|
|
25
|
+
type ActionBar = ReturnType<typeof ActionBar>;
|
|
37
26
|
export default ActionBar;
|
|
@@ -39,8 +39,12 @@
|
|
|
39
39
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function isImageType(fileType: string): boolean {
|
|
43
|
-
|
|
42
|
+
function isImageType(fileType: string, url?: string): boolean {
|
|
43
|
+
if (fileType?.startsWith('image/')) return true;
|
|
44
|
+
if (typeof url === 'string' && (/^data:image\//i.test(url) || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(url))) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
function isVideoType(fileType: string): boolean {
|
|
@@ -68,6 +72,13 @@
|
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
function handleRemove(attachment: ContentItemOutput) {
|
|
75
|
+
if (attachment.url && attachment.url.startsWith('blob:')) {
|
|
76
|
+
try {
|
|
77
|
+
URL.revokeObjectURL(attachment.url);
|
|
78
|
+
} catch {
|
|
79
|
+
/* ignore error */
|
|
80
|
+
}
|
|
81
|
+
}
|
|
71
82
|
if (onRemove) {
|
|
72
83
|
onRemove(attachment);
|
|
73
84
|
}
|
|
@@ -94,7 +105,7 @@
|
|
|
94
105
|
<div class="message-attachments">
|
|
95
106
|
{#each displayedAttachments as attachment (attachment.id)}
|
|
96
107
|
<div class="message-attachment-item">
|
|
97
|
-
{#if isImageType(attachment.file_type) && showPreview}
|
|
108
|
+
{#if isImageType(attachment.file_type, attachment.url) && showPreview}
|
|
98
109
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
99
110
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
100
111
|
<img
|
|
@@ -144,7 +155,7 @@
|
|
|
144
155
|
<div class="preview-attachments">
|
|
145
156
|
{#each displayedAttachments as attachment (attachment.id)}
|
|
146
157
|
<div class="preview-attachment-item">
|
|
147
|
-
{#if isImageType(attachment.file_type) && showPreview}
|
|
158
|
+
{#if isImageType(attachment.file_type, attachment.url) && showPreview}
|
|
148
159
|
<div class="preview-image-container">
|
|
149
160
|
<img
|
|
150
161
|
src={attachment.url}
|
|
@@ -240,7 +251,7 @@
|
|
|
240
251
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
241
252
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
242
253
|
<div class="lightbox-content" onclick={(e) => e.stopPropagation()}>
|
|
243
|
-
{#if isImageType(lightboxAttachment.file_type)}
|
|
254
|
+
{#if isImageType(lightboxAttachment.file_type, lightboxAttachment.url)}
|
|
244
255
|
<img
|
|
245
256
|
src={lightboxAttachment.url}
|
|
246
257
|
alt={lightboxAttachment.file_name || 'Attachment'}
|