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.js CHANGED
@@ -158,6 +158,7 @@ function toAssistTurnResult(ok, body) {
158
158
  // keeps the assistant button for this report.
159
159
  degraded: (_a = envelope == null ? void 0 : envelope.error) != null ? _a : ASSIST_OFFLINE_MESSAGE,
160
160
  retryable: (envelope == null ? void 0 : envelope.retryable) === true,
161
+ ...(envelope == null ? void 0 : envelope.timedOut) === true ? { timedOut: true } : {},
161
162
  ...(envelope == null ? void 0 : envelope.resendImages) === true ? { resendImages: true } : {}
162
163
  };
163
164
  }
@@ -2779,6 +2780,8 @@ function Avatar({
2779
2780
  );
2780
2781
  }
2781
2782
  var THINKING_SLOW_SECONDS = 20;
2783
+ var ASSIST_TURN_TIMEOUT_MS = 75e3;
2784
+ var ASSIST_UPLOAD_TIMEOUT_MS = 18e4;
2782
2785
  function ThinkingClock({ color }) {
2783
2786
  const [seconds, setSeconds] = (0, import_react3.useState)(0);
2784
2787
  (0, import_react3.useEffect)(() => {
@@ -2855,6 +2858,8 @@ function AssistSheet({
2855
2858
  const [messages, setMessages] = (0, import_react3.useState)([]);
2856
2859
  const [input, setInput] = (0, import_react3.useState)("");
2857
2860
  const [busy, setBusy] = (0, import_react3.useState)(false);
2861
+ const [stalled, setStalled] = (0, import_react3.useState)(null);
2862
+ const turnRef = (0, import_react3.useRef)(0);
2858
2863
  const [conversationId, setConversationId] = (0, import_react3.useState)(null);
2859
2864
  const [uploadProgress, setUploadProgress] = (0, import_react3.useState)(null);
2860
2865
  const storedImagesRef = (0, import_react3.useRef)({
@@ -2933,6 +2938,13 @@ function AssistSheet({
2933
2938
  const sentFiles = (0, import_react3.useMemo)(() => pickAssistFiles(files), [files]);
2934
2939
  const readFiles = new Set(sentFiles.map((f) => f.index));
2935
2940
  function leave(type, detail, exit = onClose) {
2941
+ if (type === "write_myself" && stalled && !description.trim()) {
2942
+ const typed = stalled.filter((m) => m.role === "user").map((m) => m.content).join("\n\n");
2943
+ if (typed) {
2944
+ if (!typePicked) keepTypedForForm(stalled);
2945
+ else onDescriptionChange(typed);
2946
+ }
2947
+ }
2936
2948
  logEvent(type, detail);
2937
2949
  flushEvents();
2938
2950
  exit();
@@ -2978,9 +2990,23 @@ function AssistSheet({
2978
2990
  async function runTurn(history2) {
2979
2991
  var _a2, _b, _c;
2980
2992
  const turnChat = chatIdRef.current;
2993
+ const turn = ++turnRef.current;
2994
+ const current = () => turnRef.current === turn;
2995
+ setStalled(null);
2981
2996
  setBusy(true);
2982
2997
  let result;
2983
2998
  const events = takeEvents();
2999
+ let waited;
3000
+ let giveUp = () => {
3001
+ };
3002
+ const gaveUp = new Promise((resolve) => {
3003
+ giveUp = () => resolve("timeout");
3004
+ });
3005
+ const arm = (ms) => {
3006
+ clearTimeout(waited);
3007
+ waited = setTimeout(giveUp, ms);
3008
+ };
3009
+ arm(ASSIST_TURN_TIMEOUT_MS);
2984
3010
  try {
2985
3011
  const picked = pickAssistImages(assistImages());
2986
3012
  const held = storedImagesRef.current;
@@ -2988,6 +3014,7 @@ function AssistSheet({
2988
3014
  const call = async (known) => {
2989
3015
  const { screenshots: sent, hasData } = await toSendList(picked, known);
2990
3016
  setUploadProgress(null);
3017
+ if (hasData) arm(ASSIST_UPLOAD_TIMEOUT_MS);
2991
3018
  return assist(
2992
3019
  {
2993
3020
  // `kind` only on drafts, so an older server sees the exact shape it
@@ -3013,13 +3040,37 @@ function AssistSheet({
3013
3040
  },
3014
3041
  events
3015
3042
  },
3016
- hasData ? { onUploadProgress: setUploadProgress } : void 0
3043
+ hasData ? {
3044
+ onUploadProgress: (fraction) => {
3045
+ if (!current()) return;
3046
+ setUploadProgress(fraction);
3047
+ if (fraction >= 1) arm(ASSIST_TURN_TIMEOUT_MS);
3048
+ }
3049
+ } : void 0
3017
3050
  );
3018
3051
  };
3019
- result = await call(stored);
3052
+ const first = await Promise.race([call(stored), gaveUp]);
3053
+ if (first === "timeout") {
3054
+ if (current() && chatIdRef.current === turnChat) {
3055
+ logEvent("turn_timeout", "sheet");
3056
+ setStalled(history2);
3057
+ }
3058
+ return;
3059
+ }
3060
+ result = first;
3061
+ if (!current()) return;
3020
3062
  if (result.resendImages) {
3021
3063
  storedImagesRef.current = { conversationId: null, hashes: /* @__PURE__ */ new Set() };
3022
- result = await call(/* @__PURE__ */ new Set());
3064
+ const again = await Promise.race([call(/* @__PURE__ */ new Set()), gaveUp]);
3065
+ if (again === "timeout") {
3066
+ if (current() && chatIdRef.current === turnChat) {
3067
+ logEvent("turn_timeout", "sheet");
3068
+ setStalled(history2);
3069
+ }
3070
+ return;
3071
+ }
3072
+ result = again;
3073
+ if (!current()) return;
3023
3074
  }
3024
3075
  if (result.conversationId && result.storedImages) {
3025
3076
  storedImagesRef.current = {
@@ -3028,6 +3079,7 @@ function AssistSheet({
3028
3079
  };
3029
3080
  }
3030
3081
  } catch (e) {
3082
+ if (!current()) return;
3031
3083
  keepTypedForForm(history2);
3032
3084
  degradeKeepingEvents(
3033
3085
  events,
@@ -3035,10 +3087,19 @@ function AssistSheet({
3035
3087
  );
3036
3088
  return;
3037
3089
  } finally {
3038
- setBusy(false);
3039
- setUploadProgress(null);
3090
+ clearTimeout(waited);
3091
+ if (current()) {
3092
+ setBusy(false);
3093
+ setUploadProgress(null);
3094
+ }
3095
+ }
3096
+ if (!current() || chatIdRef.current !== turnChat) return;
3097
+ if (result.degraded && result.timedOut) {
3098
+ if (events) eventsRef.current = [...events, ...eventsRef.current];
3099
+ logEvent("turn_timeout", "server");
3100
+ setStalled(history2);
3101
+ return;
3040
3102
  }
3041
- if (chatIdRef.current !== turnChat) return;
3042
3103
  if (result.degraded) {
3043
3104
  keepTypedForForm(history2);
3044
3105
  degradeKeepingEvents(events, result.degraded, result.retryable === true);
@@ -3119,6 +3180,7 @@ function AssistSheet({
3119
3180
  function send(text) {
3120
3181
  const value = text.trim();
3121
3182
  if (!value || busy) return;
3183
+ setStalled(null);
3122
3184
  setOptions([]);
3123
3185
  setGlitchgrabOffer(false);
3124
3186
  const underDraft = phase === "draft";
@@ -3183,6 +3245,7 @@ function AssistSheet({
3183
3245
  var _a2;
3184
3246
  flushEvents();
3185
3247
  chatIdRef.current = chat.id;
3248
+ setStalled(null);
3186
3249
  setMessages(chat.messages);
3187
3250
  setConversationId(chat.conversationId);
3188
3251
  onConversationChange == null ? void 0 : onConversationChange(chat.conversationId);
@@ -3206,6 +3269,7 @@ function AssistSheet({
3206
3269
  setShowChats(false);
3207
3270
  setViewingChat(null);
3208
3271
  resumeAskRef.current = (last == null ? void 0 : last.role) === "user";
3272
+ seedPendingRef.current = false;
3209
3273
  }
3210
3274
  (0, import_react3.useEffect)(() => {
3211
3275
  if (!resumeAskRef.current) return;
@@ -3215,6 +3279,7 @@ function AssistSheet({
3215
3279
  function startNewChat() {
3216
3280
  flushEvents();
3217
3281
  chatIdRef.current = newChatId();
3282
+ setStalled(null);
3218
3283
  setMessages([]);
3219
3284
  setConversationId(null);
3220
3285
  onConversationChange == null ? void 0 : onConversationChange(null);
@@ -3238,6 +3303,79 @@ function AssistSheet({
3238
3303
  const otherChats = savedChats.filter((c) => c.id !== chatIdRef.current);
3239
3304
  const resumable = (_a = otherChats.find((c) => c.status === "open" && c.messages.length > 0)) != null ? _a : null;
3240
3305
  const empty = (phase === "chat" || phase === "type") && messages.length === 0 && !busy;
3306
+ const resumeCard = resumable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3307
+ "div",
3308
+ {
3309
+ "data-gg-resume-chat": "",
3310
+ style: {
3311
+ display: "flex",
3312
+ flexDirection: "column",
3313
+ gap: "8px",
3314
+ padding: "10px 12px",
3315
+ borderRadius: "10px",
3316
+ border: `1px solid ${t.accent}55`,
3317
+ backgroundColor: t.bgSecondary,
3318
+ minWidth: 0
3319
+ },
3320
+ children: [
3321
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11.5px", color: t.textMuted }, children: [
3322
+ "Pick up where you left off \xB7 ",
3323
+ chatAge(resumable.updatedAt)
3324
+ ] }),
3325
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3326
+ "span",
3327
+ {
3328
+ style: {
3329
+ fontSize: "13px",
3330
+ lineHeight: 1.45,
3331
+ overflowWrap: "anywhere"
3332
+ },
3333
+ children: resumable.title
3334
+ }
3335
+ ),
3336
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
3337
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3338
+ "button",
3339
+ {
3340
+ type: "button",
3341
+ "data-gg-resume-continue": "",
3342
+ onClick: () => resumeChat(resumable),
3343
+ style: {
3344
+ border: "none",
3345
+ borderRadius: "999px",
3346
+ backgroundColor: t.accent,
3347
+ color: t.accentText,
3348
+ padding: "7px 13px",
3349
+ fontSize: "12px",
3350
+ fontWeight: 600,
3351
+ fontFamily: "inherit",
3352
+ cursor: "pointer"
3353
+ },
3354
+ children: "Continue this chat"
3355
+ }
3356
+ ),
3357
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3358
+ "button",
3359
+ {
3360
+ type: "button",
3361
+ onClick: () => setShowChats(true),
3362
+ style: {
3363
+ border: `1px solid ${t.inputBorder}`,
3364
+ borderRadius: "999px",
3365
+ background: "transparent",
3366
+ color: t.textMuted,
3367
+ padding: "7px 13px",
3368
+ fontSize: "12px",
3369
+ fontFamily: "inherit",
3370
+ cursor: "pointer"
3371
+ },
3372
+ children: "All chats"
3373
+ }
3374
+ )
3375
+ ] })
3376
+ ]
3377
+ }
3378
+ ) : null;
3241
3379
  function renderChatList() {
3242
3380
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-gg-chat-list": "", style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
3243
3381
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
@@ -3631,6 +3769,7 @@ function AssistSheet({
3631
3769
  },
3632
3770
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: showChats ? "none" : "contents" }, children: [
3633
3771
  phase === "severity" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "12px" }, children: [
3772
+ resumeCard,
3634
3773
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
3635
3774
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Avatar, { who: "assistant", theme: t }),
3636
3775
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -3804,79 +3943,7 @@ function AssistSheet({
3804
3943
  )
3805
3944
  ] }),
3806
3945
  empty && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "12px" }, children: [
3807
- resumable && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3808
- "div",
3809
- {
3810
- "data-gg-resume-chat": "",
3811
- style: {
3812
- display: "flex",
3813
- flexDirection: "column",
3814
- gap: "8px",
3815
- padding: "10px 12px",
3816
- borderRadius: "10px",
3817
- border: `1px solid ${t.accent}55`,
3818
- backgroundColor: t.bgSecondary,
3819
- minWidth: 0
3820
- },
3821
- children: [
3822
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11.5px", color: t.textMuted }, children: [
3823
- "Pick up where you left off \xB7 ",
3824
- chatAge(resumable.updatedAt)
3825
- ] }),
3826
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3827
- "span",
3828
- {
3829
- style: {
3830
- fontSize: "13px",
3831
- lineHeight: 1.45,
3832
- overflowWrap: "anywhere"
3833
- },
3834
- children: resumable.title
3835
- }
3836
- ),
3837
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
3838
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3839
- "button",
3840
- {
3841
- type: "button",
3842
- "data-gg-resume-continue": "",
3843
- onClick: () => resumeChat(resumable),
3844
- style: {
3845
- border: "none",
3846
- borderRadius: "999px",
3847
- backgroundColor: t.accent,
3848
- color: t.accentText,
3849
- padding: "7px 13px",
3850
- fontSize: "12px",
3851
- fontWeight: 600,
3852
- fontFamily: "inherit",
3853
- cursor: "pointer"
3854
- },
3855
- children: "Continue this chat"
3856
- }
3857
- ),
3858
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3859
- "button",
3860
- {
3861
- type: "button",
3862
- onClick: () => setShowChats(true),
3863
- style: {
3864
- border: `1px solid ${t.inputBorder}`,
3865
- borderRadius: "999px",
3866
- background: "transparent",
3867
- color: t.textMuted,
3868
- padding: "7px 13px",
3869
- fontSize: "12px",
3870
- fontFamily: "inherit",
3871
- cursor: "pointer"
3872
- },
3873
- children: "All chats"
3874
- }
3875
- )
3876
- ] })
3877
- ]
3878
- }
3879
- ),
3946
+ resumeCard,
3880
3947
  phase !== "type" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
3881
3948
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
3882
3949
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Avatar, { who: "assistant", theme: t }),
@@ -4201,6 +4268,74 @@ function AssistSheet({
4201
4268
  }
4202
4269
  )
4203
4270
  ] }),
4271
+ stalled && !busy && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px", minWidth: 0 }, role: "alert", children: [
4272
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Avatar, { who: "assistant", theme: t }),
4273
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4274
+ "div",
4275
+ {
4276
+ "data-gg-turn-timeout": "",
4277
+ style: {
4278
+ display: "flex",
4279
+ flexDirection: "column",
4280
+ gap: "10px",
4281
+ minWidth: 0,
4282
+ padding: "12px",
4283
+ borderRadius: "12px 12px 12px 4px",
4284
+ backgroundColor: t.bgSecondary,
4285
+ color: t.text,
4286
+ fontSize: "13px",
4287
+ lineHeight: 1.45
4288
+ },
4289
+ children: [
4290
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "No answer \u2014 this is taking too long. Try again, or write it yourself; what you typed comes with you." }),
4291
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: [
4292
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4293
+ "button",
4294
+ {
4295
+ type: "button",
4296
+ "data-gg-turn-retry": "",
4297
+ onClick: () => {
4298
+ logEvent("turn_retry");
4299
+ void runTurn(stalled);
4300
+ },
4301
+ style: {
4302
+ padding: "8px 14px",
4303
+ borderRadius: "999px",
4304
+ border: "none",
4305
+ background: t.accent,
4306
+ color: t.accentText,
4307
+ fontSize: "12px",
4308
+ fontWeight: 600,
4309
+ fontFamily: "inherit",
4310
+ cursor: "pointer"
4311
+ },
4312
+ children: "Try again"
4313
+ }
4314
+ ),
4315
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4316
+ "button",
4317
+ {
4318
+ type: "button",
4319
+ "data-gg-turn-write-myself": "",
4320
+ onClick: () => leave("write_myself", "timed out"),
4321
+ style: {
4322
+ padding: "8px 14px",
4323
+ borderRadius: "999px",
4324
+ border: `1px solid ${t.inputBorder}`,
4325
+ background: "transparent",
4326
+ color: t.textMuted,
4327
+ fontSize: "12px",
4328
+ fontFamily: "inherit",
4329
+ cursor: "pointer"
4330
+ },
4331
+ children: "Write it myself"
4332
+ }
4333
+ )
4334
+ ] })
4335
+ ]
4336
+ }
4337
+ )
4338
+ ] }),
4204
4339
  phase === "draft" && !submitted && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4205
4340
  "div",
4206
4341
  {
@@ -6573,8 +6708,8 @@ function ReportDialog({
6573
6708
  }
6574
6709
  };
6575
6710
  (0, import_react.useEffect)(() => {
6576
- setSimilarIssues(null);
6577
- setPickedSimilar(null);
6711
+ if (similarIssues !== null) setSimilarIssues(null);
6712
+ if (pickedSimilar !== null) setPickedSimilar(null);
6578
6713
  }, [description]);
6579
6714
  const handleSubmit = async (opts) => {
6580
6715
  var _a2, _b, _c;