glitchgrab 1.65.0 → 1.65.2

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
@@ -94,6 +94,7 @@ function toAssistTurnResult(ok, body) {
94
94
  // keeps the assistant button for this report.
95
95
  degraded: (_a = envelope == null ? void 0 : envelope.error) != null ? _a : ASSIST_OFFLINE_MESSAGE,
96
96
  retryable: (envelope == null ? void 0 : envelope.retryable) === true,
97
+ ...(envelope == null ? void 0 : envelope.timedOut) === true ? { timedOut: true } : {},
97
98
  ...(envelope == null ? void 0 : envelope.resendImages) === true ? { resendImages: true } : {}
98
99
  };
99
100
  }
@@ -2720,6 +2721,8 @@ function Avatar({
2720
2721
  );
2721
2722
  }
2722
2723
  var THINKING_SLOW_SECONDS = 20;
2724
+ var ASSIST_TURN_TIMEOUT_MS = 75e3;
2725
+ var ASSIST_UPLOAD_TIMEOUT_MS = 18e4;
2723
2726
  function ThinkingClock({ color }) {
2724
2727
  const [seconds, setSeconds] = useState2(0);
2725
2728
  useEffect2(() => {
@@ -2796,6 +2799,8 @@ function AssistSheet({
2796
2799
  const [messages, setMessages] = useState2([]);
2797
2800
  const [input, setInput] = useState2("");
2798
2801
  const [busy, setBusy] = useState2(false);
2802
+ const [stalled, setStalled] = useState2(null);
2803
+ const turnRef = useRef2(0);
2799
2804
  const [conversationId, setConversationId] = useState2(null);
2800
2805
  const [uploadProgress, setUploadProgress] = useState2(null);
2801
2806
  const storedImagesRef = useRef2({
@@ -2874,6 +2879,13 @@ function AssistSheet({
2874
2879
  const sentFiles = useMemo(() => pickAssistFiles(files), [files]);
2875
2880
  const readFiles = new Set(sentFiles.map((f) => f.index));
2876
2881
  function leave(type, detail, exit = onClose) {
2882
+ if (type === "write_myself" && stalled && !description.trim()) {
2883
+ const typed = stalled.filter((m) => m.role === "user").map((m) => m.content).join("\n\n");
2884
+ if (typed) {
2885
+ if (!typePicked) keepTypedForForm(stalled);
2886
+ else onDescriptionChange(typed);
2887
+ }
2888
+ }
2877
2889
  logEvent(type, detail);
2878
2890
  flushEvents();
2879
2891
  exit();
@@ -2919,9 +2931,23 @@ function AssistSheet({
2919
2931
  async function runTurn(history2) {
2920
2932
  var _a2, _b, _c;
2921
2933
  const turnChat = chatIdRef.current;
2934
+ const turn = ++turnRef.current;
2935
+ const current = () => turnRef.current === turn;
2936
+ setStalled(null);
2922
2937
  setBusy(true);
2923
2938
  let result;
2924
2939
  const events = takeEvents();
2940
+ let waited;
2941
+ let giveUp = () => {
2942
+ };
2943
+ const gaveUp = new Promise((resolve) => {
2944
+ giveUp = () => resolve("timeout");
2945
+ });
2946
+ const arm = (ms) => {
2947
+ clearTimeout(waited);
2948
+ waited = setTimeout(giveUp, ms);
2949
+ };
2950
+ arm(ASSIST_TURN_TIMEOUT_MS);
2925
2951
  try {
2926
2952
  const picked = pickAssistImages(assistImages());
2927
2953
  const held = storedImagesRef.current;
@@ -2929,6 +2955,7 @@ function AssistSheet({
2929
2955
  const call = async (known) => {
2930
2956
  const { screenshots: sent, hasData } = await toSendList(picked, known);
2931
2957
  setUploadProgress(null);
2958
+ if (hasData) arm(ASSIST_UPLOAD_TIMEOUT_MS);
2932
2959
  return assist(
2933
2960
  {
2934
2961
  // `kind` only on drafts, so an older server sees the exact shape it
@@ -2954,13 +2981,37 @@ function AssistSheet({
2954
2981
  },
2955
2982
  events
2956
2983
  },
2957
- hasData ? { onUploadProgress: setUploadProgress } : void 0
2984
+ hasData ? {
2985
+ onUploadProgress: (fraction) => {
2986
+ if (!current()) return;
2987
+ setUploadProgress(fraction);
2988
+ if (fraction >= 1) arm(ASSIST_TURN_TIMEOUT_MS);
2989
+ }
2990
+ } : void 0
2958
2991
  );
2959
2992
  };
2960
- result = await call(stored);
2993
+ const first = await Promise.race([call(stored), gaveUp]);
2994
+ if (first === "timeout") {
2995
+ if (current() && chatIdRef.current === turnChat) {
2996
+ logEvent("turn_timeout", "sheet");
2997
+ setStalled(history2);
2998
+ }
2999
+ return;
3000
+ }
3001
+ result = first;
3002
+ if (!current()) return;
2961
3003
  if (result.resendImages) {
2962
3004
  storedImagesRef.current = { conversationId: null, hashes: /* @__PURE__ */ new Set() };
2963
- result = await call(/* @__PURE__ */ new Set());
3005
+ const again = await Promise.race([call(/* @__PURE__ */ new Set()), gaveUp]);
3006
+ if (again === "timeout") {
3007
+ if (current() && chatIdRef.current === turnChat) {
3008
+ logEvent("turn_timeout", "sheet");
3009
+ setStalled(history2);
3010
+ }
3011
+ return;
3012
+ }
3013
+ result = again;
3014
+ if (!current()) return;
2964
3015
  }
2965
3016
  if (result.conversationId && result.storedImages) {
2966
3017
  storedImagesRef.current = {
@@ -2969,6 +3020,7 @@ function AssistSheet({
2969
3020
  };
2970
3021
  }
2971
3022
  } catch (e) {
3023
+ if (!current()) return;
2972
3024
  keepTypedForForm(history2);
2973
3025
  degradeKeepingEvents(
2974
3026
  events,
@@ -2976,10 +3028,19 @@ function AssistSheet({
2976
3028
  );
2977
3029
  return;
2978
3030
  } finally {
2979
- setBusy(false);
2980
- setUploadProgress(null);
3031
+ clearTimeout(waited);
3032
+ if (current()) {
3033
+ setBusy(false);
3034
+ setUploadProgress(null);
3035
+ }
3036
+ }
3037
+ if (!current() || chatIdRef.current !== turnChat) return;
3038
+ if (result.degraded && result.timedOut) {
3039
+ if (events) eventsRef.current = [...events, ...eventsRef.current];
3040
+ logEvent("turn_timeout", "server");
3041
+ setStalled(history2);
3042
+ return;
2981
3043
  }
2982
- if (chatIdRef.current !== turnChat) return;
2983
3044
  if (result.degraded) {
2984
3045
  keepTypedForForm(history2);
2985
3046
  degradeKeepingEvents(events, result.degraded, result.retryable === true);
@@ -3060,6 +3121,7 @@ function AssistSheet({
3060
3121
  function send(text) {
3061
3122
  const value = text.trim();
3062
3123
  if (!value || busy) return;
3124
+ setStalled(null);
3063
3125
  setOptions([]);
3064
3126
  setGlitchgrabOffer(false);
3065
3127
  const underDraft = phase === "draft";
@@ -3124,6 +3186,7 @@ function AssistSheet({
3124
3186
  var _a2;
3125
3187
  flushEvents();
3126
3188
  chatIdRef.current = chat.id;
3189
+ setStalled(null);
3127
3190
  setMessages(chat.messages);
3128
3191
  setConversationId(chat.conversationId);
3129
3192
  onConversationChange == null ? void 0 : onConversationChange(chat.conversationId);
@@ -3147,6 +3210,7 @@ function AssistSheet({
3147
3210
  setShowChats(false);
3148
3211
  setViewingChat(null);
3149
3212
  resumeAskRef.current = (last == null ? void 0 : last.role) === "user";
3213
+ seedPendingRef.current = false;
3150
3214
  }
3151
3215
  useEffect2(() => {
3152
3216
  if (!resumeAskRef.current) return;
@@ -3156,6 +3220,7 @@ function AssistSheet({
3156
3220
  function startNewChat() {
3157
3221
  flushEvents();
3158
3222
  chatIdRef.current = newChatId();
3223
+ setStalled(null);
3159
3224
  setMessages([]);
3160
3225
  setConversationId(null);
3161
3226
  onConversationChange == null ? void 0 : onConversationChange(null);
@@ -3179,6 +3244,79 @@ function AssistSheet({
3179
3244
  const otherChats = savedChats.filter((c) => c.id !== chatIdRef.current);
3180
3245
  const resumable = (_a = otherChats.find((c) => c.status === "open" && c.messages.length > 0)) != null ? _a : null;
3181
3246
  const empty = (phase === "chat" || phase === "type") && messages.length === 0 && !busy;
3247
+ const resumeCard = resumable ? /* @__PURE__ */ jsxs3(
3248
+ "div",
3249
+ {
3250
+ "data-gg-resume-chat": "",
3251
+ style: {
3252
+ display: "flex",
3253
+ flexDirection: "column",
3254
+ gap: "8px",
3255
+ padding: "10px 12px",
3256
+ borderRadius: "10px",
3257
+ border: `1px solid ${t.accent}55`,
3258
+ backgroundColor: t.bgSecondary,
3259
+ minWidth: 0
3260
+ },
3261
+ children: [
3262
+ /* @__PURE__ */ jsxs3("span", { style: { fontSize: "11.5px", color: t.textMuted }, children: [
3263
+ "Pick up where you left off \xB7 ",
3264
+ chatAge(resumable.updatedAt)
3265
+ ] }),
3266
+ /* @__PURE__ */ jsx3(
3267
+ "span",
3268
+ {
3269
+ style: {
3270
+ fontSize: "13px",
3271
+ lineHeight: 1.45,
3272
+ overflowWrap: "anywhere"
3273
+ },
3274
+ children: resumable.title
3275
+ }
3276
+ ),
3277
+ /* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
3278
+ /* @__PURE__ */ jsx3(
3279
+ "button",
3280
+ {
3281
+ type: "button",
3282
+ "data-gg-resume-continue": "",
3283
+ onClick: () => resumeChat(resumable),
3284
+ style: {
3285
+ border: "none",
3286
+ borderRadius: "999px",
3287
+ backgroundColor: t.accent,
3288
+ color: t.accentText,
3289
+ padding: "7px 13px",
3290
+ fontSize: "12px",
3291
+ fontWeight: 600,
3292
+ fontFamily: "inherit",
3293
+ cursor: "pointer"
3294
+ },
3295
+ children: "Continue this chat"
3296
+ }
3297
+ ),
3298
+ /* @__PURE__ */ jsx3(
3299
+ "button",
3300
+ {
3301
+ type: "button",
3302
+ onClick: () => setShowChats(true),
3303
+ style: {
3304
+ border: `1px solid ${t.inputBorder}`,
3305
+ borderRadius: "999px",
3306
+ background: "transparent",
3307
+ color: t.textMuted,
3308
+ padding: "7px 13px",
3309
+ fontSize: "12px",
3310
+ fontFamily: "inherit",
3311
+ cursor: "pointer"
3312
+ },
3313
+ children: "All chats"
3314
+ }
3315
+ )
3316
+ ] })
3317
+ ]
3318
+ }
3319
+ ) : null;
3182
3320
  function renderChatList() {
3183
3321
  return /* @__PURE__ */ jsxs3("div", { "data-gg-chat-list": "", style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
3184
3322
  /* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
@@ -3572,6 +3710,7 @@ function AssistSheet({
3572
3710
  },
3573
3711
  children: /* @__PURE__ */ jsxs3("div", { style: { display: showChats ? "none" : "contents" }, children: [
3574
3712
  phase === "severity" && /* @__PURE__ */ jsxs3("div", { style: { display: "flex", flexDirection: "column", gap: "12px" }, children: [
3713
+ resumeCard,
3575
3714
  /* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: "8px" }, children: [
3576
3715
  /* @__PURE__ */ jsx3(Avatar, { who: "assistant", theme: t }),
3577
3716
  /* @__PURE__ */ jsx3(
@@ -3745,79 +3884,7 @@ function AssistSheet({
3745
3884
  )
3746
3885
  ] }),
3747
3886
  empty && /* @__PURE__ */ jsxs3("div", { style: { display: "flex", flexDirection: "column", gap: "12px" }, children: [
3748
- resumable && /* @__PURE__ */ jsxs3(
3749
- "div",
3750
- {
3751
- "data-gg-resume-chat": "",
3752
- style: {
3753
- display: "flex",
3754
- flexDirection: "column",
3755
- gap: "8px",
3756
- padding: "10px 12px",
3757
- borderRadius: "10px",
3758
- border: `1px solid ${t.accent}55`,
3759
- backgroundColor: t.bgSecondary,
3760
- minWidth: 0
3761
- },
3762
- children: [
3763
- /* @__PURE__ */ jsxs3("span", { style: { fontSize: "11.5px", color: t.textMuted }, children: [
3764
- "Pick up where you left off \xB7 ",
3765
- chatAge(resumable.updatedAt)
3766
- ] }),
3767
- /* @__PURE__ */ jsx3(
3768
- "span",
3769
- {
3770
- style: {
3771
- fontSize: "13px",
3772
- lineHeight: 1.45,
3773
- overflowWrap: "anywhere"
3774
- },
3775
- children: resumable.title
3776
- }
3777
- ),
3778
- /* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
3779
- /* @__PURE__ */ jsx3(
3780
- "button",
3781
- {
3782
- type: "button",
3783
- "data-gg-resume-continue": "",
3784
- onClick: () => resumeChat(resumable),
3785
- style: {
3786
- border: "none",
3787
- borderRadius: "999px",
3788
- backgroundColor: t.accent,
3789
- color: t.accentText,
3790
- padding: "7px 13px",
3791
- fontSize: "12px",
3792
- fontWeight: 600,
3793
- fontFamily: "inherit",
3794
- cursor: "pointer"
3795
- },
3796
- children: "Continue this chat"
3797
- }
3798
- ),
3799
- /* @__PURE__ */ jsx3(
3800
- "button",
3801
- {
3802
- type: "button",
3803
- onClick: () => setShowChats(true),
3804
- style: {
3805
- border: `1px solid ${t.inputBorder}`,
3806
- borderRadius: "999px",
3807
- background: "transparent",
3808
- color: t.textMuted,
3809
- padding: "7px 13px",
3810
- fontSize: "12px",
3811
- fontFamily: "inherit",
3812
- cursor: "pointer"
3813
- },
3814
- children: "All chats"
3815
- }
3816
- )
3817
- ] })
3818
- ]
3819
- }
3820
- ),
3887
+ resumeCard,
3821
3888
  phase !== "type" && /* @__PURE__ */ jsxs3(Fragment2, { children: [
3822
3889
  /* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: "8px" }, children: [
3823
3890
  /* @__PURE__ */ jsx3(Avatar, { who: "assistant", theme: t }),
@@ -4142,6 +4209,74 @@ function AssistSheet({
4142
4209
  }
4143
4210
  )
4144
4211
  ] }),
4212
+ stalled && !busy && /* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: "8px", minWidth: 0 }, role: "alert", children: [
4213
+ /* @__PURE__ */ jsx3(Avatar, { who: "assistant", theme: t }),
4214
+ /* @__PURE__ */ jsxs3(
4215
+ "div",
4216
+ {
4217
+ "data-gg-turn-timeout": "",
4218
+ style: {
4219
+ display: "flex",
4220
+ flexDirection: "column",
4221
+ gap: "10px",
4222
+ minWidth: 0,
4223
+ padding: "12px",
4224
+ borderRadius: "12px 12px 12px 4px",
4225
+ backgroundColor: t.bgSecondary,
4226
+ color: t.text,
4227
+ fontSize: "13px",
4228
+ lineHeight: 1.45
4229
+ },
4230
+ children: [
4231
+ /* @__PURE__ */ jsx3("span", { children: "No answer \u2014 this is taking too long. Try again, or write it yourself; what you typed comes with you." }),
4232
+ /* @__PURE__ */ jsxs3("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: [
4233
+ /* @__PURE__ */ jsx3(
4234
+ "button",
4235
+ {
4236
+ type: "button",
4237
+ "data-gg-turn-retry": "",
4238
+ onClick: () => {
4239
+ logEvent("turn_retry");
4240
+ void runTurn(stalled);
4241
+ },
4242
+ style: {
4243
+ padding: "8px 14px",
4244
+ borderRadius: "999px",
4245
+ border: "none",
4246
+ background: t.accent,
4247
+ color: t.accentText,
4248
+ fontSize: "12px",
4249
+ fontWeight: 600,
4250
+ fontFamily: "inherit",
4251
+ cursor: "pointer"
4252
+ },
4253
+ children: "Try again"
4254
+ }
4255
+ ),
4256
+ /* @__PURE__ */ jsx3(
4257
+ "button",
4258
+ {
4259
+ type: "button",
4260
+ "data-gg-turn-write-myself": "",
4261
+ onClick: () => leave("write_myself", "timed out"),
4262
+ style: {
4263
+ padding: "8px 14px",
4264
+ borderRadius: "999px",
4265
+ border: `1px solid ${t.inputBorder}`,
4266
+ background: "transparent",
4267
+ color: t.textMuted,
4268
+ fontSize: "12px",
4269
+ fontFamily: "inherit",
4270
+ cursor: "pointer"
4271
+ },
4272
+ children: "Write it myself"
4273
+ }
4274
+ )
4275
+ ] })
4276
+ ]
4277
+ }
4278
+ )
4279
+ ] }),
4145
4280
  phase === "draft" && !submitted && /* @__PURE__ */ jsxs3(
4146
4281
  "div",
4147
4282
  {
@@ -6514,8 +6649,8 @@ function ReportDialog({
6514
6649
  }
6515
6650
  };
6516
6651
  useEffect4(() => {
6517
- setSimilarIssues(null);
6518
- setPickedSimilar(null);
6652
+ if (similarIssues !== null) setSimilarIssues(null);
6653
+ if (pickedSimilar !== null) setPickedSimilar(null);
6519
6654
  }, [description]);
6520
6655
  const handleSubmit = async (opts) => {
6521
6656
  var _a2, _b, _c;