context_drop 0.2.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/README.md +149 -12
- data/Rakefile +110 -1
- data/app/assets/javascripts/context_drop/context_drop.js +1759 -105
- data/app/controllers/context_drop/application_controller.rb +52 -3
- data/app/controllers/context_drop/configs_controller.rb +10 -1
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +99 -14
- data/app/controllers/context_drop/feedbacks_controller.rb +536 -17
- data/app/helpers/context_drop/dashboard_helper.rb +4 -0
- data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +355 -1
- data/app/javascript/context_drop/api-client.ts +343 -22
- data/app/javascript/context_drop/element-picker.ts +1 -1
- data/app/javascript/context_drop/icons.ts +6 -0
- data/app/javascript/context_drop/screenshot.ts +1 -1
- data/app/javascript/context_drop/styles.ts +311 -0
- data/app/javascript/context_drop/types.ts +141 -6
- data/app/javascript/context_drop/widget.ts +1072 -35
- data/app/models/context_drop/attachment.rb +5 -0
- data/app/models/context_drop/comment.rb +50 -0
- data/app/models/context_drop/feedback.rb +81 -11
- data/app/services/context_drop/ownership_token.rb +114 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +14 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +169 -2
- data/app/views/layouts/context_drop/application.html.erb +131 -7
- data/config/routes.rb +16 -1
- data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
- data/db/migrate/20261116000001_create_context_drop_comments_and_update_statuses.rb +44 -0
- data/lib/context_drop/agent/orchestrator.rb +1 -1
- data/lib/context_drop/configuration.rb +26 -0
- data/lib/context_drop/mcp/dispatcher.rb +2 -1
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +5 -3
- data/lib/context_drop/mcp/server.rb +1 -0
- data/lib/context_drop/mcp/tools/add_feedback_comment.rb +139 -0
- data/lib/context_drop/mcp/tools/get_feedback.rb +45 -6
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +3 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +23 -3
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +5 -3
- data/lib/context_drop/version.rb +1 -1
- metadata +7 -2
|
@@ -2,11 +2,18 @@ import type {
|
|
|
2
2
|
AgentChatMessage,
|
|
3
3
|
AgentProviderInfo,
|
|
4
4
|
AgentStatusResponse,
|
|
5
|
+
ContextDropApiClientOptions,
|
|
6
|
+
CreateCommentPayload,
|
|
5
7
|
CrossEnvFeedbackItem,
|
|
6
8
|
ElementReferenceSnapshot,
|
|
7
9
|
FeedbackSubmissionPayload,
|
|
10
|
+
FeedbackUpdatePayload,
|
|
11
|
+
OwnFeedbackRecord,
|
|
8
12
|
PendingAttachmentItem,
|
|
9
13
|
ProposedFileEdit,
|
|
14
|
+
SelectionMode,
|
|
15
|
+
SessionFeedbackAttachmentItem,
|
|
16
|
+
SessionFeedbackCommentItem,
|
|
10
17
|
SessionFeedbackEntry,
|
|
11
18
|
WidgetConfig,
|
|
12
19
|
WidgetPosition,
|
|
@@ -21,6 +28,8 @@ import {
|
|
|
21
28
|
ICON_CHEVRON_UP,
|
|
22
29
|
ICON_CLOSE,
|
|
23
30
|
ICON_CODE_PROMPT,
|
|
31
|
+
ICON_COMMENT,
|
|
32
|
+
ICON_EDIT,
|
|
24
33
|
ICON_EXPAND,
|
|
25
34
|
ICON_FILE_CODE,
|
|
26
35
|
ICON_GRIP,
|
|
@@ -37,6 +46,7 @@ import {
|
|
|
37
46
|
ICON_SIDEBAR,
|
|
38
47
|
ICON_SUN,
|
|
39
48
|
ICON_MOON,
|
|
49
|
+
ICON_TRASH,
|
|
40
50
|
ICON_UNDO
|
|
41
51
|
} from "./icons.ts";
|
|
42
52
|
import { WIDGET_SHADOW_STYLES } from "./styles.ts";
|
|
@@ -144,12 +154,24 @@ const BaseHTMLElement: typeof HTMLElement =
|
|
|
144
154
|
|
|
145
155
|
export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
146
156
|
public static get observedAttributes(): string[] {
|
|
147
|
-
return [
|
|
157
|
+
return [
|
|
158
|
+
"data-endpoint",
|
|
159
|
+
"data-position",
|
|
160
|
+
"data-placeholder",
|
|
161
|
+
"data-config",
|
|
162
|
+
"data-metadata",
|
|
163
|
+
"data-credentials",
|
|
164
|
+
"data-selection-mode",
|
|
165
|
+
"data-environment",
|
|
166
|
+
"data-theme",
|
|
167
|
+
"data-cd-theme"
|
|
168
|
+
];
|
|
148
169
|
}
|
|
149
170
|
|
|
150
171
|
public shadow: ShadowRoot | null = null;
|
|
151
172
|
private config: WidgetConfig = structuredClone(DEFAULT_CONFIG);
|
|
152
173
|
private customMetadata: Record<string, unknown> = {};
|
|
174
|
+
private customHeaders: Record<string, string> = {};
|
|
153
175
|
private apiClient: ContextDropApiClient = new ContextDropApiClient("/context_drop");
|
|
154
176
|
private picker: ElementPicker | null = null;
|
|
155
177
|
|
|
@@ -173,6 +195,19 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
173
195
|
private elementDomNodes: Map<string, Element> = new Map();
|
|
174
196
|
private attachments: PendingAttachmentItem[] = [];
|
|
175
197
|
private sessionHistory: SessionFeedbackEntry[] = [];
|
|
198
|
+
private ownFeedbacksLoaded: boolean = false;
|
|
199
|
+
private inFlightOwnFeedbacksPromise: Promise<SessionFeedbackEntry[]> | null = null;
|
|
200
|
+
private editingFeedbackId: string | null = null;
|
|
201
|
+
private commentingFeedbackId: string | null = null;
|
|
202
|
+
private reviewingFeedbackId: string | null = null;
|
|
203
|
+
private confirmingDeleteId: string | null = null;
|
|
204
|
+
private deletingFeedbackId: string | null = null;
|
|
205
|
+
private stashedDraftBeforeEdit: {
|
|
206
|
+
message: string;
|
|
207
|
+
elementReferences: ElementReferenceSnapshot[];
|
|
208
|
+
elementDomNodes: Map<string, Element>;
|
|
209
|
+
attachments: PendingAttachmentItem[];
|
|
210
|
+
} | null = null;
|
|
176
211
|
|
|
177
212
|
// Local Agent state
|
|
178
213
|
private agentStatusLoaded: boolean = false;
|
|
@@ -215,6 +250,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
215
250
|
private composerToolbarScreenshotBtn: HTMLButtonElement | null = null;
|
|
216
251
|
private composerToolbarUploadBtn: HTMLButtonElement | null = null;
|
|
217
252
|
private chatThreadEl: HTMLDivElement | null = null;
|
|
253
|
+
private editBannerEl: HTMLDivElement | null = null;
|
|
254
|
+
private editBannerInfoEl: HTMLSpanElement | null = null;
|
|
218
255
|
private textareaEl: HTMLTextAreaElement | null = null;
|
|
219
256
|
private trayEl: HTMLDivElement | null = null;
|
|
220
257
|
private statusEl: HTMLDivElement | null = null;
|
|
@@ -226,7 +263,6 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
226
263
|
private sidebarPinBtn: HTMLButtonElement | null = null;
|
|
227
264
|
private sidebarEnvPillEl: HTMLSpanElement | null = null;
|
|
228
265
|
private sidebarPushBtn: HTMLButtonElement | null = null;
|
|
229
|
-
private providerPillBtn: HTMLButtonElement | null = null;
|
|
230
266
|
private keyDotEl: HTMLSpanElement | null = null;
|
|
231
267
|
private providerPillLabelEl: HTMLSpanElement | null = null;
|
|
232
268
|
private keysToggleBtn: HTMLButtonElement | null = null;
|
|
@@ -260,6 +296,37 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
260
296
|
this.applyTheme(newValue, false);
|
|
261
297
|
} else if (name === "data-position" && newValue) {
|
|
262
298
|
this.setCornerPosition(newValue as WidgetPosition);
|
|
299
|
+
} else if (name === "data-endpoint" && newValue && this.shadow) {
|
|
300
|
+
this.setEndpoint(newValue);
|
|
301
|
+
} else if (name === "data-credentials" && newValue && this.shadow) {
|
|
302
|
+
if (newValue === "same-origin" || newValue === "include" || newValue === "omit") {
|
|
303
|
+
this.apiClient.setCredentials(newValue);
|
|
304
|
+
}
|
|
305
|
+
} else if (name === "data-placeholder" && newValue && this.shadow) {
|
|
306
|
+
this.setWidgetConfig({ placeholder: newValue });
|
|
307
|
+
} else if (name === "data-metadata" && this.shadow) {
|
|
308
|
+
if (newValue) {
|
|
309
|
+
try {
|
|
310
|
+
this.customMetadata = JSON.parse(newValue) as Record<string, unknown>;
|
|
311
|
+
} catch {
|
|
312
|
+
this.customMetadata = {};
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
this.customMetadata = {};
|
|
316
|
+
}
|
|
317
|
+
} else if (name === "data-selection-mode" && newValue && this.shadow) {
|
|
318
|
+
if (newValue === "smart" || newValue === "verbose") {
|
|
319
|
+
this.setWidgetConfig({ features: { ...this.config.features, selection_mode: newValue } });
|
|
320
|
+
}
|
|
321
|
+
} else if (name === "data-environment" && newValue && this.shadow) {
|
|
322
|
+
this.setWidgetConfig({ environment: newValue });
|
|
323
|
+
} else if (name === "data-config" && newValue && this.shadow) {
|
|
324
|
+
try {
|
|
325
|
+
const parsed = JSON.parse(newValue) as Partial<WidgetConfig>;
|
|
326
|
+
this.setWidgetConfig(parsed);
|
|
327
|
+
} catch {
|
|
328
|
+
// Ignore malformed JSON
|
|
329
|
+
}
|
|
263
330
|
}
|
|
264
331
|
}
|
|
265
332
|
|
|
@@ -300,6 +367,25 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
300
367
|
return;
|
|
301
368
|
}
|
|
302
369
|
|
|
370
|
+
if (
|
|
371
|
+
ev.key === "Escape" &&
|
|
372
|
+
!(this.picker && this.picker.isActive()) &&
|
|
373
|
+
this.isOpen &&
|
|
374
|
+
!this.isMinimized &&
|
|
375
|
+
!this.isAgentModeActive()
|
|
376
|
+
) {
|
|
377
|
+
if (this.confirmingDeleteId !== null) {
|
|
378
|
+
ev.preventDefault();
|
|
379
|
+
this.cancelDeleteFeedback();
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (this.editingFeedbackId !== null) {
|
|
383
|
+
ev.preventDefault();
|
|
384
|
+
this.cancelEditingFeedback();
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
303
389
|
// Alt+Shift+P / Option+Shift+P toggles Freeze & Pin mode in technical/verbose environments
|
|
304
390
|
if (
|
|
305
391
|
!this.isSmartSelectionMode() &&
|
|
@@ -414,6 +500,51 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
414
500
|
return this.config;
|
|
415
501
|
}
|
|
416
502
|
|
|
503
|
+
public setEndpoint(endpoint: string, options: ContextDropApiClientOptions = {}): void {
|
|
504
|
+
const resolvedCredentials =
|
|
505
|
+
options.credentials ||
|
|
506
|
+
(this.getAttribute("data-credentials") as RequestCredentials | null) ||
|
|
507
|
+
"same-origin";
|
|
508
|
+
const resolvedHeaders = options.headers || this.customHeaders;
|
|
509
|
+
this.customHeaders = { ...resolvedHeaders };
|
|
510
|
+
this.ownFeedbacksLoaded = false;
|
|
511
|
+
this.inFlightOwnFeedbacksPromise = null;
|
|
512
|
+
this.apiClient = new ContextDropApiClient(endpoint || "/context_drop", {
|
|
513
|
+
credentials: resolvedCredentials,
|
|
514
|
+
headers: this.customHeaders
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
public setHeaders(headers: Record<string, string>): void {
|
|
519
|
+
this.customHeaders = { ...headers };
|
|
520
|
+
this.apiClient.setHeaders(this.customHeaders);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
public setCredentials(credentials: RequestCredentials): void {
|
|
524
|
+
this.apiClient.setCredentials(credentials);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
public setCustomMetadata(metadata: Record<string, unknown>): void {
|
|
528
|
+
this.customMetadata = { ...metadata };
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
private emitWidgetEvent(name: string, detail?: Record<string, unknown>): void {
|
|
532
|
+
if (typeof CustomEvent !== "function" || typeof this.dispatchEvent !== "function") {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
this.dispatchEvent(
|
|
537
|
+
new CustomEvent(name, {
|
|
538
|
+
bubbles: true,
|
|
539
|
+
composed: true,
|
|
540
|
+
detail
|
|
541
|
+
})
|
|
542
|
+
);
|
|
543
|
+
} catch {
|
|
544
|
+
// Non-fatal in synthetic DOM environments
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
417
548
|
public setWidgetConfig(partial: Partial<WidgetConfig>): void {
|
|
418
549
|
const wasAgentEnabled = Boolean(this.config.agent?.enabled);
|
|
419
550
|
if (
|
|
@@ -460,8 +591,12 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
460
591
|
return;
|
|
461
592
|
}
|
|
462
593
|
this.surfaceMode = mode;
|
|
463
|
-
if (
|
|
464
|
-
|
|
594
|
+
if (this.isOpen) {
|
|
595
|
+
if (mode === "agent") {
|
|
596
|
+
void this.ensureAgentStatusLoaded();
|
|
597
|
+
} else if (!this.isMinimized) {
|
|
598
|
+
void this.ensureOwnFeedbacksLoaded();
|
|
599
|
+
}
|
|
465
600
|
}
|
|
466
601
|
this.renderTray();
|
|
467
602
|
this.renderChatThread();
|
|
@@ -481,6 +616,423 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
481
616
|
return [...this.sessionHistory];
|
|
482
617
|
}
|
|
483
618
|
|
|
619
|
+
public getEditingFeedbackId(): string | null {
|
|
620
|
+
return this.editingFeedbackId;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
private formatTimestampLabel(isoOrLabel?: string): string {
|
|
624
|
+
if (isoOrLabel && /^\d{2}:\d{2}$/.test(isoOrLabel.trim())) {
|
|
625
|
+
return isoOrLabel.trim();
|
|
626
|
+
}
|
|
627
|
+
const parsed = isoOrLabel ? new Date(isoOrLabel) : new Date();
|
|
628
|
+
const valid = Number.isNaN(parsed.getTime()) ? new Date() : parsed;
|
|
629
|
+
return `${String(valid.getHours()).padStart(2, "0")}:${String(valid.getMinutes()).padStart(2, "0")}`;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private mapOwnRecordToSessionEntry(
|
|
633
|
+
record: OwnFeedbackRecord,
|
|
634
|
+
existingEntry?: SessionFeedbackEntry
|
|
635
|
+
): SessionFeedbackEntry {
|
|
636
|
+
const smartMode = this.isSmartSelectionMode();
|
|
637
|
+
const rawMessage = typeof record.message === "string" ? record.message : "";
|
|
638
|
+
const displayMessage =
|
|
639
|
+
rawMessage || (smartMode ? "(Highlighted page area)" : "(Context drop without text)");
|
|
640
|
+
const token =
|
|
641
|
+
record.ownership_token ||
|
|
642
|
+
existingEntry?.ownershipToken ||
|
|
643
|
+
this.apiClient.getOwnershipToken(record.id) ||
|
|
644
|
+
undefined;
|
|
645
|
+
const isEdited = Boolean(
|
|
646
|
+
record.created_at && record.updated_at && record.updated_at !== record.created_at
|
|
647
|
+
);
|
|
648
|
+
|
|
649
|
+
const serverAttachments = Array.isArray(record.attachments) ? record.attachments : [];
|
|
650
|
+
const mappedAttachments: SessionFeedbackAttachmentItem[] = serverAttachments.map((att, idx) => {
|
|
651
|
+
const existingAtt = existingEntry?.attachments.find(
|
|
652
|
+
(a) =>
|
|
653
|
+
(a.server_id !== undefined && String(a.server_id) === String(att.id)) ||
|
|
654
|
+
(a.server_id === undefined &&
|
|
655
|
+
idx < (existingEntry?.attachments.length || 0) &&
|
|
656
|
+
existingEntry?.attachments[idx]?.filename === att.filename)
|
|
657
|
+
);
|
|
658
|
+
|
|
659
|
+
const previewUrl =
|
|
660
|
+
existingAtt?.preview_url &&
|
|
661
|
+
(existingAtt.preview_url.startsWith("data:") || existingAtt.preview_url.startsWith("blob:"))
|
|
662
|
+
? existingAtt.preview_url
|
|
663
|
+
: this.apiClient.buildAttachmentPreviewUrl(record.id, att.id, token);
|
|
664
|
+
|
|
665
|
+
const meta =
|
|
666
|
+
att.metadata && typeof att.metadata === "object" && !Array.isArray(att.metadata)
|
|
667
|
+
? { ...att.metadata }
|
|
668
|
+
: existingAtt?.metadata
|
|
669
|
+
? { ...existingAtt.metadata }
|
|
670
|
+
: {};
|
|
671
|
+
|
|
672
|
+
let label = existingAtt?.label || "";
|
|
673
|
+
if (!label) {
|
|
674
|
+
if (meta.auto_smart_context === true && typeof meta.friendly_label === "string") {
|
|
675
|
+
label = `Context around ${meta.friendly_label}`;
|
|
676
|
+
} else if (att.filename) {
|
|
677
|
+
label = att.filename;
|
|
678
|
+
} else {
|
|
679
|
+
label = att.attachment_type === "screenshot" ? "Screenshot" : "Attached image";
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return {
|
|
684
|
+
id: existingAtt?.id || `srv_att_${record.id}_${att.id}`,
|
|
685
|
+
server_id: att.id,
|
|
686
|
+
label,
|
|
687
|
+
preview_url: previewUrl,
|
|
688
|
+
attachment_type: att.attachment_type === "screenshot" ? "screenshot" : "image",
|
|
689
|
+
filename: att.filename,
|
|
690
|
+
element_reference_ref: att.element_reference_ref ?? existingAtt?.element_reference_ref ?? null,
|
|
691
|
+
metadata: meta
|
|
692
|
+
};
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
const elements = Array.isArray(record.element_references)
|
|
696
|
+
? structuredClone(record.element_references)
|
|
697
|
+
: existingEntry?.elements
|
|
698
|
+
? structuredClone(existingEntry.elements)
|
|
699
|
+
: [];
|
|
700
|
+
|
|
701
|
+
const mappedComments: SessionFeedbackCommentItem[] = Array.isArray(record.comments)
|
|
702
|
+
? record.comments.map((c) => ({
|
|
703
|
+
id: c.id,
|
|
704
|
+
author_label: c.author_label || "You",
|
|
705
|
+
author_type: c.author_type ?? null,
|
|
706
|
+
body: c.body ?? null,
|
|
707
|
+
createdAt: this.formatTimestampLabel(c.created_at),
|
|
708
|
+
rawCreatedAt: c.created_at,
|
|
709
|
+
attachments: Array.isArray(c.attachments)
|
|
710
|
+
? c.attachments.map((att) => ({
|
|
711
|
+
id: `srv-catt-${att.id}`,
|
|
712
|
+
server_id: att.id,
|
|
713
|
+
label: att.filename || "image.png",
|
|
714
|
+
preview_url: this.apiClient.buildAttachmentPreviewUrl(record.id, att.id, token),
|
|
715
|
+
attachment_type: att.attachment_type || "image",
|
|
716
|
+
filename: att.filename,
|
|
717
|
+
metadata: att.metadata || {}
|
|
718
|
+
}))
|
|
719
|
+
: []
|
|
720
|
+
}))
|
|
721
|
+
: existingEntry?.comments
|
|
722
|
+
? structuredClone(existingEntry.comments)
|
|
723
|
+
: [];
|
|
724
|
+
|
|
725
|
+
return {
|
|
726
|
+
id: record.id,
|
|
727
|
+
message: displayMessage,
|
|
728
|
+
rawMessage,
|
|
729
|
+
createdAt: this.formatTimestampLabel(record.created_at || existingEntry?.rawCreatedAt),
|
|
730
|
+
rawCreatedAt: record.created_at,
|
|
731
|
+
rawUpdatedAt: record.updated_at,
|
|
732
|
+
isEdited: isEdited || Boolean(existingEntry?.isEdited),
|
|
733
|
+
status: record.status,
|
|
734
|
+
ownershipToken: token,
|
|
735
|
+
elements,
|
|
736
|
+
attachments: mappedAttachments,
|
|
737
|
+
comments: mappedComments
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
public async refreshOwnFeedbacks(): Promise<SessionFeedbackEntry[]> {
|
|
742
|
+
if (typeof fetch !== "function") {
|
|
743
|
+
return [...this.sessionHistory];
|
|
744
|
+
}
|
|
745
|
+
if (this.inFlightOwnFeedbacksPromise) {
|
|
746
|
+
return this.inFlightOwnFeedbacksPromise;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
this.inFlightOwnFeedbacksPromise = (async () => {
|
|
750
|
+
try {
|
|
751
|
+
const res = await this.apiClient.fetchOwnFeedbacks();
|
|
752
|
+
this.ownFeedbacksLoaded = true;
|
|
753
|
+
const records = Array.isArray(res?.feedbacks) ? res.feedbacks : [];
|
|
754
|
+
if (records.length === 0) {
|
|
755
|
+
return [...this.sessionHistory];
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const existingById = new Map<string, SessionFeedbackEntry>();
|
|
759
|
+
for (const entry of this.sessionHistory) {
|
|
760
|
+
existingById.set(String(entry.id), entry);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
const chronologicalServerRecords = [...records].reverse();
|
|
764
|
+
const serverIds = new Set<string>();
|
|
765
|
+
const merged: SessionFeedbackEntry[] = [];
|
|
766
|
+
|
|
767
|
+
for (const record of chronologicalServerRecords) {
|
|
768
|
+
if (!record || record.id === undefined || record.id === null) continue;
|
|
769
|
+
const idKey = String(record.id);
|
|
770
|
+
serverIds.add(idKey);
|
|
771
|
+
merged.push(this.mapOwnRecordToSessionEntry(record, existingById.get(idKey)));
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
for (const localEntry of this.sessionHistory) {
|
|
775
|
+
if (!serverIds.has(String(localEntry.id))) {
|
|
776
|
+
merged.push(localEntry);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
this.sessionHistory = merged;
|
|
781
|
+
this.renderChatThread();
|
|
782
|
+
this.syncUiStates();
|
|
783
|
+
} catch {
|
|
784
|
+
// Non-fatal when offline or using minimal synthetic endpoints
|
|
785
|
+
} finally {
|
|
786
|
+
this.inFlightOwnFeedbacksPromise = null;
|
|
787
|
+
}
|
|
788
|
+
return [...this.sessionHistory];
|
|
789
|
+
})();
|
|
790
|
+
|
|
791
|
+
return this.inFlightOwnFeedbacksPromise;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
private async ensureOwnFeedbacksLoaded(): Promise<void> {
|
|
795
|
+
if (this.ownFeedbacksLoaded) return;
|
|
796
|
+
await this.refreshOwnFeedbacks();
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
public startEditingFeedback(feedbackId: number | string): boolean {
|
|
800
|
+
const targetKey = String(feedbackId);
|
|
801
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
802
|
+
if (!entry) return false;
|
|
803
|
+
|
|
804
|
+
if (this.commentingFeedbackId !== null) {
|
|
805
|
+
this.cancelCommentingFeedback();
|
|
806
|
+
}
|
|
807
|
+
this.confirmingDeleteId = null;
|
|
808
|
+
this.hideStatus();
|
|
809
|
+
|
|
810
|
+
if (this.editingFeedbackId === null && this.commentingFeedbackId === null) {
|
|
811
|
+
this.stashedDraftBeforeEdit = {
|
|
812
|
+
message: this.textareaEl?.value || "",
|
|
813
|
+
elementReferences: [...this.elementReferences],
|
|
814
|
+
elementDomNodes: new Map(this.elementDomNodes),
|
|
815
|
+
attachments: [...this.attachments]
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
this.editingFeedbackId = targetKey;
|
|
820
|
+
|
|
821
|
+
if (this.textareaEl) {
|
|
822
|
+
this.textareaEl.value = entry.rawMessage !== undefined ? entry.rawMessage : entry.message;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
this.elementReferences = structuredClone(entry.elements);
|
|
826
|
+
this.elementDomNodes.clear();
|
|
827
|
+
if (typeof document !== "undefined" && typeof document.querySelector === "function") {
|
|
828
|
+
for (const elRef of this.elementReferences) {
|
|
829
|
+
if (!elRef.selector) continue;
|
|
830
|
+
try {
|
|
831
|
+
const liveNode = document.querySelector(elRef.selector);
|
|
832
|
+
if (liveNode) {
|
|
833
|
+
this.elementDomNodes.set(elRef.client_ref, liveNode);
|
|
834
|
+
}
|
|
835
|
+
} catch {
|
|
836
|
+
// Ignore invalid or complex selectors not resolvable on current page
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
this.attachments = entry.attachments.map((att) => ({
|
|
842
|
+
id: att.id,
|
|
843
|
+
existing_attachment_id: att.server_id,
|
|
844
|
+
attachment_type: att.attachment_type,
|
|
845
|
+
label: att.label,
|
|
846
|
+
preview_url: att.preview_url,
|
|
847
|
+
signed_blob_id: att.signed_blob_id,
|
|
848
|
+
data_url: att.data_url,
|
|
849
|
+
filename: att.filename || att.label || "attachment.png",
|
|
850
|
+
element_reference_ref: att.element_reference_ref || undefined,
|
|
851
|
+
metadata: att.metadata ? structuredClone(att.metadata) : {}
|
|
852
|
+
}));
|
|
853
|
+
|
|
854
|
+
this.picker?.refreshPinnedMarkers();
|
|
855
|
+
this.renderTray();
|
|
856
|
+
this.renderChatThread();
|
|
857
|
+
this.syncUiStates();
|
|
858
|
+
this.textareaEl?.focus();
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
public cancelEditingFeedback(): void {
|
|
863
|
+
if (this.editingFeedbackId === null) return;
|
|
864
|
+
this.editingFeedbackId = null;
|
|
865
|
+
|
|
866
|
+
if (this.stashedDraftBeforeEdit) {
|
|
867
|
+
if (this.textareaEl) {
|
|
868
|
+
this.textareaEl.value = this.stashedDraftBeforeEdit.message;
|
|
869
|
+
}
|
|
870
|
+
this.elementReferences = this.stashedDraftBeforeEdit.elementReferences;
|
|
871
|
+
this.elementDomNodes = this.stashedDraftBeforeEdit.elementDomNodes;
|
|
872
|
+
this.attachments = this.stashedDraftBeforeEdit.attachments;
|
|
873
|
+
this.stashedDraftBeforeEdit = null;
|
|
874
|
+
} else {
|
|
875
|
+
if (this.textareaEl) {
|
|
876
|
+
this.textareaEl.value = "";
|
|
877
|
+
}
|
|
878
|
+
this.elementReferences = [];
|
|
879
|
+
this.elementDomNodes.clear();
|
|
880
|
+
this.attachments = [];
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
this.picker?.hideExternalPreview();
|
|
884
|
+
this.picker?.refreshPinnedMarkers();
|
|
885
|
+
this.renderTray();
|
|
886
|
+
this.renderChatThread();
|
|
887
|
+
this.syncUiStates();
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
public startCommentingFeedback(feedbackId: number | string): boolean {
|
|
891
|
+
const targetKey = String(feedbackId);
|
|
892
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
893
|
+
if (!entry) return false;
|
|
894
|
+
|
|
895
|
+
if (this.editingFeedbackId !== null) {
|
|
896
|
+
this.cancelEditingFeedback();
|
|
897
|
+
}
|
|
898
|
+
this.confirmingDeleteId = null;
|
|
899
|
+
this.hideStatus();
|
|
900
|
+
|
|
901
|
+
if (this.commentingFeedbackId === null && this.editingFeedbackId === null) {
|
|
902
|
+
this.stashedDraftBeforeEdit = {
|
|
903
|
+
message: this.textareaEl?.value || "",
|
|
904
|
+
elementReferences: [...this.elementReferences],
|
|
905
|
+
elementDomNodes: new Map(this.elementDomNodes),
|
|
906
|
+
attachments: [...this.attachments]
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
this.commentingFeedbackId = targetKey;
|
|
911
|
+
if (this.textareaEl) {
|
|
912
|
+
this.textareaEl.value = "";
|
|
913
|
+
}
|
|
914
|
+
this.elementReferences = [];
|
|
915
|
+
this.elementDomNodes.clear();
|
|
916
|
+
this.attachments = [];
|
|
917
|
+
|
|
918
|
+
this.picker?.hideExternalPreview();
|
|
919
|
+
this.picker?.refreshPinnedMarkers();
|
|
920
|
+
this.renderTray();
|
|
921
|
+
this.renderChatThread();
|
|
922
|
+
this.syncUiStates();
|
|
923
|
+
this.textareaEl?.focus();
|
|
924
|
+
return true;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
public cancelCommentingFeedback(): void {
|
|
928
|
+
if (this.commentingFeedbackId === null) return;
|
|
929
|
+
this.commentingFeedbackId = null;
|
|
930
|
+
|
|
931
|
+
if (this.stashedDraftBeforeEdit) {
|
|
932
|
+
if (this.textareaEl) {
|
|
933
|
+
this.textareaEl.value = this.stashedDraftBeforeEdit.message;
|
|
934
|
+
}
|
|
935
|
+
this.elementReferences = this.stashedDraftBeforeEdit.elementReferences;
|
|
936
|
+
this.elementDomNodes = this.stashedDraftBeforeEdit.elementDomNodes;
|
|
937
|
+
this.attachments = this.stashedDraftBeforeEdit.attachments;
|
|
938
|
+
this.stashedDraftBeforeEdit = null;
|
|
939
|
+
} else {
|
|
940
|
+
if (this.textareaEl) {
|
|
941
|
+
this.textareaEl.value = "";
|
|
942
|
+
}
|
|
943
|
+
this.elementReferences = [];
|
|
944
|
+
this.elementDomNodes.clear();
|
|
945
|
+
this.attachments = [];
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
this.renderTray();
|
|
949
|
+
this.renderChatThread();
|
|
950
|
+
this.syncUiStates();
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
public async markFeedbackReviewed(feedbackId: number | string): Promise<void> {
|
|
954
|
+
if (this.reviewingFeedbackId !== null || this.isSubmitting) return;
|
|
955
|
+
const targetKey = String(feedbackId);
|
|
956
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
957
|
+
if (!entry) return;
|
|
958
|
+
|
|
959
|
+
this.reviewingFeedbackId = targetKey;
|
|
960
|
+
this.renderChatThread();
|
|
961
|
+
|
|
962
|
+
try {
|
|
963
|
+
const res = await this.apiClient.updateFeedback(
|
|
964
|
+
entry.id,
|
|
965
|
+
{ status: "reviewed" },
|
|
966
|
+
entry.ownershipToken
|
|
967
|
+
);
|
|
968
|
+
entry.status = res?.status || "reviewed";
|
|
969
|
+
if (res?.ownership_token) {
|
|
970
|
+
entry.ownershipToken = res.ownership_token;
|
|
971
|
+
}
|
|
972
|
+
this.reviewingFeedbackId = null;
|
|
973
|
+
this.renderChatThread();
|
|
974
|
+
this.showStatus("Fix marked as reviewed.", "success");
|
|
975
|
+
this.emitWidgetEvent("context-drop:update", { response: res, id: entry.id });
|
|
976
|
+
} catch (err) {
|
|
977
|
+
this.reviewingFeedbackId = null;
|
|
978
|
+
this.renderChatThread();
|
|
979
|
+
const msg = err instanceof Error ? err.message : "Failed to mark feedback as reviewed.";
|
|
980
|
+
this.showStatus(msg, "error");
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
public requestDeleteFeedback(feedbackId: number | string): void {
|
|
985
|
+
const targetKey = String(feedbackId);
|
|
986
|
+
if (!this.sessionHistory.some((item) => String(item.id) === targetKey)) return;
|
|
987
|
+
this.confirmingDeleteId = this.confirmingDeleteId === targetKey ? null : targetKey;
|
|
988
|
+
this.renderChatThread();
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
public cancelDeleteFeedback(): void {
|
|
992
|
+
if (this.confirmingDeleteId === null) return;
|
|
993
|
+
this.confirmingDeleteId = null;
|
|
994
|
+
this.renderChatThread();
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
public async confirmDeleteFeedback(feedbackId: number | string): Promise<void> {
|
|
998
|
+
if (this.deletingFeedbackId !== null) return;
|
|
999
|
+
const targetKey = String(feedbackId);
|
|
1000
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
1001
|
+
if (!entry) return;
|
|
1002
|
+
|
|
1003
|
+
this.deletingFeedbackId = targetKey;
|
|
1004
|
+
this.renderChatThread();
|
|
1005
|
+
|
|
1006
|
+
try {
|
|
1007
|
+
const res = await this.apiClient.deleteFeedback(entry.id, entry.ownershipToken);
|
|
1008
|
+
if (this.editingFeedbackId === targetKey) {
|
|
1009
|
+
this.cancelEditingFeedback();
|
|
1010
|
+
}
|
|
1011
|
+
this.sessionHistory = this.sessionHistory.filter((item) => String(item.id) !== targetKey);
|
|
1012
|
+
this.confirmingDeleteId = null;
|
|
1013
|
+
this.deletingFeedbackId = null;
|
|
1014
|
+
this.renderChatThread();
|
|
1015
|
+
this.renderTray();
|
|
1016
|
+
this.syncUiStates();
|
|
1017
|
+
this.showStatus(
|
|
1018
|
+
this.isSmartSelectionMode() ? "Your feedback was deleted." : "Feedback deleted.",
|
|
1019
|
+
"success"
|
|
1020
|
+
);
|
|
1021
|
+
this.emitWidgetEvent("context-drop:delete", {
|
|
1022
|
+
response: res,
|
|
1023
|
+
id: entry.id
|
|
1024
|
+
});
|
|
1025
|
+
} catch (err) {
|
|
1026
|
+
this.deletingFeedbackId = null;
|
|
1027
|
+
this.renderChatThread();
|
|
1028
|
+
const msg = err instanceof Error ? err.message : "Failed to delete feedback.";
|
|
1029
|
+
this.showStatus(msg, "error");
|
|
1030
|
+
this.emitWidgetEvent("context-drop:error", {
|
|
1031
|
+
error: msg
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
484
1036
|
public getAgentMessages(): AgentChatMessage[] {
|
|
485
1037
|
return [...this.agentMessages];
|
|
486
1038
|
}
|
|
@@ -514,16 +1066,23 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
514
1066
|
}
|
|
515
1067
|
|
|
516
1068
|
public openComposer(): void {
|
|
1069
|
+
const wasOpen = this.isOpen && !this.isMinimized;
|
|
517
1070
|
this.isOpen = true;
|
|
518
1071
|
this.isMinimized = false;
|
|
519
1072
|
if (this.isAgentModeActive()) {
|
|
520
1073
|
void this.ensureAgentStatusLoaded();
|
|
1074
|
+
} else {
|
|
1075
|
+
void this.ensureOwnFeedbacksLoaded();
|
|
521
1076
|
}
|
|
522
1077
|
this.syncUiStates();
|
|
523
1078
|
this.focusActiveInput();
|
|
1079
|
+
if (!wasOpen) {
|
|
1080
|
+
this.emitWidgetEvent("context-drop:open", { open: true });
|
|
1081
|
+
}
|
|
524
1082
|
}
|
|
525
1083
|
|
|
526
1084
|
public closeComposer(): void {
|
|
1085
|
+
const wasOpen = this.isOpen;
|
|
527
1086
|
this.isOpen = false;
|
|
528
1087
|
this.isMinimized = false;
|
|
529
1088
|
if (this.picker && this.picker.isActive()) {
|
|
@@ -531,6 +1090,9 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
531
1090
|
}
|
|
532
1091
|
this.picker?.hideExternalPreview();
|
|
533
1092
|
this.syncUiStates();
|
|
1093
|
+
if (wasOpen) {
|
|
1094
|
+
this.emitWidgetEvent("context-drop:close", { open: false });
|
|
1095
|
+
}
|
|
534
1096
|
}
|
|
535
1097
|
|
|
536
1098
|
public toggleComposer(): void {
|
|
@@ -791,7 +1353,15 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
791
1353
|
|
|
792
1354
|
private readDataAttributes(): void {
|
|
793
1355
|
const endpoint = this.getAttribute("data-endpoint") || "/context_drop";
|
|
794
|
-
|
|
1356
|
+
const rawCredentials = this.getAttribute("data-credentials");
|
|
1357
|
+
const credentials: RequestCredentials =
|
|
1358
|
+
rawCredentials === "include" || rawCredentials === "omit" || rawCredentials === "same-origin"
|
|
1359
|
+
? rawCredentials
|
|
1360
|
+
: "same-origin";
|
|
1361
|
+
this.apiClient = new ContextDropApiClient(endpoint, {
|
|
1362
|
+
credentials,
|
|
1363
|
+
headers: this.customHeaders
|
|
1364
|
+
});
|
|
795
1365
|
|
|
796
1366
|
const rawConfig = this.getAttribute("data-config");
|
|
797
1367
|
if (rawConfig) {
|
|
@@ -847,6 +1417,16 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
847
1417
|
if (themeOverride === "dark" || themeOverride === "light") {
|
|
848
1418
|
this.currentTheme = themeOverride;
|
|
849
1419
|
}
|
|
1420
|
+
|
|
1421
|
+
const selectionModeOverride = this.getAttribute("data-selection-mode") as SelectionMode | null;
|
|
1422
|
+
if (selectionModeOverride === "smart" || selectionModeOverride === "verbose") {
|
|
1423
|
+
this.config.features.selection_mode = selectionModeOverride;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
const envOverride = this.getAttribute("data-environment");
|
|
1427
|
+
if (envOverride && envOverride.trim().length > 0) {
|
|
1428
|
+
this.config.environment = envOverride.trim();
|
|
1429
|
+
}
|
|
850
1430
|
}
|
|
851
1431
|
|
|
852
1432
|
private detectViewportSnapCorner(
|
|
@@ -1508,6 +2088,31 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1508
2088
|
const promptShell = document.createElement("div");
|
|
1509
2089
|
promptShell.className = "cd-prompt-shell";
|
|
1510
2090
|
|
|
2091
|
+
const editBanner = document.createElement("div");
|
|
2092
|
+
editBanner.className = "cd-edit-banner";
|
|
2093
|
+
editBanner.hidden = true;
|
|
2094
|
+
|
|
2095
|
+
const editBannerInfo = document.createElement("span");
|
|
2096
|
+
editBannerInfo.className = "cd-edit-banner-info";
|
|
2097
|
+
this.editBannerInfoEl = editBannerInfo;
|
|
2098
|
+
editBanner.appendChild(editBannerInfo);
|
|
2099
|
+
|
|
2100
|
+
const cancelEditBtn = document.createElement("button");
|
|
2101
|
+
cancelEditBtn.type = "button";
|
|
2102
|
+
cancelEditBtn.className = "cd-btn cd-btn-xs";
|
|
2103
|
+
cancelEditBtn.setAttribute("aria-label", "Cancel editing feedback");
|
|
2104
|
+
cancelEditBtn.textContent = "Cancel";
|
|
2105
|
+
cancelEditBtn.addEventListener("click", () => {
|
|
2106
|
+
if (this.commentingFeedbackId !== null) {
|
|
2107
|
+
this.cancelCommentingFeedback();
|
|
2108
|
+
} else {
|
|
2109
|
+
this.cancelEditingFeedback();
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
editBanner.appendChild(cancelEditBtn);
|
|
2113
|
+
this.editBannerEl = editBanner;
|
|
2114
|
+
promptShell.appendChild(editBanner);
|
|
2115
|
+
|
|
1511
2116
|
const textarea = document.createElement("textarea");
|
|
1512
2117
|
textarea.className = "cd-textarea";
|
|
1513
2118
|
textarea.placeholder = this.config.placeholder;
|
|
@@ -1517,8 +2122,17 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1517
2122
|
ev.preventDefault();
|
|
1518
2123
|
void this.handleSubmit();
|
|
1519
2124
|
} else if (ev.key === "Escape") {
|
|
2125
|
+
if (ev.defaultPrevented) return;
|
|
1520
2126
|
ev.preventDefault();
|
|
1521
|
-
this.
|
|
2127
|
+
if (this.confirmingDeleteId !== null) {
|
|
2128
|
+
this.cancelDeleteFeedback();
|
|
2129
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
2130
|
+
this.cancelCommentingFeedback();
|
|
2131
|
+
} else if (this.editingFeedbackId !== null) {
|
|
2132
|
+
this.cancelEditingFeedback();
|
|
2133
|
+
} else {
|
|
2134
|
+
this.closeComposer();
|
|
2135
|
+
}
|
|
1522
2136
|
}
|
|
1523
2137
|
});
|
|
1524
2138
|
textarea.addEventListener("paste", (ev) => this.handlePaste(ev));
|
|
@@ -1746,7 +2360,6 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1746
2360
|
providerPill.appendChild(keyDot);
|
|
1747
2361
|
providerPill.appendChild(providerLabel);
|
|
1748
2362
|
providerPill.addEventListener("click", () => this.toggleByokDrawer());
|
|
1749
|
-
this.providerPillBtn = providerPill;
|
|
1750
2363
|
|
|
1751
2364
|
const subbarRight = document.createElement("div");
|
|
1752
2365
|
subbarRight.className = "cd-subbar-right";
|
|
@@ -2774,12 +3387,21 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2774
3387
|
if (this.composerModeSwitchWrap) {
|
|
2775
3388
|
this.composerModeSwitchWrap.hidden = !this.config.agent?.enabled;
|
|
2776
3389
|
}
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
3390
|
+
const isCommenting = this.commentingFeedbackId !== null;
|
|
3391
|
+
if (this.textareaEl) {
|
|
3392
|
+
if (isCommenting) {
|
|
3393
|
+
this.textareaEl.placeholder = "Write a comment... (attach or paste images below)";
|
|
3394
|
+
} else if (!this.customPlaceholderSet) {
|
|
3395
|
+
this.textareaEl.placeholder = smartMode
|
|
3396
|
+
? DEFAULT_SMART_PLACEHOLDER
|
|
3397
|
+
: DEFAULT_VERBOSE_PLACEHOLDER;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
if (this.cornerPinBtn) {
|
|
3401
|
+
this.cornerPinBtn.hidden = isCommenting;
|
|
2781
3402
|
}
|
|
2782
3403
|
if (this.composerToolbarPickBtn) {
|
|
3404
|
+
this.composerToolbarPickBtn.hidden = isCommenting;
|
|
2783
3405
|
if (smartMode) {
|
|
2784
3406
|
this.composerToolbarPickBtn.title = "Highlight an area on the page";
|
|
2785
3407
|
this.composerToolbarPickBtn.setAttribute("aria-label", "Highlight an area on the page");
|
|
@@ -2794,13 +3416,60 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2794
3416
|
}
|
|
2795
3417
|
}
|
|
2796
3418
|
if (this.composerToolbarScreenshotBtn) {
|
|
2797
|
-
this.composerToolbarScreenshotBtn.hidden = smartMode;
|
|
3419
|
+
this.composerToolbarScreenshotBtn.hidden = smartMode && !isCommenting;
|
|
2798
3420
|
}
|
|
2799
3421
|
if (this.composerToolbarUploadBtn) {
|
|
2800
3422
|
this.composerToolbarUploadBtn.innerHTML = smartMode
|
|
2801
3423
|
? `${ICON_IMAGE}<span>Add image</span>`
|
|
2802
3424
|
: `${ICON_IMAGE}<span>Image</span>`;
|
|
2803
3425
|
}
|
|
3426
|
+
if (this.editBannerEl && this.editBannerInfoEl) {
|
|
3427
|
+
if (this.editingFeedbackId !== null) {
|
|
3428
|
+
this.editBannerEl.hidden = false;
|
|
3429
|
+
this.editBannerInfoEl.innerHTML = "";
|
|
3430
|
+
const iconSpan = document.createElement("span");
|
|
3431
|
+
iconSpan.innerHTML = ICON_EDIT;
|
|
3432
|
+
const labelSpan = document.createElement("span");
|
|
3433
|
+
labelSpan.textContent = smartMode ? "Editing your feedback" : "Editing feedback";
|
|
3434
|
+
this.editBannerInfoEl.appendChild(iconSpan);
|
|
3435
|
+
this.editBannerInfoEl.appendChild(labelSpan);
|
|
3436
|
+
if (!smartMode) {
|
|
3437
|
+
const idSpan = document.createElement("span");
|
|
3438
|
+
idSpan.className = "cd-edit-banner-id";
|
|
3439
|
+
idSpan.textContent = `#${this.editingFeedbackId}`;
|
|
3440
|
+
this.editBannerInfoEl.appendChild(idSpan);
|
|
3441
|
+
}
|
|
3442
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
3443
|
+
this.editBannerEl.hidden = false;
|
|
3444
|
+
this.editBannerInfoEl.innerHTML = "";
|
|
3445
|
+
const iconSpan = document.createElement("span");
|
|
3446
|
+
iconSpan.innerHTML = ICON_COMMENT;
|
|
3447
|
+
const labelSpan = document.createElement("span");
|
|
3448
|
+
labelSpan.textContent = smartMode ? "Commenting on feedback" : "Commenting on";
|
|
3449
|
+
this.editBannerInfoEl.appendChild(iconSpan);
|
|
3450
|
+
this.editBannerInfoEl.appendChild(labelSpan);
|
|
3451
|
+
if (!smartMode) {
|
|
3452
|
+
const idSpan = document.createElement("span");
|
|
3453
|
+
idSpan.className = "cd-edit-banner-id";
|
|
3454
|
+
idSpan.textContent = `#${this.commentingFeedbackId}`;
|
|
3455
|
+
this.editBannerInfoEl.appendChild(idSpan);
|
|
3456
|
+
}
|
|
3457
|
+
} else {
|
|
3458
|
+
this.editBannerEl.hidden = true;
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
if (this.submitBtn && !this.isSubmitting) {
|
|
3462
|
+
if (this.editingFeedbackId !== null) {
|
|
3463
|
+
this.submitBtn.setAttribute("aria-label", "Save feedback changes");
|
|
3464
|
+
this.submitBtn.innerHTML = `${ICON_CHECK}<span>Save</span>`;
|
|
3465
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
3466
|
+
this.submitBtn.setAttribute("aria-label", "Submit comment");
|
|
3467
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Comment</span>`;
|
|
3468
|
+
} else {
|
|
3469
|
+
this.submitBtn.setAttribute("aria-label", "Submit feedback");
|
|
3470
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Send</span>`;
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
2804
3473
|
|
|
2805
3474
|
if (this.agentSidebarEl) {
|
|
2806
3475
|
this.agentSidebarEl.hidden = !showAgentSidebar;
|
|
@@ -3036,8 +3705,21 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3036
3705
|
this.chatThreadEl.hidden = false;
|
|
3037
3706
|
|
|
3038
3707
|
for (const entry of this.sessionHistory) {
|
|
3708
|
+
const entryIdStr = String(entry.id);
|
|
3709
|
+
const isEditingThis = this.editingFeedbackId === entryIdStr;
|
|
3710
|
+
const isCommentingThis = this.commentingFeedbackId === entryIdStr;
|
|
3711
|
+
const isReviewingThis = this.reviewingFeedbackId === entryIdStr;
|
|
3712
|
+
const isConfirmingDelete = this.confirmingDeleteId === entryIdStr;
|
|
3713
|
+
const isDeletingThis = this.deletingFeedbackId === entryIdStr;
|
|
3714
|
+
const statusName = entry.status || "new";
|
|
3715
|
+
|
|
3039
3716
|
const msgCard = document.createElement("div");
|
|
3040
|
-
msgCard.className =
|
|
3717
|
+
msgCard.className = isEditingThis
|
|
3718
|
+
? "cd-chat-msg is-editing"
|
|
3719
|
+
: isCommentingThis
|
|
3720
|
+
? "cd-chat-msg is-commenting"
|
|
3721
|
+
: "cd-chat-msg";
|
|
3722
|
+
msgCard.setAttribute("data-feedback-id", entryIdStr);
|
|
3041
3723
|
|
|
3042
3724
|
if (entry.elements.length > 0 || entry.attachments.length > 0) {
|
|
3043
3725
|
const pills = document.createElement("div");
|
|
@@ -3070,16 +3752,192 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3070
3752
|
msgCard.appendChild(textP);
|
|
3071
3753
|
}
|
|
3072
3754
|
|
|
3755
|
+
if (entry.comments && entry.comments.length > 0) {
|
|
3756
|
+
const commentsList = document.createElement("div");
|
|
3757
|
+
commentsList.className = "cd-comments-list";
|
|
3758
|
+
for (const comment of entry.comments) {
|
|
3759
|
+
const cItem = document.createElement("div");
|
|
3760
|
+
cItem.className = "cd-comment-item";
|
|
3761
|
+
|
|
3762
|
+
const cHeader = document.createElement("div");
|
|
3763
|
+
cHeader.className = "cd-comment-header";
|
|
3764
|
+
const cAuthor = document.createElement("span");
|
|
3765
|
+
cAuthor.className = "cd-comment-author";
|
|
3766
|
+
cAuthor.textContent = comment.author_label || "You";
|
|
3767
|
+
const cTime = document.createElement("span");
|
|
3768
|
+
cTime.textContent = comment.createdAt;
|
|
3769
|
+
cHeader.appendChild(cAuthor);
|
|
3770
|
+
cHeader.appendChild(cTime);
|
|
3771
|
+
cItem.appendChild(cHeader);
|
|
3772
|
+
|
|
3773
|
+
if (comment.body) {
|
|
3774
|
+
const cBody = document.createElement("p");
|
|
3775
|
+
cBody.className = "cd-comment-body";
|
|
3776
|
+
cBody.textContent = comment.body;
|
|
3777
|
+
cItem.appendChild(cBody);
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
if (comment.attachments && comment.attachments.length > 0) {
|
|
3781
|
+
const cImgs = document.createElement("div");
|
|
3782
|
+
cImgs.className = "cd-comment-images";
|
|
3783
|
+
for (const att of comment.attachments) {
|
|
3784
|
+
if (att.preview_url) {
|
|
3785
|
+
const imgLink = document.createElement("a");
|
|
3786
|
+
imgLink.href = att.preview_url;
|
|
3787
|
+
imgLink.target = "_blank";
|
|
3788
|
+
imgLink.rel = "noopener noreferrer";
|
|
3789
|
+
const img = document.createElement("img");
|
|
3790
|
+
img.src = att.preview_url;
|
|
3791
|
+
img.alt = att.label || "Comment image";
|
|
3792
|
+
img.className = "cd-comment-thumb";
|
|
3793
|
+
imgLink.appendChild(img);
|
|
3794
|
+
cImgs.appendChild(imgLink);
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
if (cImgs.childNodes.length > 0) {
|
|
3798
|
+
cItem.appendChild(cImgs);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
commentsList.appendChild(cItem);
|
|
3803
|
+
}
|
|
3804
|
+
msgCard.appendChild(commentsList);
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3073
3807
|
const meta = document.createElement("div");
|
|
3074
3808
|
meta.className = "cd-chat-msg-meta";
|
|
3809
|
+
|
|
3810
|
+
const metaInfo = document.createElement("div");
|
|
3811
|
+
metaInfo.className = "cd-chat-msg-meta-info";
|
|
3812
|
+
|
|
3813
|
+
const statusBadge = document.createElement("span");
|
|
3814
|
+
statusBadge.className = `cd-msg-status-badge is-${statusName}`;
|
|
3815
|
+
statusBadge.textContent = statusName;
|
|
3816
|
+
|
|
3075
3817
|
const idSpan = document.createElement("span");
|
|
3076
|
-
|
|
3818
|
+
const baseLabel = smartMode ? "Feedback sent" : `Dropped #${entry.id}`;
|
|
3819
|
+
idSpan.textContent = entry.isEdited ? `${baseLabel} · edited` : baseLabel;
|
|
3820
|
+
|
|
3821
|
+
const sepSpan = document.createElement("span");
|
|
3822
|
+
sepSpan.setAttribute("aria-hidden", "true");
|
|
3823
|
+
sepSpan.textContent = "·";
|
|
3824
|
+
|
|
3077
3825
|
const timeSpan = document.createElement("span");
|
|
3078
3826
|
timeSpan.textContent = entry.createdAt;
|
|
3079
|
-
|
|
3080
|
-
|
|
3827
|
+
|
|
3828
|
+
metaInfo.appendChild(statusBadge);
|
|
3829
|
+
metaInfo.appendChild(idSpan);
|
|
3830
|
+
metaInfo.appendChild(sepSpan);
|
|
3831
|
+
metaInfo.appendChild(timeSpan);
|
|
3832
|
+
|
|
3833
|
+
const actions = document.createElement("div");
|
|
3834
|
+
actions.className = "cd-chat-msg-actions";
|
|
3835
|
+
|
|
3836
|
+
if (statusName === "fixed") {
|
|
3837
|
+
const reviewBtn = document.createElement("button");
|
|
3838
|
+
reviewBtn.type = "button";
|
|
3839
|
+
reviewBtn.className = "cd-review-btn";
|
|
3840
|
+
reviewBtn.title = "Confirm fix was tested and reviewed";
|
|
3841
|
+
reviewBtn.setAttribute("aria-label", "Mark fix as reviewed");
|
|
3842
|
+
reviewBtn.disabled = isReviewingThis || this.isSubmitting || this.deletingFeedbackId !== null;
|
|
3843
|
+
reviewBtn.innerHTML = `${ICON_CHECK}<span>${isReviewingThis ? "Saving..." : "Mark Reviewed"}</span>`;
|
|
3844
|
+
reviewBtn.addEventListener("click", () => {
|
|
3845
|
+
void this.markFeedbackReviewed(entry.id);
|
|
3846
|
+
});
|
|
3847
|
+
actions.appendChild(reviewBtn);
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
const commentBtn = document.createElement("button");
|
|
3851
|
+
commentBtn.type = "button";
|
|
3852
|
+
commentBtn.className = `cd-msg-action-btn${isCommentingThis ? " is-active" : ""}`;
|
|
3853
|
+
commentBtn.title = isCommentingThis ? "Cancel comment" : "Add comment";
|
|
3854
|
+
commentBtn.setAttribute("aria-label", "Add comment");
|
|
3855
|
+
commentBtn.setAttribute("aria-pressed", String(isCommentingThis));
|
|
3856
|
+
commentBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
3857
|
+
commentBtn.innerHTML = ICON_COMMENT;
|
|
3858
|
+
commentBtn.addEventListener("click", () => {
|
|
3859
|
+
if (this.commentingFeedbackId === entryIdStr) {
|
|
3860
|
+
this.cancelCommentingFeedback();
|
|
3861
|
+
} else {
|
|
3862
|
+
this.startCommentingFeedback(entry.id);
|
|
3863
|
+
}
|
|
3864
|
+
});
|
|
3865
|
+
|
|
3866
|
+
const editBtn = document.createElement("button");
|
|
3867
|
+
editBtn.type = "button";
|
|
3868
|
+
editBtn.className = `cd-msg-action-btn${isEditingThis ? " is-active" : ""}`;
|
|
3869
|
+
editBtn.title = isEditingThis ? "Cancel editing" : "Edit feedback";
|
|
3870
|
+
editBtn.setAttribute("aria-label", "Edit feedback");
|
|
3871
|
+
editBtn.setAttribute("aria-pressed", String(isEditingThis));
|
|
3872
|
+
editBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
3873
|
+
editBtn.innerHTML = ICON_EDIT;
|
|
3874
|
+
editBtn.addEventListener("click", () => {
|
|
3875
|
+
if (this.editingFeedbackId === entryIdStr) {
|
|
3876
|
+
this.cancelEditingFeedback();
|
|
3877
|
+
} else {
|
|
3878
|
+
this.startEditingFeedback(entry.id);
|
|
3879
|
+
}
|
|
3880
|
+
});
|
|
3881
|
+
|
|
3882
|
+
const deleteBtn = document.createElement("button");
|
|
3883
|
+
deleteBtn.type = "button";
|
|
3884
|
+
deleteBtn.className = "cd-msg-action-btn is-danger";
|
|
3885
|
+
deleteBtn.title = "Delete feedback";
|
|
3886
|
+
deleteBtn.setAttribute("aria-label", "Delete feedback");
|
|
3887
|
+
deleteBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
3888
|
+
deleteBtn.innerHTML = ICON_TRASH;
|
|
3889
|
+
deleteBtn.addEventListener("click", () => {
|
|
3890
|
+
this.requestDeleteFeedback(entry.id);
|
|
3891
|
+
});
|
|
3892
|
+
|
|
3893
|
+
actions.appendChild(commentBtn);
|
|
3894
|
+
actions.appendChild(editBtn);
|
|
3895
|
+
actions.appendChild(deleteBtn);
|
|
3896
|
+
|
|
3897
|
+
meta.appendChild(metaInfo);
|
|
3898
|
+
meta.appendChild(actions);
|
|
3081
3899
|
msgCard.appendChild(meta);
|
|
3082
3900
|
|
|
3901
|
+
if (isConfirmingDelete) {
|
|
3902
|
+
const confirmBar = document.createElement("div");
|
|
3903
|
+
confirmBar.className = "cd-msg-delete-confirm";
|
|
3904
|
+
confirmBar.setAttribute("role", "group");
|
|
3905
|
+
confirmBar.setAttribute("aria-label", "Confirm feedback deletion");
|
|
3906
|
+
|
|
3907
|
+
const confirmLabel = document.createElement("span");
|
|
3908
|
+
confirmLabel.className = "cd-msg-delete-label";
|
|
3909
|
+
confirmLabel.textContent = "Delete this feedback?";
|
|
3910
|
+
|
|
3911
|
+
const btnGroup = document.createElement("div");
|
|
3912
|
+
btnGroup.className = "cd-msg-delete-btns";
|
|
3913
|
+
|
|
3914
|
+
const cancelDeleteBtn = document.createElement("button");
|
|
3915
|
+
cancelDeleteBtn.type = "button";
|
|
3916
|
+
cancelDeleteBtn.className = "cd-btn cd-btn-xs";
|
|
3917
|
+
cancelDeleteBtn.setAttribute("aria-label", "Cancel delete");
|
|
3918
|
+
cancelDeleteBtn.disabled = isDeletingThis;
|
|
3919
|
+
cancelDeleteBtn.textContent = "Cancel";
|
|
3920
|
+
cancelDeleteBtn.addEventListener("click", () => {
|
|
3921
|
+
this.cancelDeleteFeedback();
|
|
3922
|
+
});
|
|
3923
|
+
|
|
3924
|
+
const confirmDeleteBtn = document.createElement("button");
|
|
3925
|
+
confirmDeleteBtn.type = "button";
|
|
3926
|
+
confirmDeleteBtn.className = "cd-btn cd-btn-xs cd-btn-danger";
|
|
3927
|
+
confirmDeleteBtn.setAttribute("aria-label", "Confirm delete feedback");
|
|
3928
|
+
confirmDeleteBtn.disabled = isDeletingThis;
|
|
3929
|
+
confirmDeleteBtn.textContent = isDeletingThis ? "Deleting..." : "Delete";
|
|
3930
|
+
confirmDeleteBtn.addEventListener("click", () => {
|
|
3931
|
+
void this.confirmDeleteFeedback(entry.id);
|
|
3932
|
+
});
|
|
3933
|
+
|
|
3934
|
+
btnGroup.appendChild(cancelDeleteBtn);
|
|
3935
|
+
btnGroup.appendChild(confirmDeleteBtn);
|
|
3936
|
+
confirmBar.appendChild(confirmLabel);
|
|
3937
|
+
confirmBar.appendChild(btnGroup);
|
|
3938
|
+
msgCard.appendChild(confirmBar);
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3083
3941
|
this.chatThreadEl.appendChild(msgCard);
|
|
3084
3942
|
}
|
|
3085
3943
|
|
|
@@ -3468,13 +4326,20 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3468
4326
|
public async handleSubmit(): Promise<void> {
|
|
3469
4327
|
if (this.isSubmitting) return;
|
|
3470
4328
|
const smartMode = this.isSmartSelectionMode();
|
|
4329
|
+
const editingId = this.editingFeedbackId;
|
|
4330
|
+
const commentingId = this.commentingFeedbackId;
|
|
3471
4331
|
|
|
3472
4332
|
if (this.pendingSmartCaptures.size > 0) {
|
|
3473
4333
|
await Promise.allSettled(Array.from(this.pendingSmartCaptures));
|
|
3474
4334
|
}
|
|
3475
4335
|
|
|
3476
4336
|
const message = (this.textareaEl?.value || "").trim();
|
|
3477
|
-
if (
|
|
4337
|
+
if (commentingId !== null) {
|
|
4338
|
+
if (message.length === 0 && this.attachments.length === 0) {
|
|
4339
|
+
this.showStatus("Write a comment or attach an image first.", "error");
|
|
4340
|
+
return;
|
|
4341
|
+
}
|
|
4342
|
+
} else if (
|
|
3478
4343
|
message.length === 0 &&
|
|
3479
4344
|
this.attachments.length === 0 &&
|
|
3480
4345
|
this.elementReferences.length === 0
|
|
@@ -3491,32 +4356,173 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3491
4356
|
this.isSubmitting = true;
|
|
3492
4357
|
if (this.submitBtn) {
|
|
3493
4358
|
this.submitBtn.disabled = true;
|
|
3494
|
-
this.submitBtn.innerHTML =
|
|
4359
|
+
this.submitBtn.innerHTML =
|
|
4360
|
+
editingId !== null
|
|
4361
|
+
? `<span>Saving...</span>`
|
|
4362
|
+
: commentingId !== null
|
|
4363
|
+
? `<span>Posting...</span>`
|
|
4364
|
+
: `<span>Sending...</span>`;
|
|
3495
4365
|
}
|
|
3496
4366
|
|
|
3497
4367
|
try {
|
|
3498
|
-
const submittedElements =
|
|
3499
|
-
const submittedAttachments = this.attachments.map((att) => ({
|
|
4368
|
+
const submittedElements = structuredClone(this.elementReferences);
|
|
4369
|
+
const submittedAttachments: SessionFeedbackAttachmentItem[] = this.attachments.map((att) => ({
|
|
3500
4370
|
id: att.id,
|
|
4371
|
+
server_id: att.existing_attachment_id,
|
|
3501
4372
|
label: att.label,
|
|
3502
4373
|
preview_url: att.preview_url,
|
|
3503
|
-
attachment_type: att.attachment_type
|
|
4374
|
+
attachment_type: att.attachment_type,
|
|
4375
|
+
filename: att.filename,
|
|
4376
|
+
signed_blob_id: att.signed_blob_id,
|
|
4377
|
+
data_url: att.data_url,
|
|
4378
|
+
element_reference_ref: att.element_reference_ref || null,
|
|
4379
|
+
metadata: att.metadata ? structuredClone(att.metadata) : {}
|
|
3504
4380
|
}));
|
|
3505
4381
|
|
|
4382
|
+
const commonMetadata: Record<string, unknown> = {
|
|
4383
|
+
...this.customMetadata,
|
|
4384
|
+
environment: this.config.environment,
|
|
4385
|
+
selection_mode: smartMode ? "smart" : "verbose",
|
|
4386
|
+
viewport: {
|
|
4387
|
+
width: typeof window !== "undefined" ? window.innerWidth : 0,
|
|
4388
|
+
height: typeof window !== "undefined" ? window.innerHeight : 0
|
|
4389
|
+
},
|
|
4390
|
+
locale: typeof navigator !== "undefined" ? navigator.language : "en"
|
|
4391
|
+
};
|
|
4392
|
+
|
|
4393
|
+
if (commentingId !== null) {
|
|
4394
|
+
const existingIdx = this.sessionHistory.findIndex(
|
|
4395
|
+
(item) => String(item.id) === commentingId
|
|
4396
|
+
);
|
|
4397
|
+
const existingEntry = existingIdx >= 0 ? this.sessionHistory[existingIdx] : undefined;
|
|
4398
|
+
|
|
4399
|
+
const commentPayload: CreateCommentPayload = {
|
|
4400
|
+
body: message,
|
|
4401
|
+
attachments: this.attachments.map((att) => ({
|
|
4402
|
+
attachment_type: att.attachment_type,
|
|
4403
|
+
filename: att.filename,
|
|
4404
|
+
signed_blob_id: att.signed_blob_id,
|
|
4405
|
+
data_url: att.signed_blob_id ? undefined : att.data_url,
|
|
4406
|
+
metadata: att.metadata
|
|
4407
|
+
}))
|
|
4408
|
+
};
|
|
4409
|
+
|
|
4410
|
+
const commentRes = await this.apiClient.createComment(
|
|
4411
|
+
existingEntry?.id ?? commentingId,
|
|
4412
|
+
commentPayload,
|
|
4413
|
+
existingEntry?.ownershipToken
|
|
4414
|
+
);
|
|
4415
|
+
|
|
4416
|
+
if (commentRes?.feedback) {
|
|
4417
|
+
const updatedEntry = this.mapOwnRecordToSessionEntry(commentRes.feedback, existingEntry);
|
|
4418
|
+
if (existingIdx >= 0) {
|
|
4419
|
+
this.sessionHistory[existingIdx] = updatedEntry;
|
|
4420
|
+
}
|
|
4421
|
+
} else if (existingEntry) {
|
|
4422
|
+
existingEntry.status = commentRes?.status || "updated";
|
|
4423
|
+
if (!existingEntry.comments) existingEntry.comments = [];
|
|
4424
|
+
existingEntry.comments.push({
|
|
4425
|
+
id: commentRes?.id ?? Date.now(),
|
|
4426
|
+
author_label: commentRes?.comment?.author_label || "You",
|
|
4427
|
+
body: message || null,
|
|
4428
|
+
createdAt: this.formatTimestampLabel(commentRes?.created_at),
|
|
4429
|
+
attachments: submittedAttachments
|
|
4430
|
+
});
|
|
4431
|
+
}
|
|
4432
|
+
|
|
4433
|
+
this.cancelCommentingFeedback();
|
|
4434
|
+
this.showStatus("Comment added.", "success");
|
|
4435
|
+
this.emitWidgetEvent("context-drop:comment", {
|
|
4436
|
+
response: commentRes,
|
|
4437
|
+
payload: commentPayload
|
|
4438
|
+
});
|
|
4439
|
+
return;
|
|
4440
|
+
}
|
|
4441
|
+
|
|
4442
|
+
if (editingId !== null) {
|
|
4443
|
+
const existingIdx = this.sessionHistory.findIndex(
|
|
4444
|
+
(item) => String(item.id) === editingId
|
|
4445
|
+
);
|
|
4446
|
+
const existingEntry = existingIdx >= 0 ? this.sessionHistory[existingIdx] : undefined;
|
|
4447
|
+
|
|
4448
|
+
const updatePayload: FeedbackUpdatePayload = {
|
|
4449
|
+
message,
|
|
4450
|
+
metadata: commonMetadata,
|
|
4451
|
+
element_references: this.elementReferences,
|
|
4452
|
+
attachments: this.attachments.map((att) => {
|
|
4453
|
+
if (att.existing_attachment_id !== undefined && att.existing_attachment_id !== null) {
|
|
4454
|
+
return {
|
|
4455
|
+
existing_id: att.existing_attachment_id,
|
|
4456
|
+
attachment_type: att.attachment_type,
|
|
4457
|
+
element_reference_ref: att.element_reference_ref,
|
|
4458
|
+
metadata: att.metadata
|
|
4459
|
+
};
|
|
4460
|
+
}
|
|
4461
|
+
return {
|
|
4462
|
+
attachment_type: att.attachment_type,
|
|
4463
|
+
filename: att.filename,
|
|
4464
|
+
signed_blob_id: att.signed_blob_id,
|
|
4465
|
+
data_url: att.signed_blob_id ? undefined : att.data_url,
|
|
4466
|
+
element_reference_ref: att.element_reference_ref,
|
|
4467
|
+
metadata: att.metadata
|
|
4468
|
+
};
|
|
4469
|
+
})
|
|
4470
|
+
};
|
|
4471
|
+
|
|
4472
|
+
const updateRes = await this.apiClient.updateFeedback(
|
|
4473
|
+
existingEntry?.id ?? editingId,
|
|
4474
|
+
updatePayload,
|
|
4475
|
+
existingEntry?.ownershipToken
|
|
4476
|
+
);
|
|
4477
|
+
|
|
4478
|
+
const mergedPreviewStub: SessionFeedbackEntry = {
|
|
4479
|
+
id: existingEntry?.id ?? updateRes?.id ?? editingId,
|
|
4480
|
+
message:
|
|
4481
|
+
message || (smartMode ? "(Highlighted page area)" : "(Context drop without text)"),
|
|
4482
|
+
rawMessage: message,
|
|
4483
|
+
createdAt: existingEntry?.createdAt || this.formatTimestampLabel(updateRes?.created_at),
|
|
4484
|
+
rawCreatedAt: existingEntry?.rawCreatedAt || updateRes?.created_at,
|
|
4485
|
+
rawUpdatedAt: updateRes?.updated_at || new Date().toISOString(),
|
|
4486
|
+
isEdited: true,
|
|
4487
|
+
status: updateRes?.status || existingEntry?.status,
|
|
4488
|
+
ownershipToken:
|
|
4489
|
+
updateRes?.ownership_token ||
|
|
4490
|
+
updateRes?.feedback?.ownership_token ||
|
|
4491
|
+
existingEntry?.ownershipToken,
|
|
4492
|
+
elements: submittedElements,
|
|
4493
|
+
attachments: submittedAttachments
|
|
4494
|
+
};
|
|
4495
|
+
|
|
4496
|
+
const updatedEntry = updateRes?.feedback
|
|
4497
|
+
? {
|
|
4498
|
+
...this.mapOwnRecordToSessionEntry(updateRes.feedback, mergedPreviewStub),
|
|
4499
|
+
isEdited: true
|
|
4500
|
+
}
|
|
4501
|
+
: mergedPreviewStub;
|
|
4502
|
+
|
|
4503
|
+
if (existingIdx >= 0) {
|
|
4504
|
+
this.sessionHistory[existingIdx] = updatedEntry;
|
|
4505
|
+
} else {
|
|
4506
|
+
this.sessionHistory.push(updatedEntry);
|
|
4507
|
+
}
|
|
4508
|
+
|
|
4509
|
+
this.cancelEditingFeedback();
|
|
4510
|
+
this.showStatus(
|
|
4511
|
+
smartMode ? "Your feedback was updated." : "Feedback updated.",
|
|
4512
|
+
"success"
|
|
4513
|
+
);
|
|
4514
|
+
this.emitWidgetEvent("context-drop:update", {
|
|
4515
|
+
response: updateRes,
|
|
4516
|
+
payload: updatePayload
|
|
4517
|
+
});
|
|
4518
|
+
return;
|
|
4519
|
+
}
|
|
4520
|
+
|
|
3506
4521
|
const payload: FeedbackSubmissionPayload = {
|
|
3507
4522
|
message,
|
|
3508
4523
|
page_url: typeof window !== "undefined" ? window.location.href : "/",
|
|
3509
4524
|
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
|
|
3510
|
-
metadata:
|
|
3511
|
-
...this.customMetadata,
|
|
3512
|
-
environment: this.config.environment,
|
|
3513
|
-
selection_mode: smartMode ? "smart" : "verbose",
|
|
3514
|
-
viewport: {
|
|
3515
|
-
width: typeof window !== "undefined" ? window.innerWidth : 0,
|
|
3516
|
-
height: typeof window !== "undefined" ? window.innerHeight : 0
|
|
3517
|
-
},
|
|
3518
|
-
locale: typeof navigator !== "undefined" ? navigator.language : "en"
|
|
3519
|
-
},
|
|
4525
|
+
metadata: commonMetadata,
|
|
3520
4526
|
element_references: this.elementReferences,
|
|
3521
4527
|
attachments: this.attachments.map((att) => ({
|
|
3522
4528
|
attachment_type: att.attachment_type,
|
|
@@ -3532,14 +4538,26 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3532
4538
|
|
|
3533
4539
|
const now = new Date();
|
|
3534
4540
|
const timeLabel = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
|
|
3535
|
-
|
|
4541
|
+
const localStub: SessionFeedbackEntry = {
|
|
3536
4542
|
id: res?.id ?? this.sessionHistory.length + 1,
|
|
3537
4543
|
message:
|
|
3538
4544
|
message || (smartMode ? "(Highlighted page area)" : "(Context drop without text)"),
|
|
4545
|
+
rawMessage: message,
|
|
3539
4546
|
createdAt: timeLabel,
|
|
4547
|
+
rawCreatedAt: res?.created_at,
|
|
4548
|
+
rawUpdatedAt: res?.updated_at || res?.created_at,
|
|
4549
|
+
isEdited: false,
|
|
4550
|
+
status: res?.status,
|
|
4551
|
+
ownershipToken: res?.ownership_token || res?.feedback?.ownership_token,
|
|
3540
4552
|
elements: submittedElements,
|
|
3541
4553
|
attachments: submittedAttachments
|
|
3542
|
-
}
|
|
4554
|
+
};
|
|
4555
|
+
|
|
4556
|
+
const createdEntry = res?.feedback
|
|
4557
|
+
? this.mapOwnRecordToSessionEntry(res.feedback, localStub)
|
|
4558
|
+
: localStub;
|
|
4559
|
+
|
|
4560
|
+
this.sessionHistory.push(createdEntry);
|
|
3543
4561
|
|
|
3544
4562
|
if (this.textareaEl) {
|
|
3545
4563
|
this.textareaEl.value = "";
|
|
@@ -3555,15 +4573,34 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3555
4573
|
smartMode ? "Thanks! Your feedback was sent." : "Context drop saved.",
|
|
3556
4574
|
"success"
|
|
3557
4575
|
);
|
|
4576
|
+
this.emitWidgetEvent("context-drop:submit", {
|
|
4577
|
+
response: res,
|
|
4578
|
+
payload
|
|
4579
|
+
});
|
|
3558
4580
|
} catch (err) {
|
|
3559
|
-
const msg =
|
|
4581
|
+
const msg =
|
|
4582
|
+
err instanceof Error
|
|
4583
|
+
? err.message
|
|
4584
|
+
: editingId !== null
|
|
4585
|
+
? "Failed to update feedback."
|
|
4586
|
+
: "Failed to submit feedback.";
|
|
3560
4587
|
this.showStatus(msg, "error");
|
|
4588
|
+
this.emitWidgetEvent("context-drop:error", {
|
|
4589
|
+
error: msg
|
|
4590
|
+
});
|
|
3561
4591
|
} finally {
|
|
3562
4592
|
this.isSubmitting = false;
|
|
3563
4593
|
if (this.submitBtn) {
|
|
3564
4594
|
this.submitBtn.disabled = false;
|
|
3565
|
-
this.
|
|
4595
|
+
if (this.editingFeedbackId !== null) {
|
|
4596
|
+
this.submitBtn.setAttribute("aria-label", "Save feedback changes");
|
|
4597
|
+
this.submitBtn.innerHTML = `${ICON_CHECK}<span>Save</span>`;
|
|
4598
|
+
} else {
|
|
4599
|
+
this.submitBtn.setAttribute("aria-label", "Submit feedback");
|
|
4600
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Send</span>`;
|
|
4601
|
+
}
|
|
3566
4602
|
}
|
|
4603
|
+
this.renderChatThread();
|
|
3567
4604
|
}
|
|
3568
4605
|
}
|
|
3569
4606
|
|