glitchgrab 1.62.4 → 1.63.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/README.md CHANGED
@@ -322,13 +322,17 @@ const leads = await listLeads({ source: "demo", since: "2026-09-01" }); // GLITC
322
322
  Glitchgrab keeps, per customer, the recorded calls, a running note history and the booked next call — and WhatsApps whoever booked it 5 minutes before it is due. After each call a note of what was asked and promised appears by itself, and the next call is booked from what was said, with a reason. Read and write it from your server with the `ggc_` key:
323
323
 
324
324
  ```ts
325
- import { listFollowUps, setFollowUpBooking, dialFollowUp, addFollowUpNote } from "glitchgrab/server";
325
+ import { listFollowUps, setFollowUpBooking, dialFollowUp, addFollowUpNote, editFollowUpNote } from "glitchgrab/server";
326
326
 
327
327
  // One request for a whole list page (≤500 ids): nextCallAt, due, lastNote, noteCount, lastCall
328
328
  const rows = await listFollowUps(owners.map((o) => o.id));
329
329
 
330
330
  // The first write for a new id needs its phone
331
331
  await addFollowUpNote(owner.id, { body: "Wants WhatsApp receipts", author: "Super Admin", phone: owner.phone });
332
+ // Correct your own note (or the one written from the call)
333
+ await editFollowUpNote(owner.id, noteId, { body: "Wants WhatsApp receipts monthly", editor: "Super Admin" });
334
+ // Moving off your own store? Copy old notes with their real dates (past only, no webhook)
335
+ await addFollowUpNote(owner.id, { body: old.body, author: old.by, createdAt: old.at, editedAt: old.editedAt, editedBy: old.editedBy });
332
336
  await setFollowUpBooking(owner.id, { nextCallAt: new Date("2026-10-27T05:30:00Z"), operator: { email: "admin@you.in" } });
333
337
 
334
338
  // Rings the operator first, then the customer, from your project's Glitchgrab number — recorded
package/dist/index.js CHANGED
@@ -924,7 +924,7 @@ async function enhanceTextOrThrow(text, token, baseUrl, screenshot, context, ide
924
924
  }
925
925
  throw new Error(unavailable);
926
926
  }
927
- async function findSimilarIssues(description, token, baseUrl, identity, files) {
927
+ async function findSimilarIssues(description, token, baseUrl, identity, files, conversationId) {
928
928
  var _a;
929
929
  try {
930
930
  const url = `${baseUrl != null ? baseUrl : DEFAULT_BASE_URL}/api/v1/reports/similar`;
@@ -937,6 +937,7 @@ async function findSimilarIssues(description, token, baseUrl, identity, files) {
937
937
  body: JSON.stringify({
938
938
  text: description,
939
939
  ...(files == null ? void 0 : files.length) ? { files } : {},
940
+ ...conversationId ? { conversationId } : {},
940
941
  ...signedFields(identity)
941
942
  })
942
943
  });
@@ -2711,16 +2712,6 @@ var STARTERS = [
2711
2712
  "I wish it could\u2026"
2712
2713
  ];
2713
2714
  var CONFIRM_OPTION = "Yes, that's it";
2714
- function isCheckBackQuestion(text) {
2715
- const t = text.trim();
2716
- return /^so,? you['’]?re saying\b/i.test(t) || /\b(is that right|is that correct|did i get (that|it) right|have i got (that|it) right)\s*\??\s*$/i.test(t);
2717
- }
2718
- function isAffirmativeReply(text) {
2719
- return /^(y|ya|yah|yes|yess|yeah|yep|yup|ok|okay|sure|correct|right|exactly|confirm(ed)?|that['’]?s (it|right|correct)|yes,? that['’]?s (it|right)|haan|han|ha|ho|hmm yes|👍)[\s.!👍]*$/i.test(
2720
- text.trim()
2721
- );
2722
- }
2723
- var AUTO_FILE_SECONDS = 3;
2724
2715
  var NARROW_QUERY = "(max-width: 640px)";
2725
2716
  function useIsNarrow() {
2726
2717
  const [narrow, setNarrow] = (0, import_react3.useState)(false);
@@ -2888,7 +2879,6 @@ function AssistSheet({
2888
2879
  const [phase, setPhase] = (0, import_react3.useState)(
2889
2880
  () => !typePicked ? "type" : currentTile === "RATING" ? "rating" : needsSeverity(currentTile) ? "severity" : "chat"
2890
2881
  );
2891
- const [autoFileLeft, setAutoFileLeft] = (0, import_react3.useState)(null);
2892
2882
  const scrollRef = (0, import_react3.useRef)(null);
2893
2883
  const draftRef = (0, import_react3.useRef)(null);
2894
2884
  const composerRef = (0, import_react3.useRef)(null);
@@ -2961,30 +2951,11 @@ function AssistSheet({
2961
2951
  el.style.height = "auto";
2962
2952
  el.style.height = `${el.scrollHeight + 2}px`;
2963
2953
  }, [input]);
2964
- (0, import_react3.useEffect)(() => {
2965
- if (autoFileLeft === null) return;
2966
- if (isSubmitting || submitted || phase !== "draft") {
2967
- setAutoFileLeft(null);
2968
- return;
2969
- }
2970
- if (autoFileLeft <= 0) {
2971
- sendDraft(true);
2972
- return;
2973
- }
2974
- const id = setTimeout(() => setAutoFileLeft((n) => n === null ? null : n - 1), 1e3);
2975
- return () => clearTimeout(id);
2976
- }, [autoFileLeft, isSubmitting, submitted, phase]);
2977
2954
  function markUp(index, shot) {
2978
2955
  if (!onAnnotateImage) return;
2979
- stopAutoFile("marked up an image");
2980
2956
  logEvent("image_markup", pageShot && shot === pageShot ? "page capture" : "attached");
2981
2957
  onAnnotateImage(index);
2982
2958
  }
2983
- function stopAutoFile(reason) {
2984
- if (autoFileLeft === null) return;
2985
- setAutoFileLeft(null);
2986
- logEvent("auto_file_stopped", reason);
2987
- }
2988
2959
  function degradeKeepingEvents(events, message, retryable) {
2989
2960
  if (events) eventsRef.current = [...events, ...eventsRef.current];
2990
2961
  flushEvents();
@@ -3004,11 +2975,10 @@ function AssistSheet({
3004
2975
  }
3005
2976
  onDescriptionChange(typed);
3006
2977
  }
3007
- async function runTurn(history2, autoFile = false) {
2978
+ async function runTurn(history2) {
3008
2979
  var _a2, _b, _c;
3009
2980
  const turnChat = chatIdRef.current;
3010
2981
  setBusy(true);
3011
- setAutoFileLeft(null);
3012
2982
  let result;
3013
2983
  const events = takeEvents();
3014
2984
  try {
@@ -3089,12 +3059,10 @@ function AssistSheet({
3089
3059
  return;
3090
3060
  }
3091
3061
  if (result.report) {
3092
- let tile = currentTile;
3093
3062
  if (!typePicked || inferredTypeRef.current) {
3094
3063
  const fallback = defaultTile();
3095
3064
  const inferred = result.reportType && tiles.includes(result.reportType) ? result.reportType : fallback;
3096
3065
  if (inferred) {
3097
- tile = inferred;
3098
3066
  inferredTypeRef.current = true;
3099
3067
  onPickType(inferred);
3100
3068
  }
@@ -3106,9 +3074,6 @@ function AssistSheet({
3106
3074
  setMessages([...history2, { role: "assistant", content: result.report, kind: "report" }]);
3107
3075
  setOptions([]);
3108
3076
  setPhase("draft");
3109
- if (autoFile && !attach && !(showSeverity && tile === "BUG" && !severity)) {
3110
- setAutoFileLeft(AUTO_FILE_SECONDS);
3111
- }
3112
3077
  return;
3113
3078
  }
3114
3079
  if (result.question) {
@@ -3151,13 +3116,7 @@ function AssistSheet({
3151
3116
  seedFromDescription();
3152
3117
  }
3153
3118
  }
3154
- function sendTyped(text) {
3155
- var _a2;
3156
- const lastAssistant = [...messages].reverse().find((m) => m.role === "assistant");
3157
- const checkingBack = options.includes(CONFIRM_OPTION) || (lastAssistant == null ? void 0 : lastAssistant.kind) !== "report" && isCheckBackQuestion((_a2 = lastAssistant == null ? void 0 : lastAssistant.content) != null ? _a2 : "");
3158
- send(text, checkingBack && isAffirmativeReply(text));
3159
- }
3160
- function send(text, autoFile = false) {
3119
+ function send(text) {
3161
3120
  const value = text.trim();
3162
3121
  if (!value || busy) return;
3163
3122
  setOptions([]);
@@ -3173,7 +3132,7 @@ function AssistSheet({
3173
3132
  const history2 = [...base, { role: "user", content: value }];
3174
3133
  setMessages(history2);
3175
3134
  setInput("");
3176
- void runTurn(history2, autoFile);
3135
+ void runTurn(history2);
3177
3136
  }
3178
3137
  function withCurrentDraft(history2) {
3179
3138
  const current = description.trim();
@@ -3186,10 +3145,9 @@ function AssistSheet({
3186
3145
  }
3187
3146
  return next;
3188
3147
  }
3189
- function sendDraft(auto = false) {
3190
- setAutoFileLeft(null);
3148
+ function sendDraft() {
3191
3149
  const edited = aiDraftRef.current !== null && description.trim() !== aiDraftRef.current.trim();
3192
- logEvent("draft_sent", auto ? "auto-filed" : edited ? "edited" : "as drafted");
3150
+ logEvent("draft_sent", edited ? "edited" : "as drafted");
3193
3151
  flushEvents();
3194
3152
  onSend();
3195
3153
  }
@@ -3232,7 +3190,6 @@ function AssistSheet({
3232
3190
  setDuplicate(null);
3233
3191
  onDuplicateChange == null ? void 0 : onDuplicateChange(null);
3234
3192
  setGlitchgrabOffer(false);
3235
- setAutoFileLeft(null);
3236
3193
  setInput("");
3237
3194
  if (chat.tile !== currentTile && tiles.includes(chat.tile)) {
3238
3195
  onPickType(chat.tile);
@@ -3265,7 +3222,6 @@ function AssistSheet({
3265
3222
  setDuplicate(null);
3266
3223
  onDuplicateChange == null ? void 0 : onDuplicateChange(null);
3267
3224
  setGlitchgrabOffer(false);
3268
- setAutoFileLeft(null);
3269
3225
  setInput("");
3270
3226
  onDescriptionChange("");
3271
3227
  onIssueTitleChange("");
@@ -3463,7 +3419,6 @@ function AssistSheet({
3463
3419
  @keyframes gg-sheet-in{from{transform:translateX(24px);opacity:0}to{transform:translateX(0);opacity:1}}
3464
3420
  @keyframes gg-sheet-up{from{transform:translateY(24px);opacity:0}to{transform:translateY(0);opacity:1}}
3465
3421
  @keyframes gg-sheet-fade{from{opacity:0}to{opacity:1}}
3466
- @keyframes gg-autofile{from{transform:scaleX(0)}to{transform:scaleX(1)}}
3467
3422
  @keyframes gg-spin{to{transform:rotate(360deg)}}
3468
3423
  @keyframes gg-dot{0%,80%,100%{transform:translateY(0);opacity:.4}40%{transform:translateY(-3px);opacity:1}}
3469
3424
  [data-gg-sheet-send]:focus-visible,[data-gg-chip]:focus-visible,[data-gg-assist-remove]:focus-visible,[data-gg-assist-annotate]:focus-visible,[data-gg-stop-auto-file]:focus-visible{outline:2px solid currentColor;outline-offset:2px}
@@ -4000,11 +3955,7 @@ function AssistSheet({
4000
3955
  color: t.text,
4001
3956
  border: live ? "none" : `1px solid ${t.accent}66`
4002
3957
  },
4003
- children: live ? (
4004
- // #402: "have a read" beside a countdown reads as a
4005
- // contradiction. Say what is about to happen instead.
4006
- autoFileLeft !== null ? "Here's your report \u2014 I'll file it unless you want to change something." : "Here's your report \u2014 have a read."
4007
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
3958
+ children: live ? "Here's your report \u2014 have a read. Nothing is sent until you send it." : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
4008
3959
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4009
3960
  "span",
4010
3961
  {
@@ -4175,7 +4126,7 @@ function AssistSheet({
4175
4126
  "data-gg-option": "",
4176
4127
  onClick: () => {
4177
4128
  logEvent("option_tap", option);
4178
- send(option, option === CONFIRM_OPTION);
4129
+ send(option);
4179
4130
  },
4180
4131
  style: {
4181
4132
  border: primary ? "1px solid transparent" : `1px solid ${t.inputBorder}`,
@@ -4296,7 +4247,6 @@ function AssistSheet({
4296
4247
  if (e.key === "Enter") e.preventDefault();
4297
4248
  },
4298
4249
  onChange: (e) => {
4299
- stopAutoFile("edited the title");
4300
4250
  onIssueTitleChange(e.target.value.replace(/[\r\n]+/g, " "));
4301
4251
  },
4302
4252
  style: {
@@ -4322,7 +4272,6 @@ function AssistSheet({
4322
4272
  ref: draftRef,
4323
4273
  value: description,
4324
4274
  onChange: (e) => {
4325
- stopAutoFile("edited the draft");
4326
4275
  onDescriptionChange(e.target.value);
4327
4276
  },
4328
4277
  rows: 6,
@@ -4343,7 +4292,7 @@ function AssistSheet({
4343
4292
  }
4344
4293
  }
4345
4294
  ),
4346
- severityAsked && autoFileLeft === null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
4295
+ severityAsked && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
4347
4296
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4348
4297
  "span",
4349
4298
  {
@@ -4631,7 +4580,6 @@ function AssistSheet({
4631
4580
  "aria-label": `Remove image ${i + 1}`,
4632
4581
  title: "Remove this image",
4633
4582
  onClick: () => {
4634
- stopAutoFile("changed attachments");
4635
4583
  logEvent(
4636
4584
  "image_removed",
4637
4585
  pageShot && shot === pageShot ? "page capture" : "attached"
@@ -4760,7 +4708,6 @@ function AssistSheet({
4760
4708
  "aria-label": `Remove file ${file.name}`,
4761
4709
  title: "Remove this file",
4762
4710
  onClick: () => {
4763
- stopAutoFile("changed attachments");
4764
4711
  logEvent("file_removed", read ? "read" : "not read");
4765
4712
  onRemoveFile(i);
4766
4713
  },
@@ -4843,7 +4790,6 @@ function AssistSheet({
4843
4790
  var _a2;
4844
4791
  const picked = Array.from((_a2 = e.target.files) != null ? _a2 : []);
4845
4792
  if (picked.length) {
4846
- stopAutoFile("changed attachments");
4847
4793
  const images = picked.filter((f) => f.type.startsWith("image/")).length;
4848
4794
  if (images) logEvent("image_added", String(images));
4849
4795
  if (picked.length > images) {
@@ -4875,13 +4821,12 @@ function AssistSheet({
4875
4821
  ref: composerRef,
4876
4822
  value: input,
4877
4823
  onChange: (e) => {
4878
- stopAutoFile("typing a change");
4879
4824
  setInput(e.target.value);
4880
4825
  },
4881
4826
  onKeyDown: (e) => {
4882
4827
  if (e.key === "Enter" && !e.shiftKey) {
4883
4828
  e.preventDefault();
4884
- sendTyped(input);
4829
+ send(input);
4885
4830
  }
4886
4831
  },
4887
4832
  placeholder: phase === "draft" ? "Anything to change? Tell me here\u2026" : phase === "type" ? "What went wrong, or what would you like? Type it here\u2026" : "Type your answer\u2026",
@@ -4911,7 +4856,7 @@ function AssistSheet({
4911
4856
  {
4912
4857
  type: "button",
4913
4858
  "data-gg-sheet-send": "",
4914
- onClick: () => sendTyped(input),
4859
+ onClick: () => send(input),
4915
4860
  disabled: busy || !input.trim(),
4916
4861
  "aria-label": "Send message",
4917
4862
  "data-gg-send-message": "",
@@ -4951,90 +4896,7 @@ function AssistSheet({
4951
4896
  children: validationError
4952
4897
  }
4953
4898
  ),
4954
- similarSlot ? similarSlot : autoFileLeft !== null ? (
4955
- // #402: "Yes, that's it" was the confirmation. The draft
4956
- // files itself unless they stop it — the bar shows how
4957
- // long is left, the button sends now, the × on its right
4958
- // stops it (#406). Stopping keeps the draft: Send Report
4959
- // comes back, and closing the sheet drops it.
4960
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px", marginTop: "8px" }, children: [
4961
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4962
- "button",
4963
- {
4964
- type: "button",
4965
- "data-gg-sheet-send": "",
4966
- "data-gg-auto-file": "",
4967
- onClick: () => sendDraft(),
4968
- style: {
4969
- flex: 1,
4970
- minWidth: 0,
4971
- position: "relative",
4972
- overflow: "hidden",
4973
- padding: "12px",
4974
- borderRadius: "10px",
4975
- border: "none",
4976
- backgroundColor: t.accent,
4977
- color: t.accentText,
4978
- fontSize: "14px",
4979
- fontWeight: 700,
4980
- fontFamily: "inherit",
4981
- cursor: "pointer"
4982
- },
4983
- children: [
4984
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4985
- "span",
4986
- {
4987
- "aria-hidden": "true",
4988
- style: {
4989
- position: "absolute",
4990
- inset: 0,
4991
- backgroundColor: "rgba(255,255,255,0.22)",
4992
- transformOrigin: "left",
4993
- animation: `gg-autofile ${AUTO_FILE_SECONDS}s linear forwards`
4994
- }
4995
- }
4996
- ),
4997
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { position: "relative" }, children: [
4998
- "Filing in ",
4999
- autoFileLeft,
5000
- "s\u2026"
5001
- ] })
5002
- ]
5003
- }
5004
- ),
5005
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
5006
- "button",
5007
- {
5008
- type: "button",
5009
- "data-gg-stop-auto-file": "",
5010
- onClick: () => stopAutoFile("pressed stop"),
5011
- "aria-label": "Stop \u2014 don't send",
5012
- title: "Stop \u2014 don't send",
5013
- style: {
5014
- flexShrink: 0,
5015
- width: "44px",
5016
- borderRadius: "10px",
5017
- border: `1px solid ${t.inputBorder}`,
5018
- background: "transparent",
5019
- color: t.text,
5020
- display: "inline-flex",
5021
- alignItems: "center",
5022
- justifyContent: "center",
5023
- cursor: "pointer"
5024
- },
5025
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
5026
- "path",
5027
- {
5028
- d: "M6 6l12 12M18 6L6 18",
5029
- stroke: "currentColor",
5030
- strokeWidth: "2.25",
5031
- strokeLinecap: "round"
5032
- }
5033
- ) })
5034
- }
5035
- )
5036
- ] })
5037
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4899
+ similarSlot ? similarSlot : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
5038
4900
  "button",
5039
4901
  {
5040
4902
  type: "button",
@@ -6754,8 +6616,10 @@ function ReportDialog({
6754
6616
  setIsSubmitting(true);
6755
6617
  setCheckingSimilar(true);
6756
6618
  const matches = await Promise.race([
6757
- // A PDF still being read is left out rather than waited for.
6758
- (similarFiles.length ? findSimilarIssues2(description.trim(), similarFiles) : findSimilarIssues2(description.trim())).catch(() => null),
6619
+ // A PDF still being read is left out rather than waited for. A draft
6620
+ // from the sheet names its chat, so an issue the reporter already
6621
+ // turned down there is not offered again (#697).
6622
+ (aiConversationId ? findSimilarIssues2(description.trim(), similarFiles.length ? similarFiles : void 0, aiConversationId) : similarFiles.length ? findSimilarIssues2(description.trim(), similarFiles) : findSimilarIssues2(description.trim())).catch(() => null),
6759
6623
  new Promise((resolve) => setTimeout(() => resolve(null), SIMILAR_WAIT_MS))
6760
6624
  ]);
6761
6625
  setCheckingSimilar(false);
@@ -11065,7 +10929,7 @@ function GlitchgrabProviderInner({
11065
10929
  [token, baseUrl, session]
11066
10930
  );
11067
10931
  const findSimilar = (0, import_react6.useCallback)(
11068
- (description, files) => findSimilarIssues(description, token, baseUrl, identity, files),
10932
+ (description, files, conversationId) => findSimilarIssues(description, token, baseUrl, identity, files, conversationId),
11069
10933
  [token, baseUrl, identity]
11070
10934
  );
11071
10935
  const readFile = (0, import_react6.useCallback)(