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.
- package/README.md +6 -5
- package/app/assets/javascripts/context_drop/context_drop.js +1589 -99
- package/dist/app/javascript/context_drop/api-client.d.ts +14 -1
- package/dist/app/javascript/context_drop/api-client.js +217 -1
- package/dist/app/javascript/context_drop/icons.d.ts +3 -0
- package/dist/app/javascript/context_drop/icons.js +3 -0
- package/dist/app/javascript/context_drop/styles.d.ts +1 -1
- package/dist/app/javascript/context_drop/styles.js +311 -0
- package/dist/app/javascript/context_drop/types.d.ts +124 -6
- package/dist/app/javascript/context_drop/widget.d.ts +23 -0
- package/dist/app/javascript/context_drop/widget.js +847 -31
- package/dist/src/cli.js +1 -1
- package/dist/src/mcp/dispatcher.js +65 -12
- package/dist/src/next/index.d.ts +1 -1
- package/dist/src/react/index.d.ts +16 -2
- package/dist/src/react/index.js +21 -1
- package/dist/src/server/handler.d.ts +7 -1
- package/dist/src/server/handler.js +710 -81
- package/dist/src/server/storage/local.d.ts +1 -1
- package/dist/src/server/storage/local.js +434 -10
- package/dist/src/server/storage/memory.d.ts +4 -1
- package/dist/src/server/storage/memory.js +241 -3
- package/dist/src/server/storage/postgres.d.ts +1 -1
- package/dist/src/server/storage/postgres.js +303 -10
- package/dist/src/server/types.d.ts +65 -2
- package/dist/src/server/types.js +3 -2
- package/package.json +1 -1
|
@@ -883,6 +883,9 @@
|
|
|
883
883
|
const ICON_PUSH_LAYOUT = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="2.5" width="12" height="11" rx="1.8"/><line x1="9.5" y1="2.5" x2="9.5" y2="13.5"/><polyline points="6.5 6.2 4.7 8 6.5 9.8"/></svg>`;
|
|
884
884
|
const ICON_SUN = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="10" cy="10" r="3.75"/><line x1="10" y1="2" x2="10" y2="4"/><line x1="10" y1="16" x2="10" y2="18"/><line x1="2" y1="10" x2="4" y2="10"/><line x1="16" y1="10" x2="18" y2="10"/><line x1="4.34" y1="4.34" x2="5.75" y2="5.75"/><line x1="14.25" y1="14.25" x2="15.66" y2="15.66"/><line x1="4.34" y1="15.66" x2="5.75" y2="14.25"/><line x1="14.25" y1="5.75" x2="15.66" y2="4.34"/></svg>`;
|
|
885
885
|
const ICON_MOON = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17.2 12.8A7.5 7.5 0 0 1 7.2 2.8a7.5 7.5 0 1 0 10 10z"/></svg>`;
|
|
886
|
+
const ICON_EDIT = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11.2 2.5a1.5 1.5 0 0 1 2.1 2.1L5.8 12.1 2.7 13l.9-3.1 7.6-7.4z"/></svg>`;
|
|
887
|
+
const ICON_TRASH = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.8 4.5h10.4"/><path d="M6.2 4.5V3.2a.9.9 0 0 1 .9-.9h1.8a.9.9 0 0 1 .9.9v1.3"/><path d="M4.2 4.5l.6 8.3a1.2 1.2 0 0 0 1.2 1.1h4a1.2 1.2 0 0 0 1.2-1.1l.6-8.3"/></svg>`;
|
|
888
|
+
const ICON_COMMENT = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.5 10.2a1.3 1.3 0 0 1-1.3 1.3H5.4L2.5 14V3.8A1.3 1.3 0 0 1 3.8 2.5h8.4a1.3 1.3 0 0 1 1.3 1.3v6.4z"/></svg>`;
|
|
886
889
|
|
|
887
890
|
// --- Module: markdown.ts ---
|
|
888
891
|
/**
|
|
@@ -1160,6 +1163,47 @@
|
|
|
1160
1163
|
border-color: #3b4252;
|
|
1161
1164
|
}
|
|
1162
1165
|
|
|
1166
|
+
:host([data-cd-theme="dark"]) .cd-msg-action-btn:hover:not(:disabled),
|
|
1167
|
+
:host([data-theme="dark"]) .cd-msg-action-btn:hover:not(:disabled),
|
|
1168
|
+
.cd-composer[data-theme="dark"] .cd-msg-action-btn:hover:not(:disabled) {
|
|
1169
|
+
background: rgba(255, 255, 255, 0.09);
|
|
1170
|
+
color: var(--cd-ink);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
:host([data-cd-theme="dark"]) .cd-msg-action-btn.is-danger:hover:not(:disabled),
|
|
1174
|
+
:host([data-theme="dark"]) .cd-msg-action-btn.is-danger:hover:not(:disabled),
|
|
1175
|
+
.cd-composer[data-theme="dark"] .cd-msg-action-btn.is-danger:hover:not(:disabled) {
|
|
1176
|
+
background: var(--cd-danger-soft);
|
|
1177
|
+
color: #fca5a5;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
:host([data-cd-theme="dark"]) .cd-edit-banner-info,
|
|
1181
|
+
:host([data-theme="dark"]) .cd-edit-banner-info,
|
|
1182
|
+
.cd-composer[data-theme="dark"] .cd-edit-banner-info {
|
|
1183
|
+
color: var(--cd-ink);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
:host([data-cd-theme="dark"]) .cd-msg-delete-label,
|
|
1187
|
+
:host([data-theme="dark"]) .cd-msg-delete-label,
|
|
1188
|
+
.cd-composer[data-theme="dark"] .cd-msg-delete-label {
|
|
1189
|
+
color: #fca5a5;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
:host([data-cd-theme="dark"]) .cd-btn-danger,
|
|
1193
|
+
:host([data-theme="dark"]) .cd-btn-danger,
|
|
1194
|
+
.cd-composer[data-theme="dark"] .cd-btn-danger {
|
|
1195
|
+
background: #dc2626;
|
|
1196
|
+
border-color: #dc2626;
|
|
1197
|
+
color: #ffffff;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
:host([data-cd-theme="dark"]) .cd-btn-danger:hover:not(:disabled),
|
|
1201
|
+
:host([data-theme="dark"]) .cd-btn-danger:hover:not(:disabled),
|
|
1202
|
+
.cd-composer[data-theme="dark"] .cd-btn-danger:hover:not(:disabled) {
|
|
1203
|
+
background: #ef4444;
|
|
1204
|
+
border-color: #ef4444;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1163
1207
|
*, *::before, *::after {
|
|
1164
1208
|
box-sizing: border-box;
|
|
1165
1209
|
}
|
|
@@ -2022,11 +2066,18 @@
|
|
|
2022
2066
|
flex-direction: column;
|
|
2023
2067
|
gap: 5px;
|
|
2024
2068
|
align-self: flex-end;
|
|
2069
|
+
width: 92%;
|
|
2025
2070
|
max-width: 92%;
|
|
2026
2071
|
padding: 9px 11px;
|
|
2027
2072
|
background: var(--cd-surface-elevated);
|
|
2028
2073
|
border: 1px solid var(--cd-border);
|
|
2029
2074
|
border-radius: 12px 12px 3px 12px;
|
|
2075
|
+
transition: border-color 0.14s var(--cd-ease), box-shadow 0.14s var(--cd-ease);
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
.cd-chat-msg.is-editing {
|
|
2079
|
+
border-color: var(--cd-accent);
|
|
2080
|
+
box-shadow: 0 0 0 2px var(--cd-accent-soft);
|
|
2030
2081
|
}
|
|
2031
2082
|
|
|
2032
2083
|
.cd-chat-msg-text {
|
|
@@ -2047,6 +2098,83 @@
|
|
|
2047
2098
|
font-variant-numeric: tabular-nums;
|
|
2048
2099
|
}
|
|
2049
2100
|
|
|
2101
|
+
.cd-chat-msg-meta-info {
|
|
2102
|
+
display: inline-flex;
|
|
2103
|
+
align-items: center;
|
|
2104
|
+
gap: 6px;
|
|
2105
|
+
min-width: 0;
|
|
2106
|
+
flex-wrap: wrap;
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
.cd-chat-msg-actions {
|
|
2110
|
+
display: inline-flex;
|
|
2111
|
+
align-items: center;
|
|
2112
|
+
gap: 2px;
|
|
2113
|
+
flex-shrink: 0;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
.cd-msg-action-btn {
|
|
2117
|
+
appearance: none;
|
|
2118
|
+
display: inline-flex;
|
|
2119
|
+
align-items: center;
|
|
2120
|
+
justify-content: center;
|
|
2121
|
+
width: 24px;
|
|
2122
|
+
height: 24px;
|
|
2123
|
+
padding: 0;
|
|
2124
|
+
border: 1px solid transparent;
|
|
2125
|
+
border-radius: 6px;
|
|
2126
|
+
background: transparent;
|
|
2127
|
+
color: var(--cd-ink-secondary);
|
|
2128
|
+
cursor: pointer;
|
|
2129
|
+
transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
.cd-msg-action-btn:hover:not(:disabled) {
|
|
2133
|
+
background: rgba(17, 19, 24, 0.06);
|
|
2134
|
+
color: var(--cd-ink);
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
.cd-msg-action-btn.is-active {
|
|
2138
|
+
background: var(--cd-accent-soft);
|
|
2139
|
+
color: var(--cd-accent-hover);
|
|
2140
|
+
border-color: rgba(29, 78, 216, 0.25);
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
.cd-msg-action-btn.is-danger:hover:not(:disabled) {
|
|
2144
|
+
background: var(--cd-danger-soft);
|
|
2145
|
+
color: var(--cd-danger);
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
.cd-msg-action-btn:disabled {
|
|
2149
|
+
opacity: 0.4;
|
|
2150
|
+
cursor: not-allowed;
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
.cd-msg-delete-confirm {
|
|
2154
|
+
display: flex;
|
|
2155
|
+
align-items: center;
|
|
2156
|
+
justify-content: space-between;
|
|
2157
|
+
gap: 8px;
|
|
2158
|
+
margin-top: 2px;
|
|
2159
|
+
padding: 6px 8px;
|
|
2160
|
+
border-radius: 8px;
|
|
2161
|
+
background: var(--cd-danger-soft);
|
|
2162
|
+
border: 1px solid rgba(185, 28, 28, 0.24);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
.cd-msg-delete-label {
|
|
2166
|
+
font-size: 11.5px;
|
|
2167
|
+
font-weight: 600;
|
|
2168
|
+
color: var(--cd-danger);
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
.cd-msg-delete-btns {
|
|
2172
|
+
display: inline-flex;
|
|
2173
|
+
align-items: center;
|
|
2174
|
+
gap: 5px;
|
|
2175
|
+
flex-shrink: 0;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2050
2178
|
.cd-chat-msg-pills {
|
|
2051
2179
|
display: flex;
|
|
2052
2180
|
flex-wrap: wrap;
|
|
@@ -2069,6 +2197,136 @@
|
|
|
2069
2197
|
font-weight: 500;
|
|
2070
2198
|
}
|
|
2071
2199
|
|
|
2200
|
+
.cd-chat-msg.is-commenting {
|
|
2201
|
+
border-color: var(--cd-accent);
|
|
2202
|
+
box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.12);
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
.cd-msg-status-badge {
|
|
2206
|
+
display: inline-flex;
|
|
2207
|
+
align-items: center;
|
|
2208
|
+
padding: 1px 6px;
|
|
2209
|
+
border-radius: 999px;
|
|
2210
|
+
font-size: 10px;
|
|
2211
|
+
font-weight: 600;
|
|
2212
|
+
text-transform: capitalize;
|
|
2213
|
+
letter-spacing: 0.01em;
|
|
2214
|
+
border: 1px solid transparent;
|
|
2215
|
+
line-height: 1.4;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
.cd-msg-status-badge.is-new {
|
|
2219
|
+
background: #eff6ff;
|
|
2220
|
+
border-color: #bfdbfe;
|
|
2221
|
+
color: #1d4ed8;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
.cd-msg-status-badge.is-updated {
|
|
2225
|
+
background: #fffbeb;
|
|
2226
|
+
border-color: #fde68a;
|
|
2227
|
+
color: #b45309;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
.cd-msg-status-badge.is-fixed {
|
|
2231
|
+
background: #eef2ff;
|
|
2232
|
+
border-color: #c7d2fe;
|
|
2233
|
+
color: #4338ca;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
.cd-msg-status-badge.is-reviewed {
|
|
2237
|
+
background: #f0fdf4;
|
|
2238
|
+
border-color: #bbf7d0;
|
|
2239
|
+
color: #15803d;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
.cd-msg-status-badge.is-dismissed {
|
|
2243
|
+
background: #f8fafc;
|
|
2244
|
+
border-color: #e2e8f0;
|
|
2245
|
+
color: #64748b;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
.cd-review-btn {
|
|
2249
|
+
display: inline-flex;
|
|
2250
|
+
align-items: center;
|
|
2251
|
+
gap: 4px;
|
|
2252
|
+
padding: 2px 7px;
|
|
2253
|
+
border-radius: 5px;
|
|
2254
|
+
border: 1px solid #bbf7d0;
|
|
2255
|
+
background: #f0fdf4;
|
|
2256
|
+
color: #15803d;
|
|
2257
|
+
font-family: inherit;
|
|
2258
|
+
font-size: 10.5px;
|
|
2259
|
+
font-weight: 600;
|
|
2260
|
+
cursor: pointer;
|
|
2261
|
+
transition: background 0.12s ease, border-color 0.12s ease;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
.cd-review-btn:hover:not(:disabled) {
|
|
2265
|
+
background: #dcfce7;
|
|
2266
|
+
border-color: #86efac;
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
.cd-review-btn:disabled {
|
|
2270
|
+
opacity: 0.5;
|
|
2271
|
+
cursor: default;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
.cd-comments-list {
|
|
2275
|
+
display: flex;
|
|
2276
|
+
flex-direction: column;
|
|
2277
|
+
gap: 6px;
|
|
2278
|
+
margin-top: 6px;
|
|
2279
|
+
padding-top: 6px;
|
|
2280
|
+
border-top: 1px dashed var(--cd-border-subtle);
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
.cd-comment-item {
|
|
2284
|
+
background: var(--cd-surface-recessed);
|
|
2285
|
+
border: 1px solid var(--cd-border-subtle);
|
|
2286
|
+
border-radius: 6px;
|
|
2287
|
+
padding: 6px 8px;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
.cd-comment-header {
|
|
2291
|
+
display: flex;
|
|
2292
|
+
align-items: center;
|
|
2293
|
+
justify-content: space-between;
|
|
2294
|
+
gap: 6px;
|
|
2295
|
+
font-size: 10.5px;
|
|
2296
|
+
color: var(--cd-muted);
|
|
2297
|
+
margin-bottom: 2px;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
.cd-comment-author {
|
|
2301
|
+
font-weight: 600;
|
|
2302
|
+
color: var(--cd-ink);
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
.cd-comment-body {
|
|
2306
|
+
margin: 0;
|
|
2307
|
+
font-size: 11.5px;
|
|
2308
|
+
line-height: 1.42;
|
|
2309
|
+
color: var(--cd-ink);
|
|
2310
|
+
white-space: pre-wrap;
|
|
2311
|
+
word-break: break-word;
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
.cd-comment-images {
|
|
2315
|
+
display: flex;
|
|
2316
|
+
flex-wrap: wrap;
|
|
2317
|
+
gap: 5px;
|
|
2318
|
+
margin-top: 5px;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
.cd-comment-thumb {
|
|
2322
|
+
width: 48px;
|
|
2323
|
+
height: 48px;
|
|
2324
|
+
object-fit: cover;
|
|
2325
|
+
border-radius: 4px;
|
|
2326
|
+
border: 1px solid var(--cd-border);
|
|
2327
|
+
display: block;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2072
2330
|
/* ==========================================================================
|
|
2073
2331
|
4. LOCAL BYOK AGENTIC CODING SIDEBAR (.cd-agent-sidebar)
|
|
2074
2332
|
========================================================================== */
|
|
@@ -2931,6 +3189,42 @@
|
|
|
2931
3189
|
border-top: 1px solid var(--cd-border);
|
|
2932
3190
|
}
|
|
2933
3191
|
|
|
3192
|
+
.cd-edit-banner {
|
|
3193
|
+
display: flex;
|
|
3194
|
+
align-items: center;
|
|
3195
|
+
justify-content: space-between;
|
|
3196
|
+
gap: 8px;
|
|
3197
|
+
padding: 6px 12px;
|
|
3198
|
+
background: var(--cd-accent-soft);
|
|
3199
|
+
border-bottom: 1px solid var(--cd-border-subtle);
|
|
3200
|
+
font-size: 12px;
|
|
3201
|
+
color: var(--cd-ink);
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
.cd-edit-banner[hidden] {
|
|
3205
|
+
display: none !important;
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
.cd-edit-banner-info {
|
|
3209
|
+
display: inline-flex;
|
|
3210
|
+
align-items: center;
|
|
3211
|
+
gap: 6px;
|
|
3212
|
+
min-width: 0;
|
|
3213
|
+
font-weight: 600;
|
|
3214
|
+
color: var(--cd-accent-hover);
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
.cd-edit-banner-info svg {
|
|
3218
|
+
color: var(--cd-accent-hover);
|
|
3219
|
+
flex-shrink: 0;
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
.cd-edit-banner-id {
|
|
3223
|
+
font-family: var(--cd-mono);
|
|
3224
|
+
font-size: 11px;
|
|
3225
|
+
font-variant-numeric: tabular-nums;
|
|
3226
|
+
}
|
|
3227
|
+
|
|
2934
3228
|
.cd-textarea {
|
|
2935
3229
|
width: 100%;
|
|
2936
3230
|
min-height: 68px;
|
|
@@ -3011,6 +3305,24 @@
|
|
|
3011
3305
|
border-color: #252a34;
|
|
3012
3306
|
}
|
|
3013
3307
|
|
|
3308
|
+
.cd-btn-xs {
|
|
3309
|
+
padding: 3px 8px;
|
|
3310
|
+
font-size: 11.5px;
|
|
3311
|
+
border-radius: 6px;
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
.cd-btn-danger {
|
|
3315
|
+
background: var(--cd-danger);
|
|
3316
|
+
border-color: var(--cd-danger);
|
|
3317
|
+
color: #ffffff;
|
|
3318
|
+
font-weight: 600;
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
.cd-btn-danger:hover:not(:disabled) {
|
|
3322
|
+
background: #991b1b;
|
|
3323
|
+
border-color: #991b1b;
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3014
3326
|
@media (max-width: 560px) {
|
|
3015
3327
|
.cd-composer,
|
|
3016
3328
|
.cd-compact-bar {
|
|
@@ -3038,6 +3350,8 @@
|
|
|
3038
3350
|
.cd-corner-flap,
|
|
3039
3351
|
.cd-drag-pin-head,
|
|
3040
3352
|
.cd-composer,
|
|
3353
|
+
.cd-chat-msg,
|
|
3354
|
+
.cd-msg-action-btn,
|
|
3041
3355
|
.cd-agent-sidebar,
|
|
3042
3356
|
.cd-skeleton-bar {
|
|
3043
3357
|
animation: none !important;
|
|
@@ -3047,6 +3361,22 @@
|
|
|
3047
3361
|
`;
|
|
3048
3362
|
|
|
3049
3363
|
// --- Module: api-client.ts ---
|
|
3364
|
+
const OWNERSHIP_STORAGE_KEY = "context_drop_ownership_tokens";
|
|
3365
|
+
const MAX_STORED_OWNERSHIP_TOKENS = 50;
|
|
3366
|
+
|
|
3367
|
+
function getBrowserLocalStorage() {
|
|
3368
|
+
try {
|
|
3369
|
+
if (typeof window !== "undefined" && "localStorage" in window) {
|
|
3370
|
+
const store = window.localStorage;
|
|
3371
|
+
if (store && typeof store.getItem === "function" && typeof store.setItem === "function") {
|
|
3372
|
+
return store;
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
} catch {
|
|
3376
|
+
// Storage unavailable or restricted by browser privacy policy
|
|
3377
|
+
}
|
|
3378
|
+
return null;
|
|
3379
|
+
}
|
|
3050
3380
|
class ContextDropApiClient {
|
|
3051
3381
|
baseUrl ;
|
|
3052
3382
|
credentials ;
|
|
@@ -3054,6 +3384,7 @@
|
|
|
3054
3384
|
cachedCsrfToken = null;
|
|
3055
3385
|
configFetched = false;
|
|
3056
3386
|
inFlightConfigPromise = null;
|
|
3387
|
+
memoryOwnershipTokens = new Map();
|
|
3057
3388
|
|
|
3058
3389
|
constructor(baseUrl = "/context_drop", options = {}) {
|
|
3059
3390
|
this.baseUrl = baseUrl.replace(/\/+$/, "") || "/context_drop";
|
|
@@ -3270,6 +3601,113 @@
|
|
|
3270
3601
|
return this.executeWithCsrfRetry(makeRequest, "Upload failed");
|
|
3271
3602
|
}
|
|
3272
3603
|
|
|
3604
|
+
ownershipScopedKey(id ) {
|
|
3605
|
+
return `${this.baseUrl}::${String(id)}`;
|
|
3606
|
+
}
|
|
3607
|
+
|
|
3608
|
+
readStoredTokenMap() {
|
|
3609
|
+
const store = getBrowserLocalStorage();
|
|
3610
|
+
if (!store) {
|
|
3611
|
+
const out = {};
|
|
3612
|
+
for (const [k, v] of this.memoryOwnershipTokens.entries()) {
|
|
3613
|
+
out[k] = v;
|
|
3614
|
+
}
|
|
3615
|
+
return out;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
try {
|
|
3619
|
+
const raw = store.getItem(OWNERSHIP_STORAGE_KEY);
|
|
3620
|
+
if (!raw) return {};
|
|
3621
|
+
const parsed = JSON.parse(raw) ;
|
|
3622
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
3623
|
+
return {};
|
|
3624
|
+
}
|
|
3625
|
+
const clean = {};
|
|
3626
|
+
for (const [k, v] of Object.entries(parsed )) {
|
|
3627
|
+
if (typeof v === "string" && v.trim().length > 0) {
|
|
3628
|
+
clean[k] = v.trim();
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
return clean;
|
|
3632
|
+
} catch {
|
|
3633
|
+
return {};
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
|
|
3637
|
+
writeStoredTokenMap(map ) {
|
|
3638
|
+
const entries = Object.entries(map);
|
|
3639
|
+
const trimmedEntries =
|
|
3640
|
+
entries.length > MAX_STORED_OWNERSHIP_TOKENS
|
|
3641
|
+
? entries.slice(entries.length - MAX_STORED_OWNERSHIP_TOKENS)
|
|
3642
|
+
: entries;
|
|
3643
|
+
|
|
3644
|
+
this.memoryOwnershipTokens.clear();
|
|
3645
|
+
const bounded = {};
|
|
3646
|
+
for (const [k, v] of trimmedEntries) {
|
|
3647
|
+
bounded[k] = v;
|
|
3648
|
+
this.memoryOwnershipTokens.set(k, v);
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
const store = getBrowserLocalStorage();
|
|
3652
|
+
if (store) {
|
|
3653
|
+
try {
|
|
3654
|
+
store.setItem(OWNERSHIP_STORAGE_KEY, JSON.stringify(bounded));
|
|
3655
|
+
} catch {
|
|
3656
|
+
// Non-fatal if storage quota exceeded
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
getOwnershipToken(id ) {
|
|
3662
|
+
const map = this.readStoredTokenMap();
|
|
3663
|
+
const scoped = map[this.ownershipScopedKey(id)];
|
|
3664
|
+
if (scoped) return scoped;
|
|
3665
|
+
const plain = map[String(id)];
|
|
3666
|
+
return plain || null;
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
setOwnershipToken(id , token ) {
|
|
3670
|
+
const trimmed = typeof token === "string" ? token.trim() : "";
|
|
3671
|
+
if (!trimmed) return;
|
|
3672
|
+
const map = this.readStoredTokenMap();
|
|
3673
|
+
const key = this.ownershipScopedKey(id);
|
|
3674
|
+
delete map[key];
|
|
3675
|
+
map[key] = trimmed;
|
|
3676
|
+
this.writeStoredTokenMap(map);
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3679
|
+
removeOwnershipToken(id ) {
|
|
3680
|
+
const map = this.readStoredTokenMap();
|
|
3681
|
+
const scopedKey = this.ownershipScopedKey(id);
|
|
3682
|
+
const plainKey = String(id);
|
|
3683
|
+
if (!(scopedKey in map) && !(plainKey in map)) return;
|
|
3684
|
+
delete map[scopedKey];
|
|
3685
|
+
delete map[plainKey];
|
|
3686
|
+
this.writeStoredTokenMap(map);
|
|
3687
|
+
}
|
|
3688
|
+
|
|
3689
|
+
getAllOwnershipTokens() {
|
|
3690
|
+
const map = this.readStoredTokenMap();
|
|
3691
|
+
const prefix = `${this.baseUrl}::`;
|
|
3692
|
+
const tokens = [];
|
|
3693
|
+
for (const [k, v] of Object.entries(map)) {
|
|
3694
|
+
if ((k.startsWith(prefix) || !k.includes("::")) && v && !tokens.includes(v)) {
|
|
3695
|
+
tokens.push(v);
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
return tokens;
|
|
3699
|
+
}
|
|
3700
|
+
|
|
3701
|
+
buildAttachmentPreviewUrl(
|
|
3702
|
+
feedbackId ,
|
|
3703
|
+
attachmentId ,
|
|
3704
|
+
ownershipToken
|
|
3705
|
+
) {
|
|
3706
|
+
const token = ownershipToken || this.getOwnershipToken(feedbackId);
|
|
3707
|
+
const base = `${this.baseUrl}/feedback/${encodeURIComponent(String(feedbackId))}/attachments/${encodeURIComponent(String(attachmentId))}`;
|
|
3708
|
+
return token ? `${base}?ownership_token=${encodeURIComponent(token)}` : base;
|
|
3709
|
+
}
|
|
3710
|
+
|
|
3273
3711
|
async submitFeedback(payload ) {
|
|
3274
3712
|
const makeRequest = async (csrfToken ) =>
|
|
3275
3713
|
fetch(`${this.baseUrl}/feedback`, {
|
|
@@ -3279,7 +3717,149 @@
|
|
|
3279
3717
|
body: JSON.stringify({ feedback: payload })
|
|
3280
3718
|
});
|
|
3281
3719
|
|
|
3282
|
-
|
|
3720
|
+
const response = await this.executeWithCsrfRetry (
|
|
3721
|
+
makeRequest,
|
|
3722
|
+
"Submission failed"
|
|
3723
|
+
);
|
|
3724
|
+
|
|
3725
|
+
const token = response?.ownership_token || response?.feedback?.ownership_token;
|
|
3726
|
+
if (response?.id !== undefined && token) {
|
|
3727
|
+
this.setOwnershipToken(response.id, token);
|
|
3728
|
+
}
|
|
3729
|
+
return response;
|
|
3730
|
+
}
|
|
3731
|
+
|
|
3732
|
+
async fetchOwnFeedbacks(limit = 30) {
|
|
3733
|
+
const headers = {
|
|
3734
|
+
Accept: "application/json"
|
|
3735
|
+
};
|
|
3736
|
+
const tokens = this.getAllOwnershipTokens();
|
|
3737
|
+
if (tokens.length > 0) {
|
|
3738
|
+
headers["X-Context-Drop-Ownership-Tokens"] = tokens.join(",");
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3741
|
+
const qs = limit > 0 ? `?limit=${encodeURIComponent(String(limit))}` : "";
|
|
3742
|
+
const response = await fetch(`${this.baseUrl}/feedback${qs}`, {
|
|
3743
|
+
method: "GET",
|
|
3744
|
+
credentials: this.credentials,
|
|
3745
|
+
headers: this.mergeClientHeaders(headers)
|
|
3746
|
+
});
|
|
3747
|
+
|
|
3748
|
+
if (!response.ok) {
|
|
3749
|
+
const errBody = await response.json().catch(() => ({}));
|
|
3750
|
+
throw new Error(
|
|
3751
|
+
(errBody ).error || `Failed to load own feedbacks (${response.status})`
|
|
3752
|
+
);
|
|
3753
|
+
}
|
|
3754
|
+
|
|
3755
|
+
const parsed = (await response.json().catch(() => ({}))) ;
|
|
3756
|
+
const feedbacks = Array.isArray(parsed?.feedbacks) ? parsed.feedbacks : [];
|
|
3757
|
+
for (const item of feedbacks) {
|
|
3758
|
+
if (item && item.id !== undefined && typeof item.ownership_token === "string") {
|
|
3759
|
+
this.setOwnershipToken(item.id, item.ownership_token);
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3763
|
+
return {
|
|
3764
|
+
total_count: typeof parsed?.total_count === "number" ? parsed.total_count : feedbacks.length,
|
|
3765
|
+
feedbacks
|
|
3766
|
+
};
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
async updateFeedback(
|
|
3770
|
+
id ,
|
|
3771
|
+
payload ,
|
|
3772
|
+
ownershipToken
|
|
3773
|
+
) {
|
|
3774
|
+
const resolvedToken = ownershipToken || this.getOwnershipToken(id);
|
|
3775
|
+
const makeRequest = async (csrfToken ) => {
|
|
3776
|
+
const headers = this.buildJsonHeaders(csrfToken);
|
|
3777
|
+
if (resolvedToken) {
|
|
3778
|
+
headers["X-Context-Drop-Ownership-Token"] = resolvedToken;
|
|
3779
|
+
}
|
|
3780
|
+
const bodyPayload = { feedback: payload };
|
|
3781
|
+
if (resolvedToken) {
|
|
3782
|
+
bodyPayload.ownership_token = resolvedToken;
|
|
3783
|
+
}
|
|
3784
|
+
return fetch(`${this.baseUrl}/feedback/${encodeURIComponent(String(id))}`, {
|
|
3785
|
+
method: "PATCH",
|
|
3786
|
+
credentials: this.credentials,
|
|
3787
|
+
headers,
|
|
3788
|
+
body: JSON.stringify(bodyPayload)
|
|
3789
|
+
});
|
|
3790
|
+
};
|
|
3791
|
+
|
|
3792
|
+
const response = await this.executeWithCsrfRetry (
|
|
3793
|
+
makeRequest,
|
|
3794
|
+
"Update failed"
|
|
3795
|
+
);
|
|
3796
|
+
|
|
3797
|
+
const nextToken = response?.ownership_token || response?.feedback?.ownership_token;
|
|
3798
|
+
if (response?.id !== undefined && nextToken) {
|
|
3799
|
+
this.setOwnershipToken(response.id, nextToken);
|
|
3800
|
+
}
|
|
3801
|
+
return response;
|
|
3802
|
+
}
|
|
3803
|
+
|
|
3804
|
+
async createComment(
|
|
3805
|
+
id ,
|
|
3806
|
+
payload ,
|
|
3807
|
+
ownershipToken
|
|
3808
|
+
) {
|
|
3809
|
+
const resolvedToken = ownershipToken || this.getOwnershipToken(id);
|
|
3810
|
+
const makeRequest = async (csrfToken ) => {
|
|
3811
|
+
const headers = this.buildJsonHeaders(csrfToken);
|
|
3812
|
+
if (resolvedToken) {
|
|
3813
|
+
headers["X-Context-Drop-Ownership-Token"] = resolvedToken;
|
|
3814
|
+
}
|
|
3815
|
+
const bodyPayload = { comment: payload };
|
|
3816
|
+
if (resolvedToken) {
|
|
3817
|
+
bodyPayload.ownership_token = resolvedToken;
|
|
3818
|
+
}
|
|
3819
|
+
return fetch(`${this.baseUrl}/feedback/${encodeURIComponent(String(id))}/comments`, {
|
|
3820
|
+
method: "POST",
|
|
3821
|
+
credentials: this.credentials,
|
|
3822
|
+
headers,
|
|
3823
|
+
body: JSON.stringify(bodyPayload)
|
|
3824
|
+
});
|
|
3825
|
+
};
|
|
3826
|
+
|
|
3827
|
+
const response = await this.executeWithCsrfRetry (
|
|
3828
|
+
makeRequest,
|
|
3829
|
+
"Comment failed"
|
|
3830
|
+
);
|
|
3831
|
+
|
|
3832
|
+
const nextToken = response?.feedback?.ownership_token;
|
|
3833
|
+
if (response?.feedback?.id !== undefined && nextToken) {
|
|
3834
|
+
this.setOwnershipToken(response.feedback.id, nextToken);
|
|
3835
|
+
}
|
|
3836
|
+
return response;
|
|
3837
|
+
}
|
|
3838
|
+
|
|
3839
|
+
async deleteFeedback(
|
|
3840
|
+
id ,
|
|
3841
|
+
ownershipToken
|
|
3842
|
+
) {
|
|
3843
|
+
const resolvedToken = ownershipToken || this.getOwnershipToken(id);
|
|
3844
|
+
const makeRequest = async (csrfToken ) => {
|
|
3845
|
+
const headers = this.buildJsonHeaders(csrfToken);
|
|
3846
|
+
if (resolvedToken) {
|
|
3847
|
+
headers["X-Context-Drop-Ownership-Token"] = resolvedToken;
|
|
3848
|
+
}
|
|
3849
|
+
return fetch(`${this.baseUrl}/feedback/${encodeURIComponent(String(id))}`, {
|
|
3850
|
+
method: "DELETE",
|
|
3851
|
+
credentials: this.credentials,
|
|
3852
|
+
headers
|
|
3853
|
+
});
|
|
3854
|
+
};
|
|
3855
|
+
|
|
3856
|
+
const response = await this.executeWithCsrfRetry (
|
|
3857
|
+
makeRequest,
|
|
3858
|
+
"Delete failed"
|
|
3859
|
+
);
|
|
3860
|
+
|
|
3861
|
+
this.removeOwnershipToken(id);
|
|
3862
|
+
return response;
|
|
3283
3863
|
}
|
|
3284
3864
|
|
|
3285
3865
|
async fetchAgentStatus() {
|
|
@@ -5409,6 +5989,19 @@
|
|
|
5409
5989
|
elementDomNodes = new Map();
|
|
5410
5990
|
attachments = [];
|
|
5411
5991
|
sessionHistory = [];
|
|
5992
|
+
ownFeedbacksLoaded = false;
|
|
5993
|
+
inFlightOwnFeedbacksPromise = null;
|
|
5994
|
+
editingFeedbackId = null;
|
|
5995
|
+
commentingFeedbackId = null;
|
|
5996
|
+
reviewingFeedbackId = null;
|
|
5997
|
+
confirmingDeleteId = null;
|
|
5998
|
+
deletingFeedbackId = null;
|
|
5999
|
+
stashedDraftBeforeEdit
|
|
6000
|
+
|
|
6001
|
+
|
|
6002
|
+
|
|
6003
|
+
|
|
6004
|
+
= null;
|
|
5412
6005
|
|
|
5413
6006
|
// Local Agent state
|
|
5414
6007
|
agentStatusLoaded = false;
|
|
@@ -5451,6 +6044,8 @@
|
|
|
5451
6044
|
composerToolbarScreenshotBtn = null;
|
|
5452
6045
|
composerToolbarUploadBtn = null;
|
|
5453
6046
|
chatThreadEl = null;
|
|
6047
|
+
editBannerEl = null;
|
|
6048
|
+
editBannerInfoEl = null;
|
|
5454
6049
|
textareaEl = null;
|
|
5455
6050
|
trayEl = null;
|
|
5456
6051
|
statusEl = null;
|
|
@@ -5566,6 +6161,25 @@
|
|
|
5566
6161
|
return;
|
|
5567
6162
|
}
|
|
5568
6163
|
|
|
6164
|
+
if (
|
|
6165
|
+
ev.key === "Escape" &&
|
|
6166
|
+
!(this.picker && this.picker.isActive()) &&
|
|
6167
|
+
this.isOpen &&
|
|
6168
|
+
!this.isMinimized &&
|
|
6169
|
+
!this.isAgentModeActive()
|
|
6170
|
+
) {
|
|
6171
|
+
if (this.confirmingDeleteId !== null) {
|
|
6172
|
+
ev.preventDefault();
|
|
6173
|
+
this.cancelDeleteFeedback();
|
|
6174
|
+
return;
|
|
6175
|
+
}
|
|
6176
|
+
if (this.editingFeedbackId !== null) {
|
|
6177
|
+
ev.preventDefault();
|
|
6178
|
+
this.cancelEditingFeedback();
|
|
6179
|
+
return;
|
|
6180
|
+
}
|
|
6181
|
+
}
|
|
6182
|
+
|
|
5569
6183
|
// Alt+Shift+P / Option+Shift+P toggles Freeze & Pin mode in technical/verbose environments
|
|
5570
6184
|
if (
|
|
5571
6185
|
!this.isSmartSelectionMode() &&
|
|
@@ -5687,107 +6301,530 @@
|
|
|
5687
6301
|
"same-origin";
|
|
5688
6302
|
const resolvedHeaders = options.headers || this.customHeaders;
|
|
5689
6303
|
this.customHeaders = { ...resolvedHeaders };
|
|
6304
|
+
this.ownFeedbacksLoaded = false;
|
|
6305
|
+
this.inFlightOwnFeedbacksPromise = null;
|
|
5690
6306
|
this.apiClient = new ContextDropApiClient(endpoint || "/context_drop", {
|
|
5691
6307
|
credentials: resolvedCredentials,
|
|
5692
6308
|
headers: this.customHeaders
|
|
5693
6309
|
});
|
|
5694
6310
|
}
|
|
5695
6311
|
|
|
5696
|
-
setHeaders(headers ) {
|
|
5697
|
-
this.customHeaders = { ...headers };
|
|
5698
|
-
this.apiClient.setHeaders(this.customHeaders);
|
|
5699
|
-
}
|
|
6312
|
+
setHeaders(headers ) {
|
|
6313
|
+
this.customHeaders = { ...headers };
|
|
6314
|
+
this.apiClient.setHeaders(this.customHeaders);
|
|
6315
|
+
}
|
|
6316
|
+
|
|
6317
|
+
setCredentials(credentials ) {
|
|
6318
|
+
this.apiClient.setCredentials(credentials);
|
|
6319
|
+
}
|
|
6320
|
+
|
|
6321
|
+
setCustomMetadata(metadata ) {
|
|
6322
|
+
this.customMetadata = { ...metadata };
|
|
6323
|
+
}
|
|
6324
|
+
|
|
6325
|
+
emitWidgetEvent(name , detail ) {
|
|
6326
|
+
if (typeof CustomEvent !== "function" || typeof this.dispatchEvent !== "function") {
|
|
6327
|
+
return;
|
|
6328
|
+
}
|
|
6329
|
+
try {
|
|
6330
|
+
this.dispatchEvent(
|
|
6331
|
+
new CustomEvent(name, {
|
|
6332
|
+
bubbles: true,
|
|
6333
|
+
composed: true,
|
|
6334
|
+
detail
|
|
6335
|
+
})
|
|
6336
|
+
);
|
|
6337
|
+
} catch {
|
|
6338
|
+
// Non-fatal in synthetic DOM environments
|
|
6339
|
+
}
|
|
6340
|
+
}
|
|
6341
|
+
|
|
6342
|
+
setWidgetConfig(partial ) {
|
|
6343
|
+
const wasAgentEnabled = Boolean(this.config.agent?.enabled);
|
|
6344
|
+
if (
|
|
6345
|
+
typeof partial.placeholder === "string" &&
|
|
6346
|
+
partial.placeholder !== DEFAULT_VERBOSE_PLACEHOLDER &&
|
|
6347
|
+
partial.placeholder !== DEFAULT_SMART_PLACEHOLDER
|
|
6348
|
+
) {
|
|
6349
|
+
this.customPlaceholderSet = true;
|
|
6350
|
+
}
|
|
6351
|
+
this.config = {
|
|
6352
|
+
...this.config,
|
|
6353
|
+
...partial,
|
|
6354
|
+
agent: { ...(this.config.agent || { enabled: false }), ...(partial.agent || {}) },
|
|
6355
|
+
features: { ...this.config.features, ...(partial.features || {}) },
|
|
6356
|
+
limits: { ...this.config.limits, ...(partial.limits || {}) },
|
|
6357
|
+
privacy: { ...this.config.privacy, ...(partial.privacy || {}) }
|
|
6358
|
+
};
|
|
6359
|
+
if (partial.csrf_token) {
|
|
6360
|
+
this.apiClient.setCsrfToken(partial.csrf_token);
|
|
6361
|
+
}
|
|
6362
|
+
if (partial.position) {
|
|
6363
|
+
this.setCornerPosition(partial.position);
|
|
6364
|
+
}
|
|
6365
|
+
const nowAgentEnabled = Boolean(this.config.agent?.enabled);
|
|
6366
|
+
if (nowAgentEnabled && !wasAgentEnabled) {
|
|
6367
|
+
this.surfaceMode = "agent";
|
|
6368
|
+
if (this.isOpen) {
|
|
6369
|
+
void this.ensureAgentStatusLoaded();
|
|
6370
|
+
}
|
|
6371
|
+
} else if (!nowAgentEnabled) {
|
|
6372
|
+
this.surfaceMode = "feedback";
|
|
6373
|
+
}
|
|
6374
|
+
this.renderTray();
|
|
6375
|
+
this.renderChatThread();
|
|
6376
|
+
this.syncUiStates();
|
|
6377
|
+
}
|
|
6378
|
+
|
|
6379
|
+
getSurfaceMode() {
|
|
6380
|
+
return this.isAgentModeActive() ? "agent" : "feedback";
|
|
6381
|
+
}
|
|
6382
|
+
|
|
6383
|
+
setSurfaceMode(mode ) {
|
|
6384
|
+
if (mode === "agent" && !this.config.agent?.enabled) {
|
|
6385
|
+
return;
|
|
6386
|
+
}
|
|
6387
|
+
this.surfaceMode = mode;
|
|
6388
|
+
if (this.isOpen) {
|
|
6389
|
+
if (mode === "agent") {
|
|
6390
|
+
void this.ensureAgentStatusLoaded();
|
|
6391
|
+
} else if (!this.isMinimized) {
|
|
6392
|
+
void this.ensureOwnFeedbacksLoaded();
|
|
6393
|
+
}
|
|
6394
|
+
}
|
|
6395
|
+
this.renderTray();
|
|
6396
|
+
this.renderChatThread();
|
|
6397
|
+
this.syncUiStates();
|
|
6398
|
+
this.focusActiveInput();
|
|
6399
|
+
}
|
|
6400
|
+
|
|
6401
|
+
getElementReferences() {
|
|
6402
|
+
return [...this.elementReferences];
|
|
6403
|
+
}
|
|
6404
|
+
|
|
6405
|
+
getAttachments() {
|
|
6406
|
+
return [...this.attachments];
|
|
6407
|
+
}
|
|
6408
|
+
|
|
6409
|
+
getSessionHistory() {
|
|
6410
|
+
return [...this.sessionHistory];
|
|
6411
|
+
}
|
|
6412
|
+
|
|
6413
|
+
getEditingFeedbackId() {
|
|
6414
|
+
return this.editingFeedbackId;
|
|
6415
|
+
}
|
|
6416
|
+
|
|
6417
|
+
formatTimestampLabel(isoOrLabel ) {
|
|
6418
|
+
if (isoOrLabel && /^\d{2}:\d{2}$/.test(isoOrLabel.trim())) {
|
|
6419
|
+
return isoOrLabel.trim();
|
|
6420
|
+
}
|
|
6421
|
+
const parsed = isoOrLabel ? new Date(isoOrLabel) : new Date();
|
|
6422
|
+
const valid = Number.isNaN(parsed.getTime()) ? new Date() : parsed;
|
|
6423
|
+
return `${String(valid.getHours()).padStart(2, "0")}:${String(valid.getMinutes()).padStart(2, "0")}`;
|
|
6424
|
+
}
|
|
6425
|
+
|
|
6426
|
+
mapOwnRecordToSessionEntry(
|
|
6427
|
+
record ,
|
|
6428
|
+
existingEntry
|
|
6429
|
+
) {
|
|
6430
|
+
const smartMode = this.isSmartSelectionMode();
|
|
6431
|
+
const rawMessage = typeof record.message === "string" ? record.message : "";
|
|
6432
|
+
const displayMessage =
|
|
6433
|
+
rawMessage || (smartMode ? "(Highlighted page area)" : "(Context drop without text)");
|
|
6434
|
+
const token =
|
|
6435
|
+
record.ownership_token ||
|
|
6436
|
+
existingEntry?.ownershipToken ||
|
|
6437
|
+
this.apiClient.getOwnershipToken(record.id) ||
|
|
6438
|
+
undefined;
|
|
6439
|
+
const isEdited = Boolean(
|
|
6440
|
+
record.created_at && record.updated_at && record.updated_at !== record.created_at
|
|
6441
|
+
);
|
|
6442
|
+
|
|
6443
|
+
const serverAttachments = Array.isArray(record.attachments) ? record.attachments : [];
|
|
6444
|
+
const mappedAttachments = serverAttachments.map((att, idx) => {
|
|
6445
|
+
const existingAtt = existingEntry?.attachments.find(
|
|
6446
|
+
(a) =>
|
|
6447
|
+
(a.server_id !== undefined && String(a.server_id) === String(att.id)) ||
|
|
6448
|
+
(a.server_id === undefined &&
|
|
6449
|
+
idx < (existingEntry?.attachments.length || 0) &&
|
|
6450
|
+
existingEntry?.attachments[idx]?.filename === att.filename)
|
|
6451
|
+
);
|
|
6452
|
+
|
|
6453
|
+
const previewUrl =
|
|
6454
|
+
existingAtt?.preview_url &&
|
|
6455
|
+
(existingAtt.preview_url.startsWith("data:") || existingAtt.preview_url.startsWith("blob:"))
|
|
6456
|
+
? existingAtt.preview_url
|
|
6457
|
+
: this.apiClient.buildAttachmentPreviewUrl(record.id, att.id, token);
|
|
6458
|
+
|
|
6459
|
+
const meta =
|
|
6460
|
+
att.metadata && typeof att.metadata === "object" && !Array.isArray(att.metadata)
|
|
6461
|
+
? { ...att.metadata }
|
|
6462
|
+
: existingAtt?.metadata
|
|
6463
|
+
? { ...existingAtt.metadata }
|
|
6464
|
+
: {};
|
|
6465
|
+
|
|
6466
|
+
let label = existingAtt?.label || "";
|
|
6467
|
+
if (!label) {
|
|
6468
|
+
if (meta.auto_smart_context === true && typeof meta.friendly_label === "string") {
|
|
6469
|
+
label = `Context around ${meta.friendly_label}`;
|
|
6470
|
+
} else if (att.filename) {
|
|
6471
|
+
label = att.filename;
|
|
6472
|
+
} else {
|
|
6473
|
+
label = att.attachment_type === "screenshot" ? "Screenshot" : "Attached image";
|
|
6474
|
+
}
|
|
6475
|
+
}
|
|
6476
|
+
|
|
6477
|
+
return {
|
|
6478
|
+
id: existingAtt?.id || `srv_att_${record.id}_${att.id}`,
|
|
6479
|
+
server_id: att.id,
|
|
6480
|
+
label,
|
|
6481
|
+
preview_url: previewUrl,
|
|
6482
|
+
attachment_type: att.attachment_type === "screenshot" ? "screenshot" : "image",
|
|
6483
|
+
filename: att.filename,
|
|
6484
|
+
element_reference_ref: att.element_reference_ref ?? existingAtt?.element_reference_ref ?? null,
|
|
6485
|
+
metadata: meta
|
|
6486
|
+
};
|
|
6487
|
+
});
|
|
6488
|
+
|
|
6489
|
+
const elements = Array.isArray(record.element_references)
|
|
6490
|
+
? structuredClone(record.element_references)
|
|
6491
|
+
: existingEntry?.elements
|
|
6492
|
+
? structuredClone(existingEntry.elements)
|
|
6493
|
+
: [];
|
|
6494
|
+
|
|
6495
|
+
const mappedComments = Array.isArray(record.comments)
|
|
6496
|
+
? record.comments.map((c) => ({
|
|
6497
|
+
id: c.id,
|
|
6498
|
+
author_label: c.author_label || "You",
|
|
6499
|
+
author_type: c.author_type ?? null,
|
|
6500
|
+
body: c.body ?? null,
|
|
6501
|
+
createdAt: this.formatTimestampLabel(c.created_at),
|
|
6502
|
+
rawCreatedAt: c.created_at,
|
|
6503
|
+
attachments: Array.isArray(c.attachments)
|
|
6504
|
+
? c.attachments.map((att) => ({
|
|
6505
|
+
id: `srv-catt-${att.id}`,
|
|
6506
|
+
server_id: att.id,
|
|
6507
|
+
label: att.filename || "image.png",
|
|
6508
|
+
preview_url: this.apiClient.buildAttachmentPreviewUrl(record.id, att.id, token),
|
|
6509
|
+
attachment_type: att.attachment_type || "image",
|
|
6510
|
+
filename: att.filename,
|
|
6511
|
+
metadata: att.metadata || {}
|
|
6512
|
+
}))
|
|
6513
|
+
: []
|
|
6514
|
+
}))
|
|
6515
|
+
: existingEntry?.comments
|
|
6516
|
+
? structuredClone(existingEntry.comments)
|
|
6517
|
+
: [];
|
|
6518
|
+
|
|
6519
|
+
return {
|
|
6520
|
+
id: record.id,
|
|
6521
|
+
message: displayMessage,
|
|
6522
|
+
rawMessage,
|
|
6523
|
+
createdAt: this.formatTimestampLabel(record.created_at || existingEntry?.rawCreatedAt),
|
|
6524
|
+
rawCreatedAt: record.created_at,
|
|
6525
|
+
rawUpdatedAt: record.updated_at,
|
|
6526
|
+
isEdited: isEdited || Boolean(existingEntry?.isEdited),
|
|
6527
|
+
status: record.status,
|
|
6528
|
+
ownershipToken: token,
|
|
6529
|
+
elements,
|
|
6530
|
+
attachments: mappedAttachments,
|
|
6531
|
+
comments: mappedComments
|
|
6532
|
+
};
|
|
6533
|
+
}
|
|
6534
|
+
|
|
6535
|
+
async refreshOwnFeedbacks() {
|
|
6536
|
+
if (typeof fetch !== "function") {
|
|
6537
|
+
return [...this.sessionHistory];
|
|
6538
|
+
}
|
|
6539
|
+
if (this.inFlightOwnFeedbacksPromise) {
|
|
6540
|
+
return this.inFlightOwnFeedbacksPromise;
|
|
6541
|
+
}
|
|
6542
|
+
|
|
6543
|
+
this.inFlightOwnFeedbacksPromise = (async () => {
|
|
6544
|
+
try {
|
|
6545
|
+
const res = await this.apiClient.fetchOwnFeedbacks();
|
|
6546
|
+
this.ownFeedbacksLoaded = true;
|
|
6547
|
+
const records = Array.isArray(res?.feedbacks) ? res.feedbacks : [];
|
|
6548
|
+
if (records.length === 0) {
|
|
6549
|
+
return [...this.sessionHistory];
|
|
6550
|
+
}
|
|
6551
|
+
|
|
6552
|
+
const existingById = new Map ();
|
|
6553
|
+
for (const entry of this.sessionHistory) {
|
|
6554
|
+
existingById.set(String(entry.id), entry);
|
|
6555
|
+
}
|
|
6556
|
+
|
|
6557
|
+
const chronologicalServerRecords = [...records].reverse();
|
|
6558
|
+
const serverIds = new Set ();
|
|
6559
|
+
const merged = [];
|
|
6560
|
+
|
|
6561
|
+
for (const record of chronologicalServerRecords) {
|
|
6562
|
+
if (!record || record.id === undefined || record.id === null) continue;
|
|
6563
|
+
const idKey = String(record.id);
|
|
6564
|
+
serverIds.add(idKey);
|
|
6565
|
+
merged.push(this.mapOwnRecordToSessionEntry(record, existingById.get(idKey)));
|
|
6566
|
+
}
|
|
6567
|
+
|
|
6568
|
+
for (const localEntry of this.sessionHistory) {
|
|
6569
|
+
if (!serverIds.has(String(localEntry.id))) {
|
|
6570
|
+
merged.push(localEntry);
|
|
6571
|
+
}
|
|
6572
|
+
}
|
|
6573
|
+
|
|
6574
|
+
this.sessionHistory = merged;
|
|
6575
|
+
this.renderChatThread();
|
|
6576
|
+
this.syncUiStates();
|
|
6577
|
+
} catch {
|
|
6578
|
+
// Non-fatal when offline or using minimal synthetic endpoints
|
|
6579
|
+
} finally {
|
|
6580
|
+
this.inFlightOwnFeedbacksPromise = null;
|
|
6581
|
+
}
|
|
6582
|
+
return [...this.sessionHistory];
|
|
6583
|
+
})();
|
|
6584
|
+
|
|
6585
|
+
return this.inFlightOwnFeedbacksPromise;
|
|
6586
|
+
}
|
|
6587
|
+
|
|
6588
|
+
async ensureOwnFeedbacksLoaded() {
|
|
6589
|
+
if (this.ownFeedbacksLoaded) return;
|
|
6590
|
+
await this.refreshOwnFeedbacks();
|
|
6591
|
+
}
|
|
6592
|
+
|
|
6593
|
+
startEditingFeedback(feedbackId ) {
|
|
6594
|
+
const targetKey = String(feedbackId);
|
|
6595
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
6596
|
+
if (!entry) return false;
|
|
6597
|
+
|
|
6598
|
+
if (this.commentingFeedbackId !== null) {
|
|
6599
|
+
this.cancelCommentingFeedback();
|
|
6600
|
+
}
|
|
6601
|
+
this.confirmingDeleteId = null;
|
|
6602
|
+
this.hideStatus();
|
|
6603
|
+
|
|
6604
|
+
if (this.editingFeedbackId === null && this.commentingFeedbackId === null) {
|
|
6605
|
+
this.stashedDraftBeforeEdit = {
|
|
6606
|
+
message: this.textareaEl?.value || "",
|
|
6607
|
+
elementReferences: [...this.elementReferences],
|
|
6608
|
+
elementDomNodes: new Map(this.elementDomNodes),
|
|
6609
|
+
attachments: [...this.attachments]
|
|
6610
|
+
};
|
|
6611
|
+
}
|
|
6612
|
+
|
|
6613
|
+
this.editingFeedbackId = targetKey;
|
|
6614
|
+
|
|
6615
|
+
if (this.textareaEl) {
|
|
6616
|
+
this.textareaEl.value = entry.rawMessage !== undefined ? entry.rawMessage : entry.message;
|
|
6617
|
+
}
|
|
6618
|
+
|
|
6619
|
+
this.elementReferences = structuredClone(entry.elements);
|
|
6620
|
+
this.elementDomNodes.clear();
|
|
6621
|
+
if (typeof document !== "undefined" && typeof document.querySelector === "function") {
|
|
6622
|
+
for (const elRef of this.elementReferences) {
|
|
6623
|
+
if (!elRef.selector) continue;
|
|
6624
|
+
try {
|
|
6625
|
+
const liveNode = document.querySelector(elRef.selector);
|
|
6626
|
+
if (liveNode) {
|
|
6627
|
+
this.elementDomNodes.set(elRef.client_ref, liveNode);
|
|
6628
|
+
}
|
|
6629
|
+
} catch {
|
|
6630
|
+
// Ignore invalid or complex selectors not resolvable on current page
|
|
6631
|
+
}
|
|
6632
|
+
}
|
|
6633
|
+
}
|
|
6634
|
+
|
|
6635
|
+
this.attachments = entry.attachments.map((att) => ({
|
|
6636
|
+
id: att.id,
|
|
6637
|
+
existing_attachment_id: att.server_id,
|
|
6638
|
+
attachment_type: att.attachment_type,
|
|
6639
|
+
label: att.label,
|
|
6640
|
+
preview_url: att.preview_url,
|
|
6641
|
+
signed_blob_id: att.signed_blob_id,
|
|
6642
|
+
data_url: att.data_url,
|
|
6643
|
+
filename: att.filename || att.label || "attachment.png",
|
|
6644
|
+
element_reference_ref: att.element_reference_ref || undefined,
|
|
6645
|
+
metadata: att.metadata ? structuredClone(att.metadata) : {}
|
|
6646
|
+
}));
|
|
5700
6647
|
|
|
5701
|
-
|
|
5702
|
-
this.
|
|
6648
|
+
this.picker?.refreshPinnedMarkers();
|
|
6649
|
+
this.renderTray();
|
|
6650
|
+
this.renderChatThread();
|
|
6651
|
+
this.syncUiStates();
|
|
6652
|
+
this.textareaEl?.focus();
|
|
6653
|
+
return true;
|
|
5703
6654
|
}
|
|
5704
6655
|
|
|
5705
|
-
|
|
5706
|
-
this.
|
|
5707
|
-
|
|
6656
|
+
cancelEditingFeedback() {
|
|
6657
|
+
if (this.editingFeedbackId === null) return;
|
|
6658
|
+
this.editingFeedbackId = null;
|
|
5708
6659
|
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
this.
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
6660
|
+
if (this.stashedDraftBeforeEdit) {
|
|
6661
|
+
if (this.textareaEl) {
|
|
6662
|
+
this.textareaEl.value = this.stashedDraftBeforeEdit.message;
|
|
6663
|
+
}
|
|
6664
|
+
this.elementReferences = this.stashedDraftBeforeEdit.elementReferences;
|
|
6665
|
+
this.elementDomNodes = this.stashedDraftBeforeEdit.elementDomNodes;
|
|
6666
|
+
this.attachments = this.stashedDraftBeforeEdit.attachments;
|
|
6667
|
+
this.stashedDraftBeforeEdit = null;
|
|
6668
|
+
} else {
|
|
6669
|
+
if (this.textareaEl) {
|
|
6670
|
+
this.textareaEl.value = "";
|
|
6671
|
+
}
|
|
6672
|
+
this.elementReferences = [];
|
|
6673
|
+
this.elementDomNodes.clear();
|
|
6674
|
+
this.attachments = [];
|
|
5723
6675
|
}
|
|
6676
|
+
|
|
6677
|
+
this.picker?.hideExternalPreview();
|
|
6678
|
+
this.picker?.refreshPinnedMarkers();
|
|
6679
|
+
this.renderTray();
|
|
6680
|
+
this.renderChatThread();
|
|
6681
|
+
this.syncUiStates();
|
|
5724
6682
|
}
|
|
5725
6683
|
|
|
5726
|
-
|
|
5727
|
-
const
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
this.customPlaceholderSet = true;
|
|
5734
|
-
}
|
|
5735
|
-
this.config = {
|
|
5736
|
-
...this.config,
|
|
5737
|
-
...partial,
|
|
5738
|
-
agent: { ...(this.config.agent || { enabled: false }), ...(partial.agent || {}) },
|
|
5739
|
-
features: { ...this.config.features, ...(partial.features || {}) },
|
|
5740
|
-
limits: { ...this.config.limits, ...(partial.limits || {}) },
|
|
5741
|
-
privacy: { ...this.config.privacy, ...(partial.privacy || {}) }
|
|
5742
|
-
};
|
|
5743
|
-
if (partial.csrf_token) {
|
|
5744
|
-
this.apiClient.setCsrfToken(partial.csrf_token);
|
|
6684
|
+
startCommentingFeedback(feedbackId ) {
|
|
6685
|
+
const targetKey = String(feedbackId);
|
|
6686
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
6687
|
+
if (!entry) return false;
|
|
6688
|
+
|
|
6689
|
+
if (this.editingFeedbackId !== null) {
|
|
6690
|
+
this.cancelEditingFeedback();
|
|
5745
6691
|
}
|
|
5746
|
-
|
|
5747
|
-
|
|
6692
|
+
this.confirmingDeleteId = null;
|
|
6693
|
+
this.hideStatus();
|
|
6694
|
+
|
|
6695
|
+
if (this.commentingFeedbackId === null && this.editingFeedbackId === null) {
|
|
6696
|
+
this.stashedDraftBeforeEdit = {
|
|
6697
|
+
message: this.textareaEl?.value || "",
|
|
6698
|
+
elementReferences: [...this.elementReferences],
|
|
6699
|
+
elementDomNodes: new Map(this.elementDomNodes),
|
|
6700
|
+
attachments: [...this.attachments]
|
|
6701
|
+
};
|
|
5748
6702
|
}
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
void this.ensureAgentStatusLoaded();
|
|
5754
|
-
}
|
|
5755
|
-
} else if (!nowAgentEnabled) {
|
|
5756
|
-
this.surfaceMode = "feedback";
|
|
6703
|
+
|
|
6704
|
+
this.commentingFeedbackId = targetKey;
|
|
6705
|
+
if (this.textareaEl) {
|
|
6706
|
+
this.textareaEl.value = "";
|
|
5757
6707
|
}
|
|
6708
|
+
this.elementReferences = [];
|
|
6709
|
+
this.elementDomNodes.clear();
|
|
6710
|
+
this.attachments = [];
|
|
6711
|
+
|
|
6712
|
+
this.picker?.hideExternalPreview();
|
|
6713
|
+
this.picker?.refreshPinnedMarkers();
|
|
5758
6714
|
this.renderTray();
|
|
5759
6715
|
this.renderChatThread();
|
|
5760
6716
|
this.syncUiStates();
|
|
6717
|
+
this.textareaEl?.focus();
|
|
6718
|
+
return true;
|
|
5761
6719
|
}
|
|
5762
6720
|
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
6721
|
+
cancelCommentingFeedback() {
|
|
6722
|
+
if (this.commentingFeedbackId === null) return;
|
|
6723
|
+
this.commentingFeedbackId = null;
|
|
5766
6724
|
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
6725
|
+
if (this.stashedDraftBeforeEdit) {
|
|
6726
|
+
if (this.textareaEl) {
|
|
6727
|
+
this.textareaEl.value = this.stashedDraftBeforeEdit.message;
|
|
6728
|
+
}
|
|
6729
|
+
this.elementReferences = this.stashedDraftBeforeEdit.elementReferences;
|
|
6730
|
+
this.elementDomNodes = this.stashedDraftBeforeEdit.elementDomNodes;
|
|
6731
|
+
this.attachments = this.stashedDraftBeforeEdit.attachments;
|
|
6732
|
+
this.stashedDraftBeforeEdit = null;
|
|
6733
|
+
} else {
|
|
6734
|
+
if (this.textareaEl) {
|
|
6735
|
+
this.textareaEl.value = "";
|
|
6736
|
+
}
|
|
6737
|
+
this.elementReferences = [];
|
|
6738
|
+
this.elementDomNodes.clear();
|
|
6739
|
+
this.attachments = [];
|
|
5774
6740
|
}
|
|
6741
|
+
|
|
5775
6742
|
this.renderTray();
|
|
5776
6743
|
this.renderChatThread();
|
|
5777
6744
|
this.syncUiStates();
|
|
5778
|
-
this.focusActiveInput();
|
|
5779
6745
|
}
|
|
5780
6746
|
|
|
5781
|
-
|
|
5782
|
-
|
|
6747
|
+
async markFeedbackReviewed(feedbackId ) {
|
|
6748
|
+
if (this.reviewingFeedbackId !== null || this.isSubmitting) return;
|
|
6749
|
+
const targetKey = String(feedbackId);
|
|
6750
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
6751
|
+
if (!entry) return;
|
|
6752
|
+
|
|
6753
|
+
this.reviewingFeedbackId = targetKey;
|
|
6754
|
+
this.renderChatThread();
|
|
6755
|
+
|
|
6756
|
+
try {
|
|
6757
|
+
const res = await this.apiClient.updateFeedback(
|
|
6758
|
+
entry.id,
|
|
6759
|
+
{ status: "reviewed" },
|
|
6760
|
+
entry.ownershipToken
|
|
6761
|
+
);
|
|
6762
|
+
entry.status = res?.status || "reviewed";
|
|
6763
|
+
if (res?.ownership_token) {
|
|
6764
|
+
entry.ownershipToken = res.ownership_token;
|
|
6765
|
+
}
|
|
6766
|
+
this.reviewingFeedbackId = null;
|
|
6767
|
+
this.renderChatThread();
|
|
6768
|
+
this.showStatus("Fix marked as reviewed.", "success");
|
|
6769
|
+
this.emitWidgetEvent("context-drop:update", { response: res, id: entry.id });
|
|
6770
|
+
} catch (err) {
|
|
6771
|
+
this.reviewingFeedbackId = null;
|
|
6772
|
+
this.renderChatThread();
|
|
6773
|
+
const msg = err instanceof Error ? err.message : "Failed to mark feedback as reviewed.";
|
|
6774
|
+
this.showStatus(msg, "error");
|
|
6775
|
+
}
|
|
5783
6776
|
}
|
|
5784
6777
|
|
|
5785
|
-
|
|
5786
|
-
|
|
6778
|
+
requestDeleteFeedback(feedbackId ) {
|
|
6779
|
+
const targetKey = String(feedbackId);
|
|
6780
|
+
if (!this.sessionHistory.some((item) => String(item.id) === targetKey)) return;
|
|
6781
|
+
this.confirmingDeleteId = this.confirmingDeleteId === targetKey ? null : targetKey;
|
|
6782
|
+
this.renderChatThread();
|
|
5787
6783
|
}
|
|
5788
6784
|
|
|
5789
|
-
|
|
5790
|
-
|
|
6785
|
+
cancelDeleteFeedback() {
|
|
6786
|
+
if (this.confirmingDeleteId === null) return;
|
|
6787
|
+
this.confirmingDeleteId = null;
|
|
6788
|
+
this.renderChatThread();
|
|
6789
|
+
}
|
|
6790
|
+
|
|
6791
|
+
async confirmDeleteFeedback(feedbackId ) {
|
|
6792
|
+
if (this.deletingFeedbackId !== null) return;
|
|
6793
|
+
const targetKey = String(feedbackId);
|
|
6794
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
6795
|
+
if (!entry) return;
|
|
6796
|
+
|
|
6797
|
+
this.deletingFeedbackId = targetKey;
|
|
6798
|
+
this.renderChatThread();
|
|
6799
|
+
|
|
6800
|
+
try {
|
|
6801
|
+
const res = await this.apiClient.deleteFeedback(entry.id, entry.ownershipToken);
|
|
6802
|
+
if (this.editingFeedbackId === targetKey) {
|
|
6803
|
+
this.cancelEditingFeedback();
|
|
6804
|
+
}
|
|
6805
|
+
this.sessionHistory = this.sessionHistory.filter((item) => String(item.id) !== targetKey);
|
|
6806
|
+
this.confirmingDeleteId = null;
|
|
6807
|
+
this.deletingFeedbackId = null;
|
|
6808
|
+
this.renderChatThread();
|
|
6809
|
+
this.renderTray();
|
|
6810
|
+
this.syncUiStates();
|
|
6811
|
+
this.showStatus(
|
|
6812
|
+
this.isSmartSelectionMode() ? "Your feedback was deleted." : "Feedback deleted.",
|
|
6813
|
+
"success"
|
|
6814
|
+
);
|
|
6815
|
+
this.emitWidgetEvent("context-drop:delete", {
|
|
6816
|
+
response: res,
|
|
6817
|
+
id: entry.id
|
|
6818
|
+
});
|
|
6819
|
+
} catch (err) {
|
|
6820
|
+
this.deletingFeedbackId = null;
|
|
6821
|
+
this.renderChatThread();
|
|
6822
|
+
const msg = err instanceof Error ? err.message : "Failed to delete feedback.";
|
|
6823
|
+
this.showStatus(msg, "error");
|
|
6824
|
+
this.emitWidgetEvent("context-drop:error", {
|
|
6825
|
+
error: msg
|
|
6826
|
+
});
|
|
6827
|
+
}
|
|
5791
6828
|
}
|
|
5792
6829
|
|
|
5793
6830
|
getAgentMessages() {
|
|
@@ -5828,6 +6865,8 @@
|
|
|
5828
6865
|
this.isMinimized = false;
|
|
5829
6866
|
if (this.isAgentModeActive()) {
|
|
5830
6867
|
void this.ensureAgentStatusLoaded();
|
|
6868
|
+
} else {
|
|
6869
|
+
void this.ensureOwnFeedbacksLoaded();
|
|
5831
6870
|
}
|
|
5832
6871
|
this.syncUiStates();
|
|
5833
6872
|
this.focusActiveInput();
|
|
@@ -6843,6 +7882,31 @@
|
|
|
6843
7882
|
const promptShell = document.createElement("div");
|
|
6844
7883
|
promptShell.className = "cd-prompt-shell";
|
|
6845
7884
|
|
|
7885
|
+
const editBanner = document.createElement("div");
|
|
7886
|
+
editBanner.className = "cd-edit-banner";
|
|
7887
|
+
editBanner.hidden = true;
|
|
7888
|
+
|
|
7889
|
+
const editBannerInfo = document.createElement("span");
|
|
7890
|
+
editBannerInfo.className = "cd-edit-banner-info";
|
|
7891
|
+
this.editBannerInfoEl = editBannerInfo;
|
|
7892
|
+
editBanner.appendChild(editBannerInfo);
|
|
7893
|
+
|
|
7894
|
+
const cancelEditBtn = document.createElement("button");
|
|
7895
|
+
cancelEditBtn.type = "button";
|
|
7896
|
+
cancelEditBtn.className = "cd-btn cd-btn-xs";
|
|
7897
|
+
cancelEditBtn.setAttribute("aria-label", "Cancel editing feedback");
|
|
7898
|
+
cancelEditBtn.textContent = "Cancel";
|
|
7899
|
+
cancelEditBtn.addEventListener("click", () => {
|
|
7900
|
+
if (this.commentingFeedbackId !== null) {
|
|
7901
|
+
this.cancelCommentingFeedback();
|
|
7902
|
+
} else {
|
|
7903
|
+
this.cancelEditingFeedback();
|
|
7904
|
+
}
|
|
7905
|
+
});
|
|
7906
|
+
editBanner.appendChild(cancelEditBtn);
|
|
7907
|
+
this.editBannerEl = editBanner;
|
|
7908
|
+
promptShell.appendChild(editBanner);
|
|
7909
|
+
|
|
6846
7910
|
const textarea = document.createElement("textarea");
|
|
6847
7911
|
textarea.className = "cd-textarea";
|
|
6848
7912
|
textarea.placeholder = this.config.placeholder;
|
|
@@ -6852,8 +7916,17 @@
|
|
|
6852
7916
|
ev.preventDefault();
|
|
6853
7917
|
void this.handleSubmit();
|
|
6854
7918
|
} else if (ev.key === "Escape") {
|
|
7919
|
+
if (ev.defaultPrevented) return;
|
|
6855
7920
|
ev.preventDefault();
|
|
6856
|
-
this.
|
|
7921
|
+
if (this.confirmingDeleteId !== null) {
|
|
7922
|
+
this.cancelDeleteFeedback();
|
|
7923
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
7924
|
+
this.cancelCommentingFeedback();
|
|
7925
|
+
} else if (this.editingFeedbackId !== null) {
|
|
7926
|
+
this.cancelEditingFeedback();
|
|
7927
|
+
} else {
|
|
7928
|
+
this.closeComposer();
|
|
7929
|
+
}
|
|
6857
7930
|
}
|
|
6858
7931
|
});
|
|
6859
7932
|
textarea.addEventListener("paste", (ev) => this.handlePaste(ev));
|
|
@@ -8108,12 +9181,21 @@
|
|
|
8108
9181
|
if (this.composerModeSwitchWrap) {
|
|
8109
9182
|
this.composerModeSwitchWrap.hidden = !this.config.agent?.enabled;
|
|
8110
9183
|
}
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
9184
|
+
const isCommenting = this.commentingFeedbackId !== null;
|
|
9185
|
+
if (this.textareaEl) {
|
|
9186
|
+
if (isCommenting) {
|
|
9187
|
+
this.textareaEl.placeholder = "Write a comment... (attach or paste images below)";
|
|
9188
|
+
} else if (!this.customPlaceholderSet) {
|
|
9189
|
+
this.textareaEl.placeholder = smartMode
|
|
9190
|
+
? DEFAULT_SMART_PLACEHOLDER
|
|
9191
|
+
: DEFAULT_VERBOSE_PLACEHOLDER;
|
|
9192
|
+
}
|
|
9193
|
+
}
|
|
9194
|
+
if (this.cornerPinBtn) {
|
|
9195
|
+
this.cornerPinBtn.hidden = isCommenting;
|
|
8115
9196
|
}
|
|
8116
9197
|
if (this.composerToolbarPickBtn) {
|
|
9198
|
+
this.composerToolbarPickBtn.hidden = isCommenting;
|
|
8117
9199
|
if (smartMode) {
|
|
8118
9200
|
this.composerToolbarPickBtn.title = "Highlight an area on the page";
|
|
8119
9201
|
this.composerToolbarPickBtn.setAttribute("aria-label", "Highlight an area on the page");
|
|
@@ -8128,13 +9210,60 @@
|
|
|
8128
9210
|
}
|
|
8129
9211
|
}
|
|
8130
9212
|
if (this.composerToolbarScreenshotBtn) {
|
|
8131
|
-
this.composerToolbarScreenshotBtn.hidden = smartMode;
|
|
9213
|
+
this.composerToolbarScreenshotBtn.hidden = smartMode && !isCommenting;
|
|
8132
9214
|
}
|
|
8133
9215
|
if (this.composerToolbarUploadBtn) {
|
|
8134
9216
|
this.composerToolbarUploadBtn.innerHTML = smartMode
|
|
8135
9217
|
? `${ICON_IMAGE}<span>Add image</span>`
|
|
8136
9218
|
: `${ICON_IMAGE}<span>Image</span>`;
|
|
8137
9219
|
}
|
|
9220
|
+
if (this.editBannerEl && this.editBannerInfoEl) {
|
|
9221
|
+
if (this.editingFeedbackId !== null) {
|
|
9222
|
+
this.editBannerEl.hidden = false;
|
|
9223
|
+
this.editBannerInfoEl.innerHTML = "";
|
|
9224
|
+
const iconSpan = document.createElement("span");
|
|
9225
|
+
iconSpan.innerHTML = ICON_EDIT;
|
|
9226
|
+
const labelSpan = document.createElement("span");
|
|
9227
|
+
labelSpan.textContent = smartMode ? "Editing your feedback" : "Editing feedback";
|
|
9228
|
+
this.editBannerInfoEl.appendChild(iconSpan);
|
|
9229
|
+
this.editBannerInfoEl.appendChild(labelSpan);
|
|
9230
|
+
if (!smartMode) {
|
|
9231
|
+
const idSpan = document.createElement("span");
|
|
9232
|
+
idSpan.className = "cd-edit-banner-id";
|
|
9233
|
+
idSpan.textContent = `#${this.editingFeedbackId}`;
|
|
9234
|
+
this.editBannerInfoEl.appendChild(idSpan);
|
|
9235
|
+
}
|
|
9236
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
9237
|
+
this.editBannerEl.hidden = false;
|
|
9238
|
+
this.editBannerInfoEl.innerHTML = "";
|
|
9239
|
+
const iconSpan = document.createElement("span");
|
|
9240
|
+
iconSpan.innerHTML = ICON_COMMENT;
|
|
9241
|
+
const labelSpan = document.createElement("span");
|
|
9242
|
+
labelSpan.textContent = smartMode ? "Commenting on feedback" : "Commenting on";
|
|
9243
|
+
this.editBannerInfoEl.appendChild(iconSpan);
|
|
9244
|
+
this.editBannerInfoEl.appendChild(labelSpan);
|
|
9245
|
+
if (!smartMode) {
|
|
9246
|
+
const idSpan = document.createElement("span");
|
|
9247
|
+
idSpan.className = "cd-edit-banner-id";
|
|
9248
|
+
idSpan.textContent = `#${this.commentingFeedbackId}`;
|
|
9249
|
+
this.editBannerInfoEl.appendChild(idSpan);
|
|
9250
|
+
}
|
|
9251
|
+
} else {
|
|
9252
|
+
this.editBannerEl.hidden = true;
|
|
9253
|
+
}
|
|
9254
|
+
}
|
|
9255
|
+
if (this.submitBtn && !this.isSubmitting) {
|
|
9256
|
+
if (this.editingFeedbackId !== null) {
|
|
9257
|
+
this.submitBtn.setAttribute("aria-label", "Save feedback changes");
|
|
9258
|
+
this.submitBtn.innerHTML = `${ICON_CHECK}<span>Save</span>`;
|
|
9259
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
9260
|
+
this.submitBtn.setAttribute("aria-label", "Submit comment");
|
|
9261
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Comment</span>`;
|
|
9262
|
+
} else {
|
|
9263
|
+
this.submitBtn.setAttribute("aria-label", "Submit feedback");
|
|
9264
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Send</span>`;
|
|
9265
|
+
}
|
|
9266
|
+
}
|
|
8138
9267
|
|
|
8139
9268
|
if (this.agentSidebarEl) {
|
|
8140
9269
|
this.agentSidebarEl.hidden = !showAgentSidebar;
|
|
@@ -8370,8 +9499,21 @@
|
|
|
8370
9499
|
this.chatThreadEl.hidden = false;
|
|
8371
9500
|
|
|
8372
9501
|
for (const entry of this.sessionHistory) {
|
|
9502
|
+
const entryIdStr = String(entry.id);
|
|
9503
|
+
const isEditingThis = this.editingFeedbackId === entryIdStr;
|
|
9504
|
+
const isCommentingThis = this.commentingFeedbackId === entryIdStr;
|
|
9505
|
+
const isReviewingThis = this.reviewingFeedbackId === entryIdStr;
|
|
9506
|
+
const isConfirmingDelete = this.confirmingDeleteId === entryIdStr;
|
|
9507
|
+
const isDeletingThis = this.deletingFeedbackId === entryIdStr;
|
|
9508
|
+
const statusName = entry.status || "new";
|
|
9509
|
+
|
|
8373
9510
|
const msgCard = document.createElement("div");
|
|
8374
|
-
msgCard.className =
|
|
9511
|
+
msgCard.className = isEditingThis
|
|
9512
|
+
? "cd-chat-msg is-editing"
|
|
9513
|
+
: isCommentingThis
|
|
9514
|
+
? "cd-chat-msg is-commenting"
|
|
9515
|
+
: "cd-chat-msg";
|
|
9516
|
+
msgCard.setAttribute("data-feedback-id", entryIdStr);
|
|
8375
9517
|
|
|
8376
9518
|
if (entry.elements.length > 0 || entry.attachments.length > 0) {
|
|
8377
9519
|
const pills = document.createElement("div");
|
|
@@ -8404,16 +9546,192 @@
|
|
|
8404
9546
|
msgCard.appendChild(textP);
|
|
8405
9547
|
}
|
|
8406
9548
|
|
|
9549
|
+
if (entry.comments && entry.comments.length > 0) {
|
|
9550
|
+
const commentsList = document.createElement("div");
|
|
9551
|
+
commentsList.className = "cd-comments-list";
|
|
9552
|
+
for (const comment of entry.comments) {
|
|
9553
|
+
const cItem = document.createElement("div");
|
|
9554
|
+
cItem.className = "cd-comment-item";
|
|
9555
|
+
|
|
9556
|
+
const cHeader = document.createElement("div");
|
|
9557
|
+
cHeader.className = "cd-comment-header";
|
|
9558
|
+
const cAuthor = document.createElement("span");
|
|
9559
|
+
cAuthor.className = "cd-comment-author";
|
|
9560
|
+
cAuthor.textContent = comment.author_label || "You";
|
|
9561
|
+
const cTime = document.createElement("span");
|
|
9562
|
+
cTime.textContent = comment.createdAt;
|
|
9563
|
+
cHeader.appendChild(cAuthor);
|
|
9564
|
+
cHeader.appendChild(cTime);
|
|
9565
|
+
cItem.appendChild(cHeader);
|
|
9566
|
+
|
|
9567
|
+
if (comment.body) {
|
|
9568
|
+
const cBody = document.createElement("p");
|
|
9569
|
+
cBody.className = "cd-comment-body";
|
|
9570
|
+
cBody.textContent = comment.body;
|
|
9571
|
+
cItem.appendChild(cBody);
|
|
9572
|
+
}
|
|
9573
|
+
|
|
9574
|
+
if (comment.attachments && comment.attachments.length > 0) {
|
|
9575
|
+
const cImgs = document.createElement("div");
|
|
9576
|
+
cImgs.className = "cd-comment-images";
|
|
9577
|
+
for (const att of comment.attachments) {
|
|
9578
|
+
if (att.preview_url) {
|
|
9579
|
+
const imgLink = document.createElement("a");
|
|
9580
|
+
imgLink.href = att.preview_url;
|
|
9581
|
+
imgLink.target = "_blank";
|
|
9582
|
+
imgLink.rel = "noopener noreferrer";
|
|
9583
|
+
const img = document.createElement("img");
|
|
9584
|
+
img.src = att.preview_url;
|
|
9585
|
+
img.alt = att.label || "Comment image";
|
|
9586
|
+
img.className = "cd-comment-thumb";
|
|
9587
|
+
imgLink.appendChild(img);
|
|
9588
|
+
cImgs.appendChild(imgLink);
|
|
9589
|
+
}
|
|
9590
|
+
}
|
|
9591
|
+
if (cImgs.childNodes.length > 0) {
|
|
9592
|
+
cItem.appendChild(cImgs);
|
|
9593
|
+
}
|
|
9594
|
+
}
|
|
9595
|
+
|
|
9596
|
+
commentsList.appendChild(cItem);
|
|
9597
|
+
}
|
|
9598
|
+
msgCard.appendChild(commentsList);
|
|
9599
|
+
}
|
|
9600
|
+
|
|
8407
9601
|
const meta = document.createElement("div");
|
|
8408
9602
|
meta.className = "cd-chat-msg-meta";
|
|
9603
|
+
|
|
9604
|
+
const metaInfo = document.createElement("div");
|
|
9605
|
+
metaInfo.className = "cd-chat-msg-meta-info";
|
|
9606
|
+
|
|
9607
|
+
const statusBadge = document.createElement("span");
|
|
9608
|
+
statusBadge.className = `cd-msg-status-badge is-${statusName}`;
|
|
9609
|
+
statusBadge.textContent = statusName;
|
|
9610
|
+
|
|
8409
9611
|
const idSpan = document.createElement("span");
|
|
8410
|
-
|
|
9612
|
+
const baseLabel = smartMode ? "Feedback sent" : `Dropped #${entry.id}`;
|
|
9613
|
+
idSpan.textContent = entry.isEdited ? `${baseLabel} · edited` : baseLabel;
|
|
9614
|
+
|
|
9615
|
+
const sepSpan = document.createElement("span");
|
|
9616
|
+
sepSpan.setAttribute("aria-hidden", "true");
|
|
9617
|
+
sepSpan.textContent = "·";
|
|
9618
|
+
|
|
8411
9619
|
const timeSpan = document.createElement("span");
|
|
8412
9620
|
timeSpan.textContent = entry.createdAt;
|
|
8413
|
-
|
|
8414
|
-
|
|
9621
|
+
|
|
9622
|
+
metaInfo.appendChild(statusBadge);
|
|
9623
|
+
metaInfo.appendChild(idSpan);
|
|
9624
|
+
metaInfo.appendChild(sepSpan);
|
|
9625
|
+
metaInfo.appendChild(timeSpan);
|
|
9626
|
+
|
|
9627
|
+
const actions = document.createElement("div");
|
|
9628
|
+
actions.className = "cd-chat-msg-actions";
|
|
9629
|
+
|
|
9630
|
+
if (statusName === "fixed") {
|
|
9631
|
+
const reviewBtn = document.createElement("button");
|
|
9632
|
+
reviewBtn.type = "button";
|
|
9633
|
+
reviewBtn.className = "cd-review-btn";
|
|
9634
|
+
reviewBtn.title = "Confirm fix was tested and reviewed";
|
|
9635
|
+
reviewBtn.setAttribute("aria-label", "Mark fix as reviewed");
|
|
9636
|
+
reviewBtn.disabled = isReviewingThis || this.isSubmitting || this.deletingFeedbackId !== null;
|
|
9637
|
+
reviewBtn.innerHTML = `${ICON_CHECK}<span>${isReviewingThis ? "Saving..." : "Mark Reviewed"}</span>`;
|
|
9638
|
+
reviewBtn.addEventListener("click", () => {
|
|
9639
|
+
void this.markFeedbackReviewed(entry.id);
|
|
9640
|
+
});
|
|
9641
|
+
actions.appendChild(reviewBtn);
|
|
9642
|
+
}
|
|
9643
|
+
|
|
9644
|
+
const commentBtn = document.createElement("button");
|
|
9645
|
+
commentBtn.type = "button";
|
|
9646
|
+
commentBtn.className = `cd-msg-action-btn${isCommentingThis ? " is-active" : ""}`;
|
|
9647
|
+
commentBtn.title = isCommentingThis ? "Cancel comment" : "Add comment";
|
|
9648
|
+
commentBtn.setAttribute("aria-label", "Add comment");
|
|
9649
|
+
commentBtn.setAttribute("aria-pressed", String(isCommentingThis));
|
|
9650
|
+
commentBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
9651
|
+
commentBtn.innerHTML = ICON_COMMENT;
|
|
9652
|
+
commentBtn.addEventListener("click", () => {
|
|
9653
|
+
if (this.commentingFeedbackId === entryIdStr) {
|
|
9654
|
+
this.cancelCommentingFeedback();
|
|
9655
|
+
} else {
|
|
9656
|
+
this.startCommentingFeedback(entry.id);
|
|
9657
|
+
}
|
|
9658
|
+
});
|
|
9659
|
+
|
|
9660
|
+
const editBtn = document.createElement("button");
|
|
9661
|
+
editBtn.type = "button";
|
|
9662
|
+
editBtn.className = `cd-msg-action-btn${isEditingThis ? " is-active" : ""}`;
|
|
9663
|
+
editBtn.title = isEditingThis ? "Cancel editing" : "Edit feedback";
|
|
9664
|
+
editBtn.setAttribute("aria-label", "Edit feedback");
|
|
9665
|
+
editBtn.setAttribute("aria-pressed", String(isEditingThis));
|
|
9666
|
+
editBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
9667
|
+
editBtn.innerHTML = ICON_EDIT;
|
|
9668
|
+
editBtn.addEventListener("click", () => {
|
|
9669
|
+
if (this.editingFeedbackId === entryIdStr) {
|
|
9670
|
+
this.cancelEditingFeedback();
|
|
9671
|
+
} else {
|
|
9672
|
+
this.startEditingFeedback(entry.id);
|
|
9673
|
+
}
|
|
9674
|
+
});
|
|
9675
|
+
|
|
9676
|
+
const deleteBtn = document.createElement("button");
|
|
9677
|
+
deleteBtn.type = "button";
|
|
9678
|
+
deleteBtn.className = "cd-msg-action-btn is-danger";
|
|
9679
|
+
deleteBtn.title = "Delete feedback";
|
|
9680
|
+
deleteBtn.setAttribute("aria-label", "Delete feedback");
|
|
9681
|
+
deleteBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
9682
|
+
deleteBtn.innerHTML = ICON_TRASH;
|
|
9683
|
+
deleteBtn.addEventListener("click", () => {
|
|
9684
|
+
this.requestDeleteFeedback(entry.id);
|
|
9685
|
+
});
|
|
9686
|
+
|
|
9687
|
+
actions.appendChild(commentBtn);
|
|
9688
|
+
actions.appendChild(editBtn);
|
|
9689
|
+
actions.appendChild(deleteBtn);
|
|
9690
|
+
|
|
9691
|
+
meta.appendChild(metaInfo);
|
|
9692
|
+
meta.appendChild(actions);
|
|
8415
9693
|
msgCard.appendChild(meta);
|
|
8416
9694
|
|
|
9695
|
+
if (isConfirmingDelete) {
|
|
9696
|
+
const confirmBar = document.createElement("div");
|
|
9697
|
+
confirmBar.className = "cd-msg-delete-confirm";
|
|
9698
|
+
confirmBar.setAttribute("role", "group");
|
|
9699
|
+
confirmBar.setAttribute("aria-label", "Confirm feedback deletion");
|
|
9700
|
+
|
|
9701
|
+
const confirmLabel = document.createElement("span");
|
|
9702
|
+
confirmLabel.className = "cd-msg-delete-label";
|
|
9703
|
+
confirmLabel.textContent = "Delete this feedback?";
|
|
9704
|
+
|
|
9705
|
+
const btnGroup = document.createElement("div");
|
|
9706
|
+
btnGroup.className = "cd-msg-delete-btns";
|
|
9707
|
+
|
|
9708
|
+
const cancelDeleteBtn = document.createElement("button");
|
|
9709
|
+
cancelDeleteBtn.type = "button";
|
|
9710
|
+
cancelDeleteBtn.className = "cd-btn cd-btn-xs";
|
|
9711
|
+
cancelDeleteBtn.setAttribute("aria-label", "Cancel delete");
|
|
9712
|
+
cancelDeleteBtn.disabled = isDeletingThis;
|
|
9713
|
+
cancelDeleteBtn.textContent = "Cancel";
|
|
9714
|
+
cancelDeleteBtn.addEventListener("click", () => {
|
|
9715
|
+
this.cancelDeleteFeedback();
|
|
9716
|
+
});
|
|
9717
|
+
|
|
9718
|
+
const confirmDeleteBtn = document.createElement("button");
|
|
9719
|
+
confirmDeleteBtn.type = "button";
|
|
9720
|
+
confirmDeleteBtn.className = "cd-btn cd-btn-xs cd-btn-danger";
|
|
9721
|
+
confirmDeleteBtn.setAttribute("aria-label", "Confirm delete feedback");
|
|
9722
|
+
confirmDeleteBtn.disabled = isDeletingThis;
|
|
9723
|
+
confirmDeleteBtn.textContent = isDeletingThis ? "Deleting..." : "Delete";
|
|
9724
|
+
confirmDeleteBtn.addEventListener("click", () => {
|
|
9725
|
+
void this.confirmDeleteFeedback(entry.id);
|
|
9726
|
+
});
|
|
9727
|
+
|
|
9728
|
+
btnGroup.appendChild(cancelDeleteBtn);
|
|
9729
|
+
btnGroup.appendChild(confirmDeleteBtn);
|
|
9730
|
+
confirmBar.appendChild(confirmLabel);
|
|
9731
|
+
confirmBar.appendChild(btnGroup);
|
|
9732
|
+
msgCard.appendChild(confirmBar);
|
|
9733
|
+
}
|
|
9734
|
+
|
|
8417
9735
|
this.chatThreadEl.appendChild(msgCard);
|
|
8418
9736
|
}
|
|
8419
9737
|
|
|
@@ -8802,13 +10120,20 @@
|
|
|
8802
10120
|
async handleSubmit() {
|
|
8803
10121
|
if (this.isSubmitting) return;
|
|
8804
10122
|
const smartMode = this.isSmartSelectionMode();
|
|
10123
|
+
const editingId = this.editingFeedbackId;
|
|
10124
|
+
const commentingId = this.commentingFeedbackId;
|
|
8805
10125
|
|
|
8806
10126
|
if (this.pendingSmartCaptures.size > 0) {
|
|
8807
10127
|
await Promise.allSettled(Array.from(this.pendingSmartCaptures));
|
|
8808
10128
|
}
|
|
8809
10129
|
|
|
8810
10130
|
const message = (this.textareaEl?.value || "").trim();
|
|
8811
|
-
if (
|
|
10131
|
+
if (commentingId !== null) {
|
|
10132
|
+
if (message.length === 0 && this.attachments.length === 0) {
|
|
10133
|
+
this.showStatus("Write a comment or attach an image first.", "error");
|
|
10134
|
+
return;
|
|
10135
|
+
}
|
|
10136
|
+
} else if (
|
|
8812
10137
|
message.length === 0 &&
|
|
8813
10138
|
this.attachments.length === 0 &&
|
|
8814
10139
|
this.elementReferences.length === 0
|
|
@@ -8825,32 +10150,173 @@
|
|
|
8825
10150
|
this.isSubmitting = true;
|
|
8826
10151
|
if (this.submitBtn) {
|
|
8827
10152
|
this.submitBtn.disabled = true;
|
|
8828
|
-
this.submitBtn.innerHTML =
|
|
10153
|
+
this.submitBtn.innerHTML =
|
|
10154
|
+
editingId !== null
|
|
10155
|
+
? `<span>Saving...</span>`
|
|
10156
|
+
: commentingId !== null
|
|
10157
|
+
? `<span>Posting...</span>`
|
|
10158
|
+
: `<span>Sending...</span>`;
|
|
8829
10159
|
}
|
|
8830
10160
|
|
|
8831
10161
|
try {
|
|
8832
|
-
const submittedElements =
|
|
8833
|
-
const submittedAttachments
|
|
10162
|
+
const submittedElements = structuredClone(this.elementReferences);
|
|
10163
|
+
const submittedAttachments = this.attachments.map((att) => ({
|
|
8834
10164
|
id: att.id,
|
|
10165
|
+
server_id: att.existing_attachment_id,
|
|
8835
10166
|
label: att.label,
|
|
8836
10167
|
preview_url: att.preview_url,
|
|
8837
|
-
attachment_type: att.attachment_type
|
|
10168
|
+
attachment_type: att.attachment_type,
|
|
10169
|
+
filename: att.filename,
|
|
10170
|
+
signed_blob_id: att.signed_blob_id,
|
|
10171
|
+
data_url: att.data_url,
|
|
10172
|
+
element_reference_ref: att.element_reference_ref || null,
|
|
10173
|
+
metadata: att.metadata ? structuredClone(att.metadata) : {}
|
|
8838
10174
|
}));
|
|
8839
10175
|
|
|
10176
|
+
const commonMetadata = {
|
|
10177
|
+
...this.customMetadata,
|
|
10178
|
+
environment: this.config.environment,
|
|
10179
|
+
selection_mode: smartMode ? "smart" : "verbose",
|
|
10180
|
+
viewport: {
|
|
10181
|
+
width: typeof window !== "undefined" ? window.innerWidth : 0,
|
|
10182
|
+
height: typeof window !== "undefined" ? window.innerHeight : 0
|
|
10183
|
+
},
|
|
10184
|
+
locale: typeof navigator !== "undefined" ? navigator.language : "en"
|
|
10185
|
+
};
|
|
10186
|
+
|
|
10187
|
+
if (commentingId !== null) {
|
|
10188
|
+
const existingIdx = this.sessionHistory.findIndex(
|
|
10189
|
+
(item) => String(item.id) === commentingId
|
|
10190
|
+
);
|
|
10191
|
+
const existingEntry = existingIdx >= 0 ? this.sessionHistory[existingIdx] : undefined;
|
|
10192
|
+
|
|
10193
|
+
const commentPayload = {
|
|
10194
|
+
body: message,
|
|
10195
|
+
attachments: this.attachments.map((att) => ({
|
|
10196
|
+
attachment_type: att.attachment_type,
|
|
10197
|
+
filename: att.filename,
|
|
10198
|
+
signed_blob_id: att.signed_blob_id,
|
|
10199
|
+
data_url: att.signed_blob_id ? undefined : att.data_url,
|
|
10200
|
+
metadata: att.metadata
|
|
10201
|
+
}))
|
|
10202
|
+
};
|
|
10203
|
+
|
|
10204
|
+
const commentRes = await this.apiClient.createComment(
|
|
10205
|
+
existingEntry?.id ?? commentingId,
|
|
10206
|
+
commentPayload,
|
|
10207
|
+
existingEntry?.ownershipToken
|
|
10208
|
+
);
|
|
10209
|
+
|
|
10210
|
+
if (commentRes?.feedback) {
|
|
10211
|
+
const updatedEntry = this.mapOwnRecordToSessionEntry(commentRes.feedback, existingEntry);
|
|
10212
|
+
if (existingIdx >= 0) {
|
|
10213
|
+
this.sessionHistory[existingIdx] = updatedEntry;
|
|
10214
|
+
}
|
|
10215
|
+
} else if (existingEntry) {
|
|
10216
|
+
existingEntry.status = commentRes?.status || "updated";
|
|
10217
|
+
if (!existingEntry.comments) existingEntry.comments = [];
|
|
10218
|
+
existingEntry.comments.push({
|
|
10219
|
+
id: commentRes?.id ?? Date.now(),
|
|
10220
|
+
author_label: commentRes?.comment?.author_label || "You",
|
|
10221
|
+
body: message || null,
|
|
10222
|
+
createdAt: this.formatTimestampLabel(commentRes?.created_at),
|
|
10223
|
+
attachments: submittedAttachments
|
|
10224
|
+
});
|
|
10225
|
+
}
|
|
10226
|
+
|
|
10227
|
+
this.cancelCommentingFeedback();
|
|
10228
|
+
this.showStatus("Comment added.", "success");
|
|
10229
|
+
this.emitWidgetEvent("context-drop:comment", {
|
|
10230
|
+
response: commentRes,
|
|
10231
|
+
payload: commentPayload
|
|
10232
|
+
});
|
|
10233
|
+
return;
|
|
10234
|
+
}
|
|
10235
|
+
|
|
10236
|
+
if (editingId !== null) {
|
|
10237
|
+
const existingIdx = this.sessionHistory.findIndex(
|
|
10238
|
+
(item) => String(item.id) === editingId
|
|
10239
|
+
);
|
|
10240
|
+
const existingEntry = existingIdx >= 0 ? this.sessionHistory[existingIdx] : undefined;
|
|
10241
|
+
|
|
10242
|
+
const updatePayload = {
|
|
10243
|
+
message,
|
|
10244
|
+
metadata: commonMetadata,
|
|
10245
|
+
element_references: this.elementReferences,
|
|
10246
|
+
attachments: this.attachments.map((att) => {
|
|
10247
|
+
if (att.existing_attachment_id !== undefined && att.existing_attachment_id !== null) {
|
|
10248
|
+
return {
|
|
10249
|
+
existing_id: att.existing_attachment_id,
|
|
10250
|
+
attachment_type: att.attachment_type,
|
|
10251
|
+
element_reference_ref: att.element_reference_ref,
|
|
10252
|
+
metadata: att.metadata
|
|
10253
|
+
};
|
|
10254
|
+
}
|
|
10255
|
+
return {
|
|
10256
|
+
attachment_type: att.attachment_type,
|
|
10257
|
+
filename: att.filename,
|
|
10258
|
+
signed_blob_id: att.signed_blob_id,
|
|
10259
|
+
data_url: att.signed_blob_id ? undefined : att.data_url,
|
|
10260
|
+
element_reference_ref: att.element_reference_ref,
|
|
10261
|
+
metadata: att.metadata
|
|
10262
|
+
};
|
|
10263
|
+
})
|
|
10264
|
+
};
|
|
10265
|
+
|
|
10266
|
+
const updateRes = await this.apiClient.updateFeedback(
|
|
10267
|
+
existingEntry?.id ?? editingId,
|
|
10268
|
+
updatePayload,
|
|
10269
|
+
existingEntry?.ownershipToken
|
|
10270
|
+
);
|
|
10271
|
+
|
|
10272
|
+
const mergedPreviewStub = {
|
|
10273
|
+
id: existingEntry?.id ?? updateRes?.id ?? editingId,
|
|
10274
|
+
message:
|
|
10275
|
+
message || (smartMode ? "(Highlighted page area)" : "(Context drop without text)"),
|
|
10276
|
+
rawMessage: message,
|
|
10277
|
+
createdAt: existingEntry?.createdAt || this.formatTimestampLabel(updateRes?.created_at),
|
|
10278
|
+
rawCreatedAt: existingEntry?.rawCreatedAt || updateRes?.created_at,
|
|
10279
|
+
rawUpdatedAt: updateRes?.updated_at || new Date().toISOString(),
|
|
10280
|
+
isEdited: true,
|
|
10281
|
+
status: updateRes?.status || existingEntry?.status,
|
|
10282
|
+
ownershipToken:
|
|
10283
|
+
updateRes?.ownership_token ||
|
|
10284
|
+
updateRes?.feedback?.ownership_token ||
|
|
10285
|
+
existingEntry?.ownershipToken,
|
|
10286
|
+
elements: submittedElements,
|
|
10287
|
+
attachments: submittedAttachments
|
|
10288
|
+
};
|
|
10289
|
+
|
|
10290
|
+
const updatedEntry = updateRes?.feedback
|
|
10291
|
+
? {
|
|
10292
|
+
...this.mapOwnRecordToSessionEntry(updateRes.feedback, mergedPreviewStub),
|
|
10293
|
+
isEdited: true
|
|
10294
|
+
}
|
|
10295
|
+
: mergedPreviewStub;
|
|
10296
|
+
|
|
10297
|
+
if (existingIdx >= 0) {
|
|
10298
|
+
this.sessionHistory[existingIdx] = updatedEntry;
|
|
10299
|
+
} else {
|
|
10300
|
+
this.sessionHistory.push(updatedEntry);
|
|
10301
|
+
}
|
|
10302
|
+
|
|
10303
|
+
this.cancelEditingFeedback();
|
|
10304
|
+
this.showStatus(
|
|
10305
|
+
smartMode ? "Your feedback was updated." : "Feedback updated.",
|
|
10306
|
+
"success"
|
|
10307
|
+
);
|
|
10308
|
+
this.emitWidgetEvent("context-drop:update", {
|
|
10309
|
+
response: updateRes,
|
|
10310
|
+
payload: updatePayload
|
|
10311
|
+
});
|
|
10312
|
+
return;
|
|
10313
|
+
}
|
|
10314
|
+
|
|
8840
10315
|
const payload = {
|
|
8841
10316
|
message,
|
|
8842
10317
|
page_url: typeof window !== "undefined" ? window.location.href : "/",
|
|
8843
10318
|
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
|
|
8844
|
-
metadata:
|
|
8845
|
-
...this.customMetadata,
|
|
8846
|
-
environment: this.config.environment,
|
|
8847
|
-
selection_mode: smartMode ? "smart" : "verbose",
|
|
8848
|
-
viewport: {
|
|
8849
|
-
width: typeof window !== "undefined" ? window.innerWidth : 0,
|
|
8850
|
-
height: typeof window !== "undefined" ? window.innerHeight : 0
|
|
8851
|
-
},
|
|
8852
|
-
locale: typeof navigator !== "undefined" ? navigator.language : "en"
|
|
8853
|
-
},
|
|
10319
|
+
metadata: commonMetadata,
|
|
8854
10320
|
element_references: this.elementReferences,
|
|
8855
10321
|
attachments: this.attachments.map((att) => ({
|
|
8856
10322
|
attachment_type: att.attachment_type,
|
|
@@ -8866,14 +10332,26 @@
|
|
|
8866
10332
|
|
|
8867
10333
|
const now = new Date();
|
|
8868
10334
|
const timeLabel = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
|
|
8869
|
-
|
|
10335
|
+
const localStub = {
|
|
8870
10336
|
id: res?.id ?? this.sessionHistory.length + 1,
|
|
8871
10337
|
message:
|
|
8872
10338
|
message || (smartMode ? "(Highlighted page area)" : "(Context drop without text)"),
|
|
10339
|
+
rawMessage: message,
|
|
8873
10340
|
createdAt: timeLabel,
|
|
10341
|
+
rawCreatedAt: res?.created_at,
|
|
10342
|
+
rawUpdatedAt: res?.updated_at || res?.created_at,
|
|
10343
|
+
isEdited: false,
|
|
10344
|
+
status: res?.status,
|
|
10345
|
+
ownershipToken: res?.ownership_token || res?.feedback?.ownership_token,
|
|
8874
10346
|
elements: submittedElements,
|
|
8875
10347
|
attachments: submittedAttachments
|
|
8876
|
-
}
|
|
10348
|
+
};
|
|
10349
|
+
|
|
10350
|
+
const createdEntry = res?.feedback
|
|
10351
|
+
? this.mapOwnRecordToSessionEntry(res.feedback, localStub)
|
|
10352
|
+
: localStub;
|
|
10353
|
+
|
|
10354
|
+
this.sessionHistory.push(createdEntry);
|
|
8877
10355
|
|
|
8878
10356
|
if (this.textareaEl) {
|
|
8879
10357
|
this.textareaEl.value = "";
|
|
@@ -8894,7 +10372,12 @@
|
|
|
8894
10372
|
payload
|
|
8895
10373
|
});
|
|
8896
10374
|
} catch (err) {
|
|
8897
|
-
const msg =
|
|
10375
|
+
const msg =
|
|
10376
|
+
err instanceof Error
|
|
10377
|
+
? err.message
|
|
10378
|
+
: editingId !== null
|
|
10379
|
+
? "Failed to update feedback."
|
|
10380
|
+
: "Failed to submit feedback.";
|
|
8898
10381
|
this.showStatus(msg, "error");
|
|
8899
10382
|
this.emitWidgetEvent("context-drop:error", {
|
|
8900
10383
|
error: msg
|
|
@@ -8903,8 +10386,15 @@
|
|
|
8903
10386
|
this.isSubmitting = false;
|
|
8904
10387
|
if (this.submitBtn) {
|
|
8905
10388
|
this.submitBtn.disabled = false;
|
|
8906
|
-
this.
|
|
10389
|
+
if (this.editingFeedbackId !== null) {
|
|
10390
|
+
this.submitBtn.setAttribute("aria-label", "Save feedback changes");
|
|
10391
|
+
this.submitBtn.innerHTML = `${ICON_CHECK}<span>Save</span>`;
|
|
10392
|
+
} else {
|
|
10393
|
+
this.submitBtn.setAttribute("aria-label", "Submit feedback");
|
|
10394
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Send</span>`;
|
|
10395
|
+
}
|
|
8907
10396
|
}
|
|
10397
|
+
this.renderChatThread();
|
|
8908
10398
|
}
|
|
8909
10399
|
}
|
|
8910
10400
|
|