glitchgrab 1.65.2 → 1.66.0

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.js CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  FeedbackButton: () => FeedbackButton,
37
37
  GLITCHGRAB_SHORTCUT: () => GLITCHGRAB_SHORTCUT2,
38
38
  GLITCHGRAB_SHORTCUT_MAC: () => GLITCHGRAB_SHORTCUT_MAC2,
39
+ GlitchgrabCallIssue: () => GlitchgrabCallIssue,
39
40
  GlitchgrabErrorBoundary: () => GlitchgrabErrorBoundary,
40
41
  GlitchgrabProvider: () => GlitchgrabProvider,
41
42
  ReportButton: () => ReportButton,
@@ -9035,7 +9036,7 @@ function getPlaceholder(type, idx = 0, hasVoice = false) {
9035
9036
  case "OTHER":
9036
9037
  return "Tell us what's on your mind...";
9037
9038
  case "VIDEO_SCRIPT":
9038
- return "Paste the script, and say which screens the video should show...";
9039
+ return "Describe the video or paste a script, and say which screens it should show...";
9039
9040
  }
9040
9041
  }
9041
9042
  function getTypeIcon(type, color, size = 24) {
@@ -9162,6 +9163,70 @@ function getTypeIcon(type, color, size = 24) {
9162
9163
  // src/booking-dialog.tsx
9163
9164
  var import_react5 = require("react");
9164
9165
 
9166
+ // src/calendar-links.ts
9167
+ function stamp(iso) {
9168
+ return new Date(iso).toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
9169
+ }
9170
+ function details(ev) {
9171
+ return [ev.description, ev.meetUrl ? `Join: ${ev.meetUrl}` : null].filter(Boolean).join("\n\n");
9172
+ }
9173
+ function googleCalendarUrl(ev) {
9174
+ const params = new URLSearchParams({
9175
+ action: "TEMPLATE",
9176
+ text: ev.title,
9177
+ dates: `${stamp(ev.startsAt)}/${stamp(ev.endsAt)}`,
9178
+ details: details(ev)
9179
+ });
9180
+ if (ev.meetUrl) params.set("location", ev.meetUrl);
9181
+ return `https://calendar.google.com/calendar/render?${params.toString()}`;
9182
+ }
9183
+ function esc(s) {
9184
+ return s.replace(/\\/g, "\\\\").replace(/;/g, ";").replace(/,/g, "\\,").replace(/\r?\n/g, "\\n");
9185
+ }
9186
+ function fold(line) {
9187
+ const out = [];
9188
+ let rest = line;
9189
+ while (rest.length > 74) {
9190
+ out.push(rest.slice(0, 74));
9191
+ rest = ` ${rest.slice(74)}`;
9192
+ }
9193
+ out.push(rest);
9194
+ return out.join("\r\n");
9195
+ }
9196
+ function buildIcs(ev) {
9197
+ const lines = [
9198
+ "BEGIN:VCALENDAR",
9199
+ "VERSION:2.0",
9200
+ "PRODID:-//Glitchgrab//Booking//EN",
9201
+ "CALSCALE:GREGORIAN",
9202
+ "METHOD:PUBLISH",
9203
+ "BEGIN:VEVENT",
9204
+ `UID:${ev.id}@glitchgrab.dev`,
9205
+ `DTSTAMP:${stamp((/* @__PURE__ */ new Date()).toISOString())}`,
9206
+ `DTSTART:${stamp(ev.startsAt)}`,
9207
+ `DTEND:${stamp(ev.endsAt)}`,
9208
+ `SUMMARY:${esc(ev.title)}`,
9209
+ `DESCRIPTION:${esc(details(ev))}`,
9210
+ ...ev.meetUrl ? [`LOCATION:${esc(ev.meetUrl)}`, `URL:${ev.meetUrl}`] : [],
9211
+ // 15 minutes before — the calendar's own reminder, the point of the feature.
9212
+ "BEGIN:VALARM",
9213
+ "ACTION:DISPLAY",
9214
+ "DESCRIPTION:Demo starts in 15 minutes",
9215
+ "TRIGGER:-PT15M",
9216
+ "END:VALARM",
9217
+ "END:VEVENT",
9218
+ "END:VCALENDAR"
9219
+ ];
9220
+ return lines.map(fold).join("\r\n") + "\r\n";
9221
+ }
9222
+ function icsDownloadUrl(ev) {
9223
+ try {
9224
+ return URL.createObjectURL(new Blob([buildIcs(ev)], { type: "text/calendar;charset=utf-8" }));
9225
+ } catch (e) {
9226
+ return null;
9227
+ }
9228
+ }
9229
+
9165
9230
  // src/phone.ts
9166
9231
  var COUNTRIES = [
9167
9232
  { iso: "IN", name: "India", dial: "91" },
@@ -9229,10 +9294,12 @@ function readQuestions(value) {
9229
9294
  if (!Array.isArray(value)) return [];
9230
9295
  return value.flatMap((row) => {
9231
9296
  if (!row || typeof row !== "object") return [];
9232
- const { id, label, options, required } = row;
9233
- if (typeof id !== "string" || typeof label !== "string" || !Array.isArray(options)) return [];
9297
+ const { id, label, options, required, type } = row;
9298
+ if (typeof id !== "string" || typeof label !== "string") return [];
9299
+ if (type === "text") return [{ id, label, type: "text", options: [], required: required !== false }];
9300
+ if (!Array.isArray(options)) return [];
9234
9301
  const choices = options.filter((o) => typeof o === "string" && o !== "");
9235
- return choices.length > 0 ? [{ id, label, options: choices, required: required !== false }] : [];
9302
+ return choices.length > 0 ? [{ id, label, type: "choice", options: choices, required: required !== false }] : [];
9236
9303
  });
9237
9304
  }
9238
9305
  var LIGHT = {
@@ -9396,6 +9463,7 @@ function BookingDialog({
9396
9463
  const [dial, setDial] = (0, import_react5.useState)(() => defaultDialForZone(localZone()));
9397
9464
  const [phoneTouched, setPhoneTouched] = (0, import_react5.useState)(false);
9398
9465
  const [tried, setTried] = (0, import_react5.useState)(false);
9466
+ const [toast, setToast] = (0, import_react5.useState)(null);
9399
9467
  const [questions, setQuestions] = (0, import_react5.useState)([]);
9400
9468
  const [answers, setAnswers] = (0, import_react5.useState)({});
9401
9469
  const [pageLoaded, setPageLoaded] = (0, import_react5.useState)(false);
@@ -9499,8 +9567,14 @@ function BookingDialog({
9499
9567
  const daySlots = day ? (_d = byDay.get(day)) != null ? _d : [] : [];
9500
9568
  const atFirstMonth = month <= today.slice(0, 7);
9501
9569
  const pastHorizon = monthLoaded && !error && byDay.size === 0 && !atFirstMonth;
9502
- const given = questions.flatMap((q) => q.options.includes(answers[q.id]) ? [{ ...q, answer: answers[q.id] }] : []);
9503
- const unanswered = questions.filter((q) => q.required && !q.options.includes(answers[q.id]));
9570
+ const isAnswered = (q) => {
9571
+ var _a2;
9572
+ return q.type === "text" ? Boolean((_a2 = answers[q.id]) == null ? void 0 : _a2.trim()) : q.options.includes(answers[q.id]);
9573
+ };
9574
+ const given = questions.flatMap(
9575
+ (q) => isAnswered(q) ? [{ ...q, answer: q.type === "text" ? answers[q.id].trim() : answers[q.id] }] : []
9576
+ );
9577
+ const unanswered = questions.filter((q) => q.required && !isAnswered(q));
9504
9578
  const phoneError = phoneProblem(dial, phone);
9505
9579
  const nameMissing = !name.trim();
9506
9580
  const emailMissing = !email.includes("@");
@@ -9511,12 +9585,25 @@ function BookingDialog({
9511
9585
  ...unanswered.map((q) => `an answer to \u201C${q.label}\u201D`),
9512
9586
  ...selected ? [] : ["a day and time"]
9513
9587
  ];
9588
+ (0, import_react5.useEffect)(() => {
9589
+ if (!toast) return;
9590
+ const id = setTimeout(() => setToast(null), 4500);
9591
+ return () => clearTimeout(id);
9592
+ }, [toast]);
9514
9593
  const roomy = step === "pick";
9515
9594
  async function startBooking() {
9516
- var _a2, _b2, _c2;
9595
+ var _a2, _b2, _c2, _d2;
9517
9596
  if (missing.length > 0 || !selected) {
9518
9597
  setTried(true);
9519
9598
  setPhoneTouched(true);
9599
+ const parts = [
9600
+ ...nameMissing ? ["your name"] : [],
9601
+ ...phoneError ? ["a valid mobile number"] : [],
9602
+ ...emailMissing ? ["your email"] : [],
9603
+ ...unanswered.length ? [unanswered.length === 1 ? "1 required answer" : `${unanswered.length} required answers`] : [],
9604
+ ...selected ? [] : ["a day and time"]
9605
+ ];
9606
+ setToast(`Add ${parts.length > 1 ? `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}` : parts[0]}`);
9520
9607
  return;
9521
9608
  }
9522
9609
  if (preview) {
@@ -9548,9 +9635,10 @@ function BookingDialog({
9548
9635
  return;
9549
9636
  }
9550
9637
  if (json.data.confirmed) {
9551
- setMeetUrl((_b2 = json.data.meetUrl) != null ? _b2 : null);
9638
+ setBookingId((_b2 = json.data.bookingId) != null ? _b2 : null);
9639
+ setMeetUrl((_c2 = json.data.meetUrl) != null ? _c2 : null);
9552
9640
  setStep("done");
9553
- reportBooked(json.data.bookingId, (_c2 = json.data.meetUrl) != null ? _c2 : null);
9641
+ reportBooked(json.data.bookingId, (_d2 = json.data.meetUrl) != null ? _d2 : null);
9554
9642
  return;
9555
9643
  }
9556
9644
  setBookingId(json.data.bookingId);
@@ -9597,6 +9685,7 @@ function BookingDialog({
9597
9685
  const selectedEnd = selected ? (_e = selected.endsAt) != null ? _e : new Date(new Date(selected.startsAt).getTime() + page.slotMinutes * 6e4).toISOString() : null;
9598
9686
  const monthDate = new Date(keyToUtc(`${month}-01`));
9599
9687
  const muted = { color: t.muted };
9688
+ const calendarEvent = step === "done" && bookingId && selected && selectedEnd ? { id: bookingId, title: page.title, startsAt: selected.startsAt, endsAt: selectedEnd, meetUrl } : null;
9600
9689
  const credit = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
9601
9690
  "div",
9602
9691
  {
@@ -10034,7 +10123,7 @@ function BookingDialog({
10034
10123
  }
10035
10124
  )
10036
10125
  ] });
10037
- const details = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
10126
+ const details2 = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
10038
10127
  "div",
10039
10128
  {
10040
10129
  style: {
@@ -10088,7 +10177,22 @@ function BookingDialog({
10088
10177
  ),
10089
10178
  !pageLoaded && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { fontSize: 13, ...muted }, children: "Loading\u2026" }),
10090
10179
  questions.map((q) => {
10180
+ var _a2;
10091
10181
  const gap = tried && unanswered.includes(q);
10182
+ if (q.type === "text") {
10183
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
10184
+ Field,
10185
+ {
10186
+ t,
10187
+ label: q.required ? q.label : `${q.label} (optional)`,
10188
+ value: (_a2 = answers[q.id]) != null ? _a2 : "",
10189
+ onChange: (v) => setAnswers((prev) => ({ ...prev, [q.id]: v })),
10190
+ maxLength: 300,
10191
+ error: gap ? "Please fill this in" : null
10192
+ },
10193
+ q.id
10194
+ );
10195
+ }
10092
10196
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { role: "group", "aria-label": q.label, children: [
10093
10197
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { fontSize: 13, fontWeight: 500, overflowWrap: "anywhere" }, children: [
10094
10198
  q.label,
@@ -10177,7 +10281,7 @@ function BookingDialog({
10177
10281
  onClick: startBooking,
10178
10282
  disabled: busy,
10179
10283
  "aria-disabled": missing.length > 0,
10180
- style: { ...primaryStyle(t, busy || missing.length > 0), cursor: busy ? "default" : "pointer", whiteSpace: "nowrap" },
10284
+ style: { ...primaryStyle(t, busy), cursor: busy ? "default" : "pointer", whiteSpace: "nowrap" },
10181
10285
  children: requireOtp ? busy ? "Sending code\u2026" : "Send verification code" : busy ? "Booking\u2026" : "Book demo"
10182
10286
  }
10183
10287
  )
@@ -10229,6 +10333,41 @@ function BookingDialog({
10229
10333
  email,
10230
10334
  ", and we'll send a WhatsApp reminder before the call."
10231
10335
  ] }),
10336
+ calendarEvent && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "flex", flexWrap: "wrap", gap: 8 }, children: [
10337
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
10338
+ "a",
10339
+ {
10340
+ href: googleCalendarUrl(calendarEvent),
10341
+ target: "_blank",
10342
+ rel: "noreferrer",
10343
+ style: { ...primaryStyle(t, false), textDecoration: "none" },
10344
+ children: "Add to Google Calendar"
10345
+ }
10346
+ ),
10347
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
10348
+ "button",
10349
+ {
10350
+ type: "button",
10351
+ onClick: () => {
10352
+ const url = icsDownloadUrl(calendarEvent);
10353
+ if (!url) return;
10354
+ const a = document.createElement("a");
10355
+ a.href = url;
10356
+ a.download = "demo.ics";
10357
+ a.click();
10358
+ setTimeout(() => URL.revokeObjectURL(url), 1e3);
10359
+ },
10360
+ style: {
10361
+ ...primaryStyle(t, false),
10362
+ background: "transparent",
10363
+ color: t.ink,
10364
+ border: `1px solid ${t.border}`,
10365
+ cursor: "pointer"
10366
+ },
10367
+ children: "Download .ics (Outlook, Apple)"
10368
+ }
10369
+ )
10370
+ ] }),
10232
10371
  meetUrl && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
10233
10372
  "a",
10234
10373
  {
@@ -10302,6 +10441,30 @@ function BookingDialog({
10302
10441
  lineHeight: 1.4
10303
10442
  },
10304
10443
  children: [
10444
+ toast && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
10445
+ "div",
10446
+ {
10447
+ role: "status",
10448
+ "aria-live": "polite",
10449
+ style: {
10450
+ position: "fixed",
10451
+ left: "50%",
10452
+ bottom: wide ? 88 : 96,
10453
+ transform: "translateX(-50%)",
10454
+ maxWidth: "min(480px, calc(100vw - 32px))",
10455
+ padding: "10px 16px",
10456
+ borderRadius: 10,
10457
+ background: t.ink,
10458
+ color: t.onInk,
10459
+ fontSize: 13,
10460
+ lineHeight: 1.5,
10461
+ fontWeight: 600,
10462
+ boxShadow: "0 8px 24px rgba(0,0,0,.35)",
10463
+ zIndex: 2147483647
10464
+ },
10465
+ children: toast
10466
+ }
10467
+ ),
10305
10468
  summary,
10306
10469
  roomy ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { flex: "1 1 auto", minWidth: 0, display: "flex", flexDirection: "column" }, children: [
10307
10470
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
@@ -10316,7 +10479,7 @@ function BookingDialog({
10316
10479
  overflowY: wide && !split ? "auto" : void 0
10317
10480
  },
10318
10481
  children: [
10319
- details,
10482
+ details2,
10320
10483
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
10321
10484
  "div",
10322
10485
  {
@@ -10450,6 +10613,7 @@ function Field({
10450
10613
  type = "text",
10451
10614
  autoComplete,
10452
10615
  inputMode,
10616
+ maxLength,
10453
10617
  error
10454
10618
  }) {
10455
10619
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { style: { display: "block", fontSize: 13, fontWeight: 500, color: t.text }, children: [
@@ -10461,6 +10625,7 @@ function Field({
10461
10625
  value,
10462
10626
  autoComplete,
10463
10627
  inputMode,
10628
+ maxLength,
10464
10629
  "aria-invalid": Boolean(error),
10465
10630
  onChange: (e) => onChange(e.target.value),
10466
10631
  style: {
@@ -10648,11 +10813,11 @@ function describeRejection(reason) {
10648
10813
  const source = reason;
10649
10814
  const nestedError = source.error;
10650
10815
  const message = (_h = (_g = (_f = (_e = (_d = (_c = (_b = readString(source.message)) != null ? _b : readString(nestedError)) != null ? _c : readString(nestedError == null ? void 0 : nestedError.message)) != null ? _d : readScalar(source.code)) != null ? _e : readString(source.name)) != null ? _f : readScalar(source.status)) != null ? _g : readString(source.statusText)) != null ? _h : "";
10651
- const details = serialize(reason);
10816
+ const details2 = serialize(reason);
10652
10817
  return {
10653
10818
  message: message || (isEventLike(reason) ? describeEvent(reason) : describeShape(reason)),
10654
10819
  stack,
10655
- details
10820
+ details: details2
10656
10821
  };
10657
10822
  } catch (e) {
10658
10823
  return { message: "" };
@@ -11494,19 +11659,337 @@ function FeedbackButton({
11494
11659
  );
11495
11660
  }
11496
11661
 
11497
- // src/use-reports.ts
11662
+ // src/call-issue-dialog.tsx
11498
11663
  var import_react8 = require("react");
11664
+ var import_jsx_runtime11 = require("react/jsx-runtime");
11665
+ var DEFAULT_BASE_URL3 = "https://glitchgrab.dev";
11666
+ var ApiError = class extends Error {
11667
+ constructor(message, status, code) {
11668
+ super(message);
11669
+ this.status = status;
11670
+ this.code = code;
11671
+ }
11672
+ };
11673
+ function formatDuration2(sec) {
11674
+ if (!sec || sec < 1) return "";
11675
+ return `${Math.floor(sec / 60)}:${String(Math.round(sec % 60)).padStart(2, "0")}`;
11676
+ }
11677
+ function readDraft(value) {
11678
+ if (!value || typeof value !== "object") return null;
11679
+ const v = value;
11680
+ if (typeof v.id !== "string" || typeof v.title !== "string") return null;
11681
+ return {
11682
+ id: v.id,
11683
+ title: v.title,
11684
+ body: typeof v.body === "string" ? v.body : "",
11685
+ labels: Array.isArray(v.labels) ? v.labels.filter((l) => typeof l === "string") : [],
11686
+ quotes: Array.isArray(v.quotes) ? v.quotes.filter((q) => !!q && typeof q.text === "string").slice(0, 3) : [],
11687
+ status: typeof v.status === "string" ? v.status : "DRAFT",
11688
+ githubNumber: typeof v.githubNumber === "number" ? v.githubNumber : null,
11689
+ githubUrl: typeof v.githubUrl === "string" ? v.githubUrl : null
11690
+ };
11691
+ }
11692
+ function GlitchgrabCallIssue({ callId, open, onClose, getToken, baseUrl, onFiled }) {
11693
+ var _a, _b;
11694
+ const base = (baseUrl || DEFAULT_BASE_URL3).replace(/\/+$/, "");
11695
+ const tokenRef = (0, import_react8.useRef)(null);
11696
+ const [loaded, setLoaded] = (0, import_react8.useState)(null);
11697
+ const [busy, setBusy] = (0, import_react8.useState)(null);
11698
+ const [error, setError] = (0, import_react8.useState)(null);
11699
+ const [picked, setPicked] = (0, import_react8.useState)(/* @__PURE__ */ new Set());
11700
+ const [filed, setFiled] = (0, import_react8.useState)([]);
11701
+ const [fixing, setFixing] = (0, import_react8.useState)(null);
11702
+ const [fixText, setFixText] = (0, import_react8.useState)("");
11703
+ const [fixBusy, setFixBusy] = (0, import_react8.useState)(false);
11704
+ const dark = typeof window !== "undefined" ? detectDark() : false;
11705
+ const accent = (_a = typeof window !== "undefined" ? detectHostAccent() : null) != null ? _a : { accent: "#3b82f6", accentText: "#fff" };
11706
+ const c = dark ? { bg: "#18181b", pane: "#222226", border: "#3f3f46", text: "#fafafa", muted: "#a1a1aa" } : { bg: "#ffffff", pane: "#f6f6f7", border: "#e4e4e7", text: "#18181b", muted: "#71717a" };
11707
+ const call = (0, import_react8.useCallback)(
11708
+ async (path, init = {}) => {
11709
+ var _a2, _b2, _c;
11710
+ for (let attempt = 0; attempt < 2; attempt++) {
11711
+ if (!tokenRef.current) tokenRef.current = await getToken(callId);
11712
+ const res = await fetch(`${base}/api/v1/sdk/call-issue/${encodeURIComponent(callId)}${path}`, {
11713
+ method: (_a2 = init.method) != null ? _a2 : "GET",
11714
+ headers: {
11715
+ Authorization: `Bearer ${tokenRef.current}`,
11716
+ ...init.body === void 0 ? {} : { "Content-Type": "application/json" }
11717
+ },
11718
+ ...init.body === void 0 ? {} : { body: JSON.stringify(init.body) }
11719
+ });
11720
+ const json = await res.json().catch(() => null);
11721
+ if (res.ok && (json == null ? void 0 : json.success)) return json.data;
11722
+ if (res.status === 401 && attempt === 0) {
11723
+ tokenRef.current = null;
11724
+ continue;
11725
+ }
11726
+ throw new ApiError((_b2 = json == null ? void 0 : json.error) != null ? _b2 : `HTTP ${res.status}`, res.status, (_c = json == null ? void 0 : json.code) != null ? _c : null);
11727
+ }
11728
+ throw new ApiError("Could not reach Glitchgrab", 0, null);
11729
+ },
11730
+ [base, callId, getToken]
11731
+ );
11732
+ const apply = (0, import_react8.useCallback)((data) => {
11733
+ const d = data != null ? data : {};
11734
+ const drafts = (Array.isArray(d.drafts) ? d.drafts : []).map(readDraft).filter((x) => x !== null);
11735
+ const callRaw = d.call;
11736
+ setLoaded((prev) => {
11737
+ var _a2, _b2;
11738
+ return {
11739
+ drafts,
11740
+ canExtract: d.canExtract !== false,
11741
+ extractedAt: typeof d.extractedAt === "string" ? d.extractedAt : (_a2 = prev == null ? void 0 : prev.extractedAt) != null ? _a2 : null,
11742
+ call: callRaw && typeof callRaw.pageUrl === "string" ? {
11743
+ title: typeof callRaw.title === "string" ? callRaw.title : null,
11744
+ at: typeof callRaw.at === "string" ? callRaw.at : "",
11745
+ durationSec: typeof callRaw.durationSec === "number" ? callRaw.durationSec : null,
11746
+ pageUrl: callRaw.pageUrl
11747
+ } : (_b2 = prev == null ? void 0 : prev.call) != null ? _b2 : null
11748
+ };
11749
+ });
11750
+ setPicked(new Set(drafts.filter((x) => x.status === "DRAFT").map((x) => x.id)));
11751
+ }, []);
11752
+ const read = (0, import_react8.useCallback)(async () => {
11753
+ setBusy("read");
11754
+ setError(null);
11755
+ try {
11756
+ const data = await call("/drafts", { method: "POST" });
11757
+ apply({ ...data, canExtract: true, extractedAt: (/* @__PURE__ */ new Date()).toISOString() });
11758
+ } catch (e) {
11759
+ setError(e instanceof Error ? e.message : "Could not read this call.");
11760
+ } finally {
11761
+ setBusy(null);
11762
+ }
11763
+ }, [apply, call]);
11764
+ (0, import_react8.useEffect)(() => {
11765
+ if (!open) return;
11766
+ let cancelled = false;
11767
+ setLoaded(null);
11768
+ setFiled([]);
11769
+ setError(null);
11770
+ setBusy("load");
11771
+ (async () => {
11772
+ try {
11773
+ const data = await call("/drafts");
11774
+ if (cancelled) return;
11775
+ apply(data);
11776
+ const hasDrafts = Array.isArray(data.drafts) && data.drafts.length > 0;
11777
+ if (!hasDrafts && data.canExtract !== false && !data.extractedAt) {
11778
+ setBusy(null);
11779
+ await read();
11780
+ }
11781
+ } catch (e) {
11782
+ if (!cancelled) setError(e instanceof Error ? e.message : "Could not open this call.");
11783
+ } finally {
11784
+ if (!cancelled) setBusy((b) => b === "load" ? null : b);
11785
+ }
11786
+ })();
11787
+ return () => {
11788
+ cancelled = true;
11789
+ };
11790
+ }, [open, callId]);
11791
+ (0, import_react8.useEffect)(() => {
11792
+ if (!open) return;
11793
+ const onKey = (e) => e.key === "Escape" && onClose();
11794
+ window.addEventListener("keydown", onKey);
11795
+ return () => window.removeEventListener("keydown", onKey);
11796
+ }, [open, onClose]);
11797
+ if (!open) return null;
11798
+ const active = ((_b = loaded == null ? void 0 : loaded.drafts) != null ? _b : []).filter((d) => d.status === "DRAFT");
11799
+ const chosen = active.filter((d) => picked.has(d.id));
11800
+ const discard = async (id) => {
11801
+ try {
11802
+ await call(`/drafts/${encodeURIComponent(id)}`, { method: "DELETE" });
11803
+ setLoaded((l) => l ? { ...l, drafts: l.drafts.filter((d) => d.id !== id) } : l);
11804
+ setPicked((p) => {
11805
+ const next = new Set(p);
11806
+ next.delete(id);
11807
+ return next;
11808
+ });
11809
+ } catch (e) {
11810
+ setError(e instanceof Error ? e.message : "Could not remove it.");
11811
+ }
11812
+ };
11813
+ const correct = async (id) => {
11814
+ if (!fixText.trim()) return;
11815
+ setFixBusy(true);
11816
+ setError(null);
11817
+ try {
11818
+ const data = await call(`/drafts/${encodeURIComponent(id)}/chat`, {
11819
+ method: "POST",
11820
+ body: { message: fixText }
11821
+ });
11822
+ const next = readDraft(data.draft);
11823
+ if (next) setLoaded((l) => l ? { ...l, drafts: l.drafts.map((d) => d.id === id ? { ...d, ...next } : d) } : l);
11824
+ setFixing(null);
11825
+ setFixText("");
11826
+ } catch (e) {
11827
+ setError(e instanceof Error ? e.message : "Could not rewrite it.");
11828
+ } finally {
11829
+ setFixBusy(false);
11830
+ }
11831
+ };
11832
+ const file = async () => {
11833
+ var _a2, _b2, _c, _d, _e;
11834
+ setBusy("file");
11835
+ setError(null);
11836
+ try {
11837
+ const data = await call("/create", { method: "POST", body: { draftIds: chosen.map((d) => d.id) } });
11838
+ const done = [...(_a2 = data.created) != null ? _a2 : [], ...(_b2 = data.already) != null ? _b2 : []];
11839
+ setFiled(done);
11840
+ if (((_c = data.created) != null ? _c : []).length > 0) onFiled == null ? void 0 : onFiled((_d = data.created) != null ? _d : []);
11841
+ if ((_e = data.failed) == null ? void 0 : _e.length) setError(`${data.failed.length} could not be filed: ${data.failed[0].error}`);
11842
+ const doneIds = new Set(done.map((d) => d.id));
11843
+ setLoaded((l) => l ? { ...l, drafts: l.drafts.filter((d) => !doneIds.has(d.id)) } : l);
11844
+ } catch (e) {
11845
+ setError(e instanceof Error ? e.message : "Could not file the issues.");
11846
+ } finally {
11847
+ setBusy(null);
11848
+ }
11849
+ };
11850
+ const button = (primary, disabled) => ({
11851
+ padding: "8px 14px",
11852
+ borderRadius: 8,
11853
+ border: primary ? 0 : `1px solid ${c.border}`,
11854
+ background: primary ? accent.accent : "transparent",
11855
+ color: primary ? accent.accentText : c.text,
11856
+ fontSize: 13,
11857
+ fontWeight: 500,
11858
+ cursor: disabled ? "not-allowed" : "pointer",
11859
+ opacity: disabled ? 0.55 : 1
11860
+ });
11861
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
11862
+ "div",
11863
+ {
11864
+ role: "dialog",
11865
+ "aria-modal": "true",
11866
+ "aria-label": "Create issues from this call",
11867
+ onClick: (e) => e.target === e.currentTarget && onClose(),
11868
+ style: { position: "fixed", inset: 0, zIndex: 2147483e3, background: "rgba(0,0,0,0.45)", display: "flex", justifyContent: "flex-end" },
11869
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
11870
+ "div",
11871
+ {
11872
+ style: {
11873
+ width: "min(560px, 100vw)",
11874
+ height: "100%",
11875
+ background: c.bg,
11876
+ color: c.text,
11877
+ borderLeft: `1px solid ${c.border}`,
11878
+ display: "flex",
11879
+ flexDirection: "column",
11880
+ fontFamily: "inherit",
11881
+ boxSizing: "border-box"
11882
+ },
11883
+ children: [
11884
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { padding: "16px 18px", borderBottom: `1px solid ${c.border}`, display: "flex", gap: 12, alignItems: "flex-start" }, children: [
11885
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { flex: 1, minWidth: 0 }, children: [
11886
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { fontSize: 15, fontWeight: 600 }, children: "Create issues from this call" }),
11887
+ (loaded == null ? void 0 : loaded.call) && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { fontSize: 12, color: c.muted, marginTop: 4, overflowWrap: "anywhere" }, children: [
11888
+ loaded.call.title ? `${loaded.call.title} \xB7 ` : "",
11889
+ loaded.call.at ? new Date(loaded.call.at).toLocaleString() : "",
11890
+ formatDuration2(loaded.call.durationSec) ? ` \xB7 ${formatDuration2(loaded.call.durationSec)}` : "",
11891
+ " \xB7 ",
11892
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("a", { href: loaded.call.pageUrl, target: "_blank", rel: "noreferrer", style: { color: accent.accent }, children: "Open in Glitchgrab \u2197" })
11893
+ ] })
11894
+ ] }),
11895
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: onClose, "aria-label": "Close", style: { ...button(false, false), padding: "4px 10px" }, children: "\u2715" })
11896
+ ] }),
11897
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { flex: 1, overflowY: "auto", padding: 18, display: "flex", flexDirection: "column", gap: 12 }, children: [
11898
+ error && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { role: "alert", style: { padding: "10px 12px", borderRadius: 8, border: "1px solid #ef4444", color: "#ef4444", fontSize: 13 }, children: error }),
11899
+ (busy === "load" || busy === "read") && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { color: c.muted, fontSize: 13 }, children: busy === "read" ? "Reading the call\u2026 this takes about 20\u201340 seconds." : "Opening the call\u2026" }),
11900
+ filed.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { padding: 12, borderRadius: 8, background: c.pane, fontSize: 13 }, children: [
11901
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { fontWeight: 600, marginBottom: 6 }, children: [
11902
+ "\u2713 Filed ",
11903
+ filed.length === 1 ? "1 issue" : `${filed.length} issues`
11904
+ ] }),
11905
+ filed.map((f) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { overflowWrap: "anywhere" }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("a", { href: f.url, target: "_blank", rel: "noreferrer", style: { color: accent.accent }, children: [
11906
+ "#",
11907
+ f.number,
11908
+ " ",
11909
+ f.title,
11910
+ " \u2197"
11911
+ ] }) }, f.id)),
11912
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { color: c.muted, marginTop: 6 }, children: "Each carries the call id, a link to the call and the lines it came from." })
11913
+ ] }),
11914
+ !busy && loaded && !loaded.canExtract && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { color: c.muted, fontSize: 13 }, children: "This call has no transcript yet. It is ready a few minutes after the call ends." }),
11915
+ !busy && loaded && loaded.canExtract && active.length === 0 && filed.length === 0 && !error && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { color: c.muted, fontSize: 13 }, children: "Nothing in this call needs an issue." }),
11916
+ active.map((d, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { border: `1px solid ${c.border}`, borderRadius: 10, padding: 12, background: c.pane }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { display: "flex", gap: 10, alignItems: "flex-start" }, children: [
11917
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
11918
+ "input",
11919
+ {
11920
+ type: "checkbox",
11921
+ "aria-label": `Select ${d.title}`,
11922
+ checked: picked.has(d.id),
11923
+ onChange: () => setPicked((p) => {
11924
+ const next = new Set(p);
11925
+ if (next.has(d.id)) next.delete(d.id);
11926
+ else next.add(d.id);
11927
+ return next;
11928
+ }),
11929
+ style: { marginTop: 3 }
11930
+ }
11931
+ ),
11932
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { flex: 1, minWidth: 0 }, children: [
11933
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { fontSize: 14, fontWeight: 600, overflowWrap: "anywhere" }, children: [
11934
+ i + 1,
11935
+ ". ",
11936
+ d.title
11937
+ ] }),
11938
+ d.labels.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { fontSize: 11, color: c.muted, marginTop: 2 }, children: d.labels.join(" \xB7 ") }),
11939
+ d.quotes.map((q, qi) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { fontSize: 12, color: c.muted, marginTop: 6, borderLeft: `2px solid ${c.border}`, paddingLeft: 8, overflowWrap: "anywhere" }, children: [
11940
+ q.speaker ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("b", { children: [
11941
+ q.speaker,
11942
+ ": "
11943
+ ] }) : null,
11944
+ q.text
11945
+ ] }, qi)),
11946
+ fixing === d.id ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { display: "flex", gap: 6, marginTop: 8 }, children: [
11947
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
11948
+ "input",
11949
+ {
11950
+ value: fixText,
11951
+ onChange: (e) => setFixText(e.target.value),
11952
+ onKeyDown: (e) => e.key === "Enter" && !fixBusy && void correct(d.id),
11953
+ placeholder: "attendance here means WhatsApp check-in, not a biometric device",
11954
+ "aria-label": "What should change in this draft",
11955
+ style: { flex: 1, padding: "7px 9px", borderRadius: 8, border: `1px solid ${c.border}`, background: c.bg, color: c.text, fontSize: 12 }
11956
+ }
11957
+ ),
11958
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", disabled: fixBusy || !fixText.trim(), onClick: () => void correct(d.id), style: button(true, fixBusy || !fixText.trim()), children: fixBusy ? "Rewriting\u2026" : "Send" })
11959
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { display: "flex", gap: 12, marginTop: 8, fontSize: 12 }, children: [
11960
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => {
11961
+ setFixing(d.id);
11962
+ setFixText("");
11963
+ }, style: { background: "none", border: 0, padding: 0, color: accent.accent, cursor: "pointer" }, children: "Not what we meant" }),
11964
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => void discard(d.id), style: { background: "none", border: 0, padding: 0, color: c.muted, cursor: "pointer" }, children: "Remove" })
11965
+ ] })
11966
+ ] })
11967
+ ] }) }, d.id))
11968
+ ] }),
11969
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { padding: "12px 18px", borderTop: `1px solid ${c.border}`, display: "flex", gap: 10, justifyContent: "space-between", alignItems: "center" }, children: [
11970
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", disabled: busy !== null || !(loaded == null ? void 0 : loaded.canExtract), onClick: () => void read(), style: button(false, busy !== null || !(loaded == null ? void 0 : loaded.canExtract)), children: "Read the call again" }),
11971
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", disabled: busy !== null || chosen.length === 0, onClick: () => void file(), style: button(true, busy !== null || chosen.length === 0), children: busy === "file" ? "Creating\u2026" : chosen.length === 1 ? "Create 1 issue" : `Create ${chosen.length} issues` })
11972
+ ] })
11973
+ ]
11974
+ }
11975
+ )
11976
+ }
11977
+ );
11978
+ }
11979
+
11980
+ // src/use-reports.ts
11981
+ var import_react9 = require("react");
11499
11982
  var BASE_URL = "https://glitchgrab.dev";
11500
11983
  function useGlitchgrabReports({
11501
11984
  token,
11502
11985
  userId,
11503
11986
  limit = 100
11504
11987
  }) {
11505
- const [reports, setReports] = (0, import_react8.useState)([]);
11506
- const [isLoading, setIsLoading] = (0, import_react8.useState)(true);
11507
- const [isFetching, setIsFetching] = (0, import_react8.useState)(false);
11508
- const [error, setError] = (0, import_react8.useState)(null);
11509
- const fetchReports = (0, import_react8.useCallback)(async () => {
11988
+ const [reports, setReports] = (0, import_react9.useState)([]);
11989
+ const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
11990
+ const [isFetching, setIsFetching] = (0, import_react9.useState)(false);
11991
+ const [error, setError] = (0, import_react9.useState)(null);
11992
+ const fetchReports = (0, import_react9.useCallback)(async () => {
11510
11993
  var _a, _b;
11511
11994
  if (!token || !userId) {
11512
11995
  setIsLoading(false);
@@ -11532,7 +12015,7 @@ function useGlitchgrabReports({
11532
12015
  setIsFetching(false);
11533
12016
  }
11534
12017
  }, [token, userId, limit]);
11535
- (0, import_react8.useEffect)(() => {
12018
+ (0, import_react9.useEffect)(() => {
11536
12019
  fetchReports();
11537
12020
  }, [fetchReports]);
11538
12021
  return { reports, isLoading, isFetching, error, refetch: fetchReports };
@@ -11569,9 +12052,9 @@ function useGlitchgrabActions({
11569
12052
  onSuccess,
11570
12053
  onError
11571
12054
  }) {
11572
- const [isPending, setIsPending] = (0, import_react8.useState)(false);
11573
- const [error, setError] = (0, import_react8.useState)(null);
11574
- const run = (0, import_react8.useCallback)(
12055
+ const [isPending, setIsPending] = (0, import_react9.useState)(false);
12056
+ const [error, setError] = (0, import_react9.useState)(null);
12057
+ const run = (0, import_react9.useCallback)(
11575
12058
  async (reportId, body) => {
11576
12059
  setIsPending(true);
11577
12060
  setError(null);
@@ -11635,12 +12118,12 @@ function useGlitchgrabReportThread({
11635
12118
  reporterEmail
11636
12119
  }) {
11637
12120
  var _a;
11638
- const [report, setReport] = (0, import_react8.useState)(null);
11639
- const [isLoading, setIsLoading] = (0, import_react8.useState)(!!reportId);
11640
- const [isFetching, setIsFetching] = (0, import_react8.useState)(false);
11641
- const [isPosting, setIsPosting] = (0, import_react8.useState)(false);
11642
- const [error, setError] = (0, import_react8.useState)(null);
11643
- const refetch = (0, import_react8.useCallback)(async () => {
12121
+ const [report, setReport] = (0, import_react9.useState)(null);
12122
+ const [isLoading, setIsLoading] = (0, import_react9.useState)(!!reportId);
12123
+ const [isFetching, setIsFetching] = (0, import_react9.useState)(false);
12124
+ const [isPosting, setIsPosting] = (0, import_react9.useState)(false);
12125
+ const [error, setError] = (0, import_react9.useState)(null);
12126
+ const refetch = (0, import_react9.useCallback)(async () => {
11644
12127
  if (!token || !reportId) {
11645
12128
  setReport(null);
11646
12129
  setIsLoading(false);
@@ -11657,10 +12140,10 @@ function useGlitchgrabReportThread({
11657
12140
  setIsFetching(false);
11658
12141
  }
11659
12142
  }, [token, reportId]);
11660
- (0, import_react8.useEffect)(() => {
12143
+ (0, import_react9.useEffect)(() => {
11661
12144
  refetch();
11662
12145
  }, [refetch]);
11663
- const addComment = (0, import_react8.useCallback)(
12146
+ const addComment = (0, import_react9.useCallback)(
11664
12147
  async (message) => {
11665
12148
  if (!token || !reportId || !message.trim()) return false;
11666
12149
  setIsPosting(true);
@@ -11682,8 +12165,8 @@ function useGlitchgrabReportThread({
11682
12165
  }
11683
12166
 
11684
12167
  // src/use-feedback.ts
11685
- var import_react9 = require("react");
11686
- var DEFAULT_BASE_URL3 = "https://glitchgrab.dev";
12168
+ var import_react10 = require("react");
12169
+ var DEFAULT_BASE_URL4 = "https://glitchgrab.dev";
11687
12170
  function buildUrl({
11688
12171
  approvedOnly,
11689
12172
  userId,
@@ -11695,7 +12178,7 @@ function buildUrl({
11695
12178
  if (approvedOnly) params.set("approved", "true");
11696
12179
  if (userId) params.set("reporterPrimaryKey", userId);
11697
12180
  if (minRating) params.set("minRating", String(minRating));
11698
- return `${baseUrl != null ? baseUrl : DEFAULT_BASE_URL3}/api/v1/sdk/feedback?${params.toString()}`;
12181
+ return `${baseUrl != null ? baseUrl : DEFAULT_BASE_URL4}/api/v1/sdk/feedback?${params.toString()}`;
11699
12182
  }
11700
12183
  async function fetchGlitchgrabFeedback(query) {
11701
12184
  var _a, _b;
@@ -11708,11 +12191,11 @@ async function fetchGlitchgrabFeedback(query) {
11708
12191
  }
11709
12192
  function useGlitchgrabFeedback(query) {
11710
12193
  const { token, approvedOnly, userId, minRating, limit, baseUrl } = query;
11711
- const [feedback, setFeedback] = (0, import_react9.useState)([]);
11712
- const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
11713
- const [isFetching, setIsFetching] = (0, import_react9.useState)(false);
11714
- const [error, setError] = (0, import_react9.useState)(null);
11715
- const load = (0, import_react9.useCallback)(async () => {
12194
+ const [feedback, setFeedback] = (0, import_react10.useState)([]);
12195
+ const [isLoading, setIsLoading] = (0, import_react10.useState)(true);
12196
+ const [isFetching, setIsFetching] = (0, import_react10.useState)(false);
12197
+ const [error, setError] = (0, import_react10.useState)(null);
12198
+ const load = (0, import_react10.useCallback)(async () => {
11716
12199
  if (!token) {
11717
12200
  setIsLoading(false);
11718
12201
  return;
@@ -11736,7 +12219,7 @@ function useGlitchgrabFeedback(query) {
11736
12219
  setIsFetching(false);
11737
12220
  }
11738
12221
  }, [token, approvedOnly, userId, minRating, limit, baseUrl]);
11739
- (0, import_react9.useEffect)(() => {
12222
+ (0, import_react10.useEffect)(() => {
11740
12223
  load();
11741
12224
  }, [load]);
11742
12225
  return { feedback, isLoading, isFetching, error, refetch: load };
@@ -11748,6 +12231,7 @@ function useGlitchgrabFeedback(query) {
11748
12231
  FeedbackButton,
11749
12232
  GLITCHGRAB_SHORTCUT,
11750
12233
  GLITCHGRAB_SHORTCUT_MAC,
12234
+ GlitchgrabCallIssue,
11751
12235
  GlitchgrabErrorBoundary,
11752
12236
  GlitchgrabProvider,
11753
12237
  ReportButton,