glitchgrab 1.19.2 → 1.20.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/dist/index.mjs CHANGED
@@ -269,6 +269,30 @@ async function sendReport(payload, baseUrl) {
269
269
  return null;
270
270
  }
271
271
  }
272
+ async function enhanceText(text, token, baseUrl) {
273
+ var _a;
274
+ try {
275
+ const trimmed = text.trim();
276
+ if (!trimmed) return text;
277
+ const url = `${baseUrl != null ? baseUrl : DEFAULT_BASE_URL}/api/v1/ai/enhance-text`;
278
+ const response = await fetch(url, {
279
+ method: "POST",
280
+ headers: {
281
+ "Content-Type": "application/json",
282
+ Authorization: `Bearer ${token}`
283
+ },
284
+ body: JSON.stringify({ text: trimmed })
285
+ });
286
+ if (!response.ok) return text;
287
+ const envelope = await response.json();
288
+ if ((envelope == null ? void 0 : envelope.success) && typeof ((_a = envelope.data) == null ? void 0 : _a.text) === "string") {
289
+ return envelope.data.text;
290
+ }
291
+ return text;
292
+ } catch (e) {
293
+ return text;
294
+ }
295
+ }
272
296
 
273
297
  // src/dedup.ts
274
298
  var DEFAULT_WINDOW_MS = 5 * 60 * 1e3;
@@ -540,9 +564,11 @@ function isLowQualityText(text) {
540
564
  }
541
565
  function ReportDialog({
542
566
  report,
567
+ enhanceText: enhanceText2,
543
568
  types,
544
569
  showSeverity = true
545
570
  }) {
571
+ const [isEnhancing, setIsEnhancing] = useState(false);
546
572
  const [mounted, setMounted] = useState(false);
547
573
  useEffect(() => {
548
574
  setMounted(true);
@@ -884,38 +910,83 @@ function ReportDialog({
884
910
  type
885
911
  )) }),
886
912
  step === 2 && /* @__PURE__ */ jsxs(Fragment, { children: [
887
- /* @__PURE__ */ jsx(
888
- "textarea",
889
- {
890
- value: description,
891
- onChange: (e) => {
892
- setDescription(e.target.value);
893
- if (validationError) setValidationError(null);
894
- },
895
- placeholder: getPlaceholder(reportType),
896
- style: {
897
- width: "100%",
898
- minHeight: "100px",
899
- padding: "10px 12px",
900
- borderRadius: "8px",
901
- border: `1px solid ${t.inputBorder}`,
902
- fontSize: "14px",
903
- fontFamily: "inherit",
904
- resize: "vertical",
905
- outline: "none",
906
- boxSizing: "border-box",
907
- color: t.text,
908
- backgroundColor: t.inputBg
909
- },
910
- onFocus: (e) => {
911
- e.target.style.borderColor = t.accent;
912
- },
913
- onBlur: (e) => {
914
- e.target.style.borderColor = t.inputBorder;
915
- },
916
- autoFocus: true
917
- }
918
- ),
913
+ /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
914
+ /* @__PURE__ */ jsx(
915
+ "textarea",
916
+ {
917
+ value: description,
918
+ onChange: (e) => {
919
+ setDescription(e.target.value);
920
+ if (validationError) setValidationError(null);
921
+ },
922
+ placeholder: getPlaceholder(reportType),
923
+ style: {
924
+ width: "100%",
925
+ minHeight: "100px",
926
+ padding: enhanceText2 ? "28px 12px 10px" : "10px 12px",
927
+ borderRadius: "8px",
928
+ border: `1px solid ${t.inputBorder}`,
929
+ fontSize: "14px",
930
+ fontFamily: "inherit",
931
+ resize: "vertical",
932
+ outline: "none",
933
+ boxSizing: "border-box",
934
+ color: t.text,
935
+ backgroundColor: t.inputBg
936
+ },
937
+ onFocus: (e) => {
938
+ e.target.style.borderColor = t.accent;
939
+ },
940
+ onBlur: (e) => {
941
+ e.target.style.borderColor = t.inputBorder;
942
+ },
943
+ autoFocus: true
944
+ }
945
+ ),
946
+ enhanceText2 && /* @__PURE__ */ jsxs(
947
+ "button",
948
+ {
949
+ type: "button",
950
+ onClick: async () => {
951
+ if (!description.trim() || isEnhancing) return;
952
+ setIsEnhancing(true);
953
+ try {
954
+ const polished = await enhanceText2(description);
955
+ if (polished && polished !== description) {
956
+ setDescription(polished);
957
+ if (validationError) setValidationError(null);
958
+ }
959
+ } finally {
960
+ setIsEnhancing(false);
961
+ }
962
+ },
963
+ disabled: !description.trim() || isEnhancing,
964
+ style: {
965
+ position: "absolute",
966
+ top: "6px",
967
+ right: "6px",
968
+ display: "inline-flex",
969
+ alignItems: "center",
970
+ gap: "4px",
971
+ background: t.inputBg,
972
+ border: "none",
973
+ padding: "2px 6px",
974
+ borderRadius: "4px",
975
+ fontFamily: "inherit",
976
+ fontSize: "11px",
977
+ color: t.textMuted,
978
+ cursor: !description.trim() || isEnhancing ? "default" : "pointer",
979
+ opacity: !description.trim() ? 0.5 : 1,
980
+ zIndex: 1
981
+ },
982
+ title: "Polish grammar \u2014 preserves your meaning",
983
+ children: [
984
+ /* @__PURE__ */ jsx("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5L12 3zM19 15l.75 2.25L22 18l-2.25.75L19 21l-.75-2.25L16 18l2.25-.75L19 15z", stroke: t.textMuted, strokeWidth: "1.5", strokeLinejoin: "round" }) }),
985
+ isEnhancing ? "Enhancing..." : "AI enhance"
986
+ ]
987
+ }
988
+ )
989
+ ] }),
919
990
  showSeverity && reportType === "BUG" && /* @__PURE__ */ jsxs("div", { style: { marginTop: "10px" }, children: [
920
991
  /* @__PURE__ */ jsx("span", { style: { fontSize: "12px", color: t.textMuted, marginBottom: "6px", display: "block" }, children: "Severity" }),
921
992
  /* @__PURE__ */ jsx("div", { style: { display: "flex", gap: "6px" }, children: ["low", "medium", "high"].map((s) => /* @__PURE__ */ jsx(
@@ -1336,6 +1407,10 @@ function GlitchgrabProviderInner({
1336
1407
  const handleError = (event) => {
1337
1408
  var _a, _b, _c, _d, _e, _f;
1338
1409
  try {
1410
+ const isOpaqueCrossOrigin = event.message === "Script error." || event.message === "Script error" || !event.error && !event.filename;
1411
+ if (isOpaqueCrossOrigin) {
1412
+ return;
1413
+ }
1339
1414
  const context = captureContext(visitedPagesRef.current);
1340
1415
  const sig = computeSignature({
1341
1416
  errorMessage: event.message,
@@ -1378,6 +1453,9 @@ function GlitchgrabProviderInner({
1378
1453
  const context = captureContext(visitedPagesRef.current);
1379
1454
  const reason = event.reason;
1380
1455
  const errMsg = reason instanceof Error ? reason.message : String(reason);
1456
+ if (errMsg === "Script error." || errMsg === "Script error") {
1457
+ return;
1458
+ }
1381
1459
  const errStack = reason instanceof Error ? reason.stack : void 0;
1382
1460
  const sig = computeSignature({
1383
1461
  errorMessage: errMsg,
@@ -1464,6 +1542,16 @@ function GlitchgrabProviderInner({
1464
1542
  },
1465
1543
  []
1466
1544
  );
1545
+ const enhance = useCallback(
1546
+ async (text) => {
1547
+ try {
1548
+ return await enhanceText(text, token, baseUrl);
1549
+ } catch (e) {
1550
+ return text;
1551
+ }
1552
+ },
1553
+ [token, baseUrl]
1554
+ );
1467
1555
  const openReportDialog = useCallback((options) => {
1468
1556
  if (typeof window !== "undefined") {
1469
1557
  window.dispatchEvent(new CustomEvent("glitchgrab:open-report", { detail: options }));
@@ -1492,7 +1580,8 @@ function GlitchgrabProviderInner({
1492
1580
  reportBug,
1493
1581
  report,
1494
1582
  addBreadcrumb: addBreadcrumb2,
1495
- openReportDialog
1583
+ openReportDialog,
1584
+ enhanceText: enhance
1496
1585
  },
1497
1586
  children: [
1498
1587
  /* @__PURE__ */ jsx2(
@@ -1507,7 +1596,7 @@ function GlitchgrabProviderInner({
1507
1596
  children
1508
1597
  }
1509
1598
  ),
1510
- /* @__PURE__ */ jsx2(ReportDialog, { report, types, showSeverity })
1599
+ /* @__PURE__ */ jsx2(ReportDialog, { report, enhanceText: enhance, types, showSeverity })
1511
1600
  ]
1512
1601
  }
1513
1602
  );
@@ -1732,6 +1821,7 @@ export {
1732
1821
  clearBreadcrumbs,
1733
1822
  clearDedupCache,
1734
1823
  computeSignature,
1824
+ enhanceText,
1735
1825
  fetchGlitchgrabReports,
1736
1826
  getBreadcrumbs,
1737
1827
  initBreadcrumbs,