glitchgrab 1.65.0 → 1.65.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.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);
@@ -3215,6 +3278,7 @@ function AssistSheet({
3215
3278
  function startNewChat() {
3216
3279
  flushEvents();
3217
3280
  chatIdRef.current = newChatId();
3281
+ setStalled(null);
3218
3282
  setMessages([]);
3219
3283
  setConversationId(null);
3220
3284
  onConversationChange == null ? void 0 : onConversationChange(null);
@@ -4201,6 +4265,74 @@ function AssistSheet({
4201
4265
  }
4202
4266
  )
4203
4267
  ] }),
4268
+ stalled && !busy && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "8px", minWidth: 0 }, role: "alert", children: [
4269
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Avatar, { who: "assistant", theme: t }),
4270
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4271
+ "div",
4272
+ {
4273
+ "data-gg-turn-timeout": "",
4274
+ style: {
4275
+ display: "flex",
4276
+ flexDirection: "column",
4277
+ gap: "10px",
4278
+ minWidth: 0,
4279
+ padding: "12px",
4280
+ borderRadius: "12px 12px 12px 4px",
4281
+ backgroundColor: t.bgSecondary,
4282
+ color: t.text,
4283
+ fontSize: "13px",
4284
+ lineHeight: 1.45
4285
+ },
4286
+ children: [
4287
+ /* @__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." }),
4288
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: [
4289
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4290
+ "button",
4291
+ {
4292
+ type: "button",
4293
+ "data-gg-turn-retry": "",
4294
+ onClick: () => {
4295
+ logEvent("turn_retry");
4296
+ void runTurn(stalled);
4297
+ },
4298
+ style: {
4299
+ padding: "8px 14px",
4300
+ borderRadius: "999px",
4301
+ border: "none",
4302
+ background: t.accent,
4303
+ color: t.accentText,
4304
+ fontSize: "12px",
4305
+ fontWeight: 600,
4306
+ fontFamily: "inherit",
4307
+ cursor: "pointer"
4308
+ },
4309
+ children: "Try again"
4310
+ }
4311
+ ),
4312
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4313
+ "button",
4314
+ {
4315
+ type: "button",
4316
+ "data-gg-turn-write-myself": "",
4317
+ onClick: () => leave("write_myself", "timed out"),
4318
+ style: {
4319
+ padding: "8px 14px",
4320
+ borderRadius: "999px",
4321
+ border: `1px solid ${t.inputBorder}`,
4322
+ background: "transparent",
4323
+ color: t.textMuted,
4324
+ fontSize: "12px",
4325
+ fontFamily: "inherit",
4326
+ cursor: "pointer"
4327
+ },
4328
+ children: "Write it myself"
4329
+ }
4330
+ )
4331
+ ] })
4332
+ ]
4333
+ }
4334
+ )
4335
+ ] }),
4204
4336
  phase === "draft" && !submitted && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4205
4337
  "div",
4206
4338
  {