dsh-codex-subscription 3.2.2 → 3.2.4

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/lib/client.js CHANGED
@@ -153,6 +153,63 @@ window.__ModuleLoader__.load({
153
153
  };
154
154
  }
155
155
  //#endregion
156
+ //#region src/use-image-source.js
157
+ function useImageSource(load, identity, preview) {
158
+ const [attempt, setAttempt] = (0, react.useState)(0);
159
+ const [state, setState] = (0, react.useState)({
160
+ identity,
161
+ src: preview,
162
+ failed: false,
163
+ usable: false
164
+ });
165
+ (0, react.useEffect)(() => {
166
+ let live = true;
167
+ setState((previous) => ({
168
+ identity,
169
+ src: previous.identity === identity ? previous.src : preview,
170
+ failed: false,
171
+ usable: previous.identity === identity && previous.usable
172
+ }));
173
+ Promise.resolve().then(() => attempt === 0 && preview ? preview : load()).then((src) => {
174
+ if (live) setState((previous) => ({
175
+ identity,
176
+ src,
177
+ failed: !src,
178
+ usable: previous.identity === identity && previous.src === src && previous.usable
179
+ }));
180
+ }, () => {
181
+ if (live) setState((previous) => ({
182
+ ...previous,
183
+ failed: true
184
+ }));
185
+ });
186
+ return () => {
187
+ live = false;
188
+ };
189
+ }, [
190
+ identity,
191
+ load,
192
+ preview,
193
+ attempt
194
+ ]);
195
+ return {
196
+ src: state.identity === identity ? state.src : preview,
197
+ failed: state.identity === identity && state.failed,
198
+ usable: state.identity === identity && state.usable,
199
+ loaded: () => setState((previous) => previous.identity === identity ? {
200
+ ...previous,
201
+ usable: true
202
+ } : previous),
203
+ fail: () => setState((previous) => previous.identity === identity ? {
204
+ ...previous,
205
+ failed: true,
206
+ usable: false
207
+ } : previous),
208
+ retry: () => setAttempt((value) => value + 1),
209
+ attempt
210
+ };
211
+ }
212
+ //#endregion
156
213
  //#region src/image-edit.js
157
214
  const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
158
215
  const validCoordinate = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
@@ -236,7 +293,7 @@ window.__ModuleLoader__.load({
236
293
  * sourceInDraft?: boolean }} options
237
294
  */
238
295
  function officialImageTools({ src, name, t, attachForEdit, sourceInDraft = false }) {
239
- const send = (draft, extraFiles = []) => attachForEdit(src, name, draft, [], void 0, sourceInDraft, extraFiles);
296
+ const send = (draft, extraFiles = [], signal) => attachForEdit(src, name, draft, [], void 0, sourceInDraft, extraFiles, { signal });
240
297
  const base = {
241
298
  pendingLabel: t("imageEditPreparing"),
242
299
  errorLabel: t("imageEditFailed"),
@@ -248,17 +305,17 @@ window.__ModuleLoader__.load({
248
305
  id: "remove-background",
249
306
  kind: "tool",
250
307
  label: t("imageRemoveBackground"),
251
- onInvoke: () => send(t("imageRemoveBackgroundPrompt"))
308
+ onInvoke: ({ signal } = {}) => send(t("imageRemoveBackgroundPrompt"), [], signal)
252
309
  },
253
310
  {
254
311
  ...base,
255
312
  id: "erase",
256
313
  kind: "mask",
257
314
  label: t("imageErase"),
258
- onInvoke: async ({ mask }) => {
315
+ onInvoke: async ({ mask, signal }) => {
259
316
  if (!(mask instanceof Blob)) throw new Error("Mark the area to erase first");
260
317
  const maskName = `${String(name).replace(/\.[a-z0-9]+$/iu, "")}-erase-mask.png`;
261
- return send(t("imageErasePrompt"), [new File([mask], maskName, { type: "image/png" })]);
318
+ return send(t("imageErasePrompt"), [new File([mask], maskName, { type: "image/png" })], signal);
262
319
  }
263
320
  },
264
321
  {
@@ -270,18 +327,30 @@ window.__ModuleLoader__.load({
270
327
  value: ratio,
271
328
  label: `${t(`imageRatio_${id}`)} ${ratio}`
272
329
  })),
273
- onInvoke: ({ option }) => send(t("imageResizePrompt").replaceAll("{aspectRatio}", option))
330
+ onInvoke: ({ option, signal }) => send(t("imageResizePrompt").replaceAll("{aspectRatio}", option), [], signal)
274
331
  }
275
332
  ];
276
333
  }
277
334
  //#endregion
335
+ //#region src/composer-attachment-native.js
336
+ function nativeComposerAttachments(entries, ownComponent) {
337
+ return entries.find((entry) => entry.component !== ownComponent && entry.locale === "conversation" && !entry.store && !entry.children && (entry.inject === void 0 || typeof entry.inject === "function"));
338
+ }
339
+ function nativeComposerProps(entry, props, translate) {
340
+ return {
341
+ ...props,
342
+ ...entry.inject?.(props.sessionId),
343
+ t: translate
344
+ };
345
+ }
346
+ //#endregion
278
347
  //#region src/client-image-previews.jsx
279
- function openPreview(props, item, opener, sourceInDraft = false) {
348
+ function openPreview(props, item, opener, sourceInDraft = false, group = [item]) {
280
349
  const { service, preference, t, attachForEdit } = props;
281
350
  const settings = preference.getSnapshot();
282
- const referenceName = `annotated-${item.name}.png`;
283
- service.open({
284
- items: [{
351
+ const items = group.map((item) => {
352
+ const referenceName = `annotated-${String(item.name).replace(/\.[a-z0-9]+$/iu, "")}.png`;
353
+ return {
285
354
  ...item,
286
355
  actions: settings.imageEditing ? [
287
356
  {
@@ -290,12 +359,15 @@ window.__ModuleLoader__.load({
290
359
  pendingLabel: t("imageEditPreparing"),
291
360
  errorLabel: t("imageEditFailed"),
292
361
  closeOnSuccess: true,
293
- onInvoke: ({ annotations }) => attachForEdit(item.src, item.name, buildImageEditDraft({
362
+ onInvoke: ({ annotations, signal }) => attachForEdit(item.src, item.name, buildImageEditDraft({
294
363
  annotations,
295
364
  translate: t,
296
365
  sourceName: item.name,
297
366
  referenceName
298
- }), annotations, referenceName, sourceInDraft)
367
+ }), annotations, referenceName, sourceInDraft, void 0, {
368
+ signal,
369
+ sourceId: sourceInDraft ? item.id : void 0
370
+ })
299
371
  },
300
372
  ...officialImageTools({
301
373
  src: item.src,
@@ -312,8 +384,13 @@ window.__ModuleLoader__.load({
312
384
  onInvoke: () => props.openSketchImage(item.src, item.name)
313
385
  }] : []
314
386
  ] : []
315
- }],
387
+ };
388
+ });
389
+ service.open({
390
+ items,
391
+ index: Math.max(0, items.findIndex((candidate) => candidate.id === item.id)),
316
392
  opener,
393
+ scope: props.sessionId,
317
394
  source: sourceInDraft ? "codex-draft" : "codex-message",
318
395
  annotations: settings.imageAnnotations
319
396
  });
@@ -323,31 +400,34 @@ window.__ModuleLoader__.load({
323
400
  const entry = (0, react.useSyncExternalStore)(watchNativeAttachments, nativeAttachments);
324
401
  (0, react.useEffect)(() => {
325
402
  const current = service.getSnapshot();
326
- if (current?.source === "codex-draft" && !attachments.some((item) => item.id === current.items[0]?.id)) service.close();
403
+ if (current?.source === "codex-draft" && current.items.some((image) => !attachments.some((item) => item.id === image.id))) service.close();
327
404
  }, [attachments, service]);
328
405
  (0, react.useEffect)(() => () => {
329
406
  if (service.getSnapshot()?.source === "codex-draft") service.close();
330
407
  }, [service]);
331
408
  const latest = (0, react.useRef)(props);
409
+ const root = (0, react.useRef)(null);
332
410
  latest.current = props;
333
411
  (0, react.useEffect)(() => {
334
412
  const onWindowClick = (event) => {
335
413
  const target = event.target;
336
414
  if (!(target instanceof Element)) return;
337
415
  const button = target.closest("button"), image = button?.querySelector(":scope > img");
416
+ if (!button || !root.current?.contains(button)) return;
338
417
  const item = image && latest.current.attachments.find((candidate) => candidate.previewUrl === image.src);
339
418
  if (!item || event.button !== 0 || event.ctrlKey || event.metaKey || event.altKey) return;
340
419
  event.preventDefault();
341
420
  event.stopPropagation();
342
421
  event.stopImmediatePropagation();
343
- openPreview(latest.current, {
422
+ const group = latest.current.attachments.filter((item) => item.previewUrl).map((item) => ({
344
423
  id: item.id,
345
424
  src: item.previewUrl,
346
425
  name: item.file.name,
347
426
  width: item.width,
348
427
  height: item.height,
349
428
  bytes: item.file.size
350
- }, button, true);
429
+ }));
430
+ openPreview(latest.current, group.find((image) => image.id === item.id), button, true, group);
351
431
  };
352
432
  window.addEventListener("click", onWindowClick, true);
353
433
  return () => window.removeEventListener("click", onWindowClick, true);
@@ -355,39 +435,15 @@ window.__ModuleLoader__.load({
355
435
  if (!entry) return null;
356
436
  const NativeAttachments = entry.component;
357
437
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
438
+ ref: root,
358
439
  style: { display: "contents" },
359
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NativeAttachments, {
360
- ...props,
361
- t: nativeTranslate
362
- })
440
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NativeAttachments, { ...nativeComposerProps(entry, props, nativeTranslate) })
363
441
  });
364
442
  }
365
- function MessageImagePreview({ image, ...props }) {
443
+ function MessageImagePreview({ image, onOpen, ...props }) {
366
444
  const { loadImage, t } = props;
367
- const [src, setSrc] = (0, react.useState)(image.preview?.url);
368
- const [failed, setFailed] = (0, react.useState)(false);
369
- const [attempt, setAttempt] = (0, react.useState)(0);
370
- (0, react.useEffect)(() => {
371
- if (image.preview) {
372
- setSrc(image.preview.url);
373
- return;
374
- }
375
- let live = true;
376
- setSrc(void 0);
377
- setFailed(false);
378
- Promise.resolve().then(() => loadImage(image.attachment)).then((value) => {
379
- if (live) setSrc(value);
380
- }, () => {
381
- if (live) setFailed(true);
382
- });
383
- return () => {
384
- live = false;
385
- };
386
- }, [
387
- image,
388
- loadImage,
389
- attempt
390
- ]);
445
+ const reload = (0, react.useCallback)(() => image.attachment ? loadImage(image.attachment) : image.preview?.url, [image, loadImage]);
446
+ const { src, failed, retry, fail, attempt, usable, loaded } = useImageSource(reload, image.attachment?.attachmentId ?? image.preview?.url ?? image, image.preview?.url);
391
447
  const item = {
392
448
  ...image.attachment ?? image.preview,
393
449
  ...image.label ? { name: image.label } : {}
@@ -399,24 +455,49 @@ window.__ModuleLoader__.load({
399
455
  disabled: !src && !failed,
400
456
  onClick: (event) => {
401
457
  if (failed) {
402
- setAttempt((value) => value + 1);
458
+ retry();
403
459
  return;
404
460
  }
405
- openPreview(props, {
461
+ onOpen(image, {
406
462
  id: item.attachmentId ?? src,
407
463
  src,
464
+ reload,
408
465
  name: item.name ?? "image.png",
409
466
  width: item.width,
410
467
  height: item.height
411
468
  }, event.currentTarget);
412
469
  },
413
- children: src ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
470
+ children: failed && !usable ? t("accountRetry") : src ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
414
471
  src,
472
+ onError: fail,
473
+ onLoad: loaded,
415
474
  alt: item.name ?? "image"
416
- }) : failed ? t("accountRetry") : "…"
475
+ }, attempt), failed ? t("accountRetry") : null] }) : "…"
417
476
  });
418
477
  }
419
478
  function MessageImagePreviews({ images, align, compact, thumbnail, ...props }) {
479
+ const opening = (0, react.useRef)(0);
480
+ (0, react.useEffect)(() => () => {
481
+ opening.current++;
482
+ }, [images]);
483
+ const onOpen = async (selected, item, opener) => {
484
+ const revision = ++opening.current;
485
+ const group = await Promise.all(images.map(async (image) => {
486
+ if (image === selected) return item;
487
+ const ref = image.attachment ?? image.preview;
488
+ const reload = () => image.attachment ? props.loadImage(image.attachment) : image.preview?.url;
489
+ const src = image.preview?.url ?? await reload().catch(() => "about:blank");
490
+ return {
491
+ id: ref.attachmentId ?? src,
492
+ src,
493
+ reload,
494
+ name: ref.name ?? "image.png",
495
+ width: ref.width,
496
+ height: ref.height
497
+ };
498
+ }));
499
+ if (revision === opening.current) openPreview(props, item, opener, false, group);
500
+ };
420
501
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
421
502
  className: "codexMessageImages",
422
503
  "data-align": align,
@@ -424,6 +505,7 @@ window.__ModuleLoader__.load({
424
505
  "data-thumbnail": thumbnail || void 0,
425
506
  children: images.map((image, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessageImagePreview, {
426
507
  image,
508
+ onOpen,
427
509
  ...props
428
510
  }, image.attachment?.attachmentId ?? image.preview?.url ?? index))
429
511
  });
@@ -645,6 +727,10 @@ window.__ModuleLoader__.load({
645
727
  }
646
728
  //#endregion
647
729
  //#region src/original-image-download.js
730
+ function imageEditSource(rpc, sessionId, original, preview) {
731
+ if (original === void 0) return preview;
732
+ return async ({ signal } = {}) => new Blob([await readOriginalImage(rpc, sessionId, original, { signal })], { type: original.mediaType });
733
+ }
648
734
  function decodeBase64Chunk(value) {
649
735
  if (typeof value !== "string" || value.length === 0 || value.length > Math.ceil(4194304 / 3) * 4 + 8) throw new Error("Invalid original image chunk");
650
736
  let decoded;
@@ -715,90 +801,84 @@ window.__ModuleLoader__.load({
715
801
  URL.revokeObjectURL(url);
716
802
  }
717
803
  }
718
- function CodexGeneratedImage({ attachment, original, rpc, sessionId, loadImage, openSketchImage, attachForEdit, getImageViewer, getInternalImageViewer, t, features }) {
719
- const [attempt, setAttempt] = (0, react.useState)(0);
720
- const [error, setError] = (0, react.useState)(false);
721
- const [src, setSrc] = (0, react.useState)();
804
+ function CodexGeneratedImage({ attachment, original, gallery, rpc, sessionId, loadImage, openSketchImage, attachForEdit, getImageViewer, getInternalImageViewer, t, features }) {
805
+ const { src, failed: error, fail, retry, attempt, usable, loaded } = useImageSource((0, react.useCallback)(() => loadImage(attachment), [attachment, loadImage]), attachment.attachmentId ?? attachment);
722
806
  const triggerRef = (0, react.useRef)(null);
723
- (0, react.useEffect)(() => {
724
- let live = true;
725
- setError(false);
726
- setSrc(void 0);
727
- Promise.resolve().then(() => loadImage(attachment)).then((value) => {
728
- if (live) setSrc(value);
729
- }).catch(() => {
730
- if (live) setError(true);
731
- });
732
- return () => {
733
- live = false;
734
- };
735
- }, [
736
- attachment,
737
- loadImage,
738
- attempt
739
- ]);
807
+ const opening = (0, react.useRef)(0);
808
+ (0, react.useEffect)(() => () => {
809
+ opening.current++;
810
+ }, [attachment]);
740
811
  const label = attachment.name ?? t("imageLabel");
741
- const downloadName = imageDownloadName(attachment);
742
- const downloadOriginal = async ({ signal, onProgress } = {}) => {
743
- if (original === void 0) return;
744
- triggerBlobDownload(await readOriginalImage(rpc, sessionId, original, {
745
- signal,
746
- onProgress
747
- }), original.mediaType, original.name);
748
- };
749
- const openImage = () => {
812
+ const makeItem = (attachment, original, src) => {
813
+ const downloadName = imageDownloadName(attachment);
814
+ const editSource = imageEditSource(rpc, sessionId, original, src);
815
+ return {
816
+ id: attachment.attachmentId ?? downloadName,
817
+ src,
818
+ reload: () => loadImage(attachment),
819
+ name: attachment.name ?? t("imageLabel"),
820
+ width: original?.width ?? attachment.width,
821
+ height: original?.height ?? attachment.height,
822
+ bytes: original?.bytes ?? attachment.bytes,
823
+ download: original === void 0 ? void 0 : {
824
+ pendingLabel: t("imageDownloadPreparing"),
825
+ errorLabel: t("imageDownloadFailed"),
826
+ onInvoke: async ({ signal, onProgress } = {}) => triggerBlobDownload(await readOriginalImage(rpc, sessionId, original, {
827
+ signal,
828
+ onProgress
829
+ }), original.mediaType, original.name)
830
+ },
831
+ actions: !features.imageEditing ? [] : [
832
+ {
833
+ id: "continue-editing",
834
+ label: t("imageEdit"),
835
+ pendingLabel: t("imageEditPreparing"),
836
+ errorLabel: t("imageEditFailed"),
837
+ closeOnSuccess: true,
838
+ onInvoke: ({ annotations = [], signal }) => {
839
+ const imageKey = String(attachment.attachmentId ?? "image").replace(/[^a-zA-Z0-9_-]/g, "_");
840
+ const sourceName = annotations.length === 0 ? downloadName : `codex-edit-${imageKey}-source.png`;
841
+ const referenceName = `codex-edit-${imageKey}-annotations.png`;
842
+ return attachForEdit(editSource, sourceName, buildImageEditDraft({
843
+ annotations,
844
+ translate: t,
845
+ width: original?.width ?? attachment.width,
846
+ height: original?.height ?? attachment.height,
847
+ sourceName,
848
+ referenceName
849
+ }), annotations, referenceName, false, void 0, { signal });
850
+ }
851
+ },
852
+ ...officialImageTools({
853
+ src: editSource,
854
+ name: downloadName,
855
+ t,
856
+ attachForEdit
857
+ }),
858
+ ...features.imageSketch && openSketchImage ? [{
859
+ id: "sketch",
860
+ label: t("imageToSketch"),
861
+ pendingLabel: t("imageEditPreparing"),
862
+ errorLabel: t("imageEditFailed"),
863
+ onInvoke: () => openSketchImage(src, downloadName)
864
+ }] : []
865
+ ]
866
+ };
867
+ };
868
+ const openImage = async () => {
750
869
  if (src === void 0) return;
870
+ const revision = ++opening.current;
871
+ const items = await Promise.all((gallery ?? [{
872
+ attachment,
873
+ original
874
+ }]).map(async (image) => makeItem(image.attachment, image.original, image.attachment === attachment ? src : await loadImage(image.attachment).catch(() => "about:blank"))));
875
+ if (revision !== opening.current) return;
751
876
  const request = {
752
- items: [{
753
- id: attachment.attachmentId ?? downloadName,
754
- src,
755
- name: label,
756
- width: attachment.width,
757
- height: attachment.height,
758
- bytes: attachment.bytes,
759
- download: original === void 0 ? void 0 : {
760
- pendingLabel: t("imageDownloadPreparing"),
761
- errorLabel: t("imageDownloadFailed"),
762
- onInvoke: downloadOriginal
763
- },
764
- actions: !features.imageEditing ? [] : [
765
- {
766
- id: "continue-editing",
767
- label: t("imageEdit"),
768
- pendingLabel: t("imageEditPreparing"),
769
- errorLabel: t("imageEditFailed"),
770
- closeOnSuccess: true,
771
- onInvoke: ({ annotations = [] }) => {
772
- const imageKey = String(attachment.attachmentId ?? "image").replace(/[^a-zA-Z0-9_-]/g, "_");
773
- const sourceName = annotations.length === 0 ? downloadName : `codex-edit-${imageKey}-source.png`;
774
- const referenceName = `codex-edit-${imageKey}-annotations.png`;
775
- return attachForEdit(src, sourceName, buildImageEditDraft({
776
- annotations,
777
- translate: t,
778
- width: attachment.width,
779
- height: attachment.height,
780
- sourceName,
781
- referenceName
782
- }), annotations, referenceName);
783
- }
784
- },
785
- ...officialImageTools({
786
- src,
787
- name: downloadName,
788
- t,
789
- attachForEdit
790
- }),
791
- ...features.imageSketch && openSketchImage ? [{
792
- id: "sketch",
793
- label: t("imageToSketch"),
794
- pendingLabel: t("imageEditPreparing"),
795
- errorLabel: t("imageEditFailed"),
796
- onInvoke: () => openSketchImage(src, downloadName)
797
- }] : []
798
- ]
799
- }],
877
+ items,
878
+ index: Math.max(0, items.findIndex((item) => item.id === attachment.attachmentId)),
800
879
  opener: triggerRef.current,
801
880
  source: "codex-generated",
881
+ scope: sessionId,
802
882
  annotations: features.imageViewer && features.imageAnnotations
803
883
  };
804
884
  if (features.imageViewer && getInternalImageViewer?.()?.open?.(request) === true) return;
@@ -809,26 +889,28 @@ window.__ModuleLoader__.load({
809
889
  });
810
890
  else window.open(src, "_blank", "noopener,noreferrer");
811
891
  };
812
- if (error) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
892
+ if (error && !usable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
813
893
  type: "button",
814
894
  className: "codexGeneratedImageRetry",
815
- onClick: () => setAttempt((value) => value + 1),
895
+ onClick: retry,
816
896
  children: t("imageLoadFailed")
817
897
  });
818
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
898
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
819
899
  ref: triggerRef,
820
900
  type: "button",
821
901
  className: "codexGeneratedImageFrame",
822
- title: t("imageOpen"),
902
+ title: error ? t("imageLoadFailed") : t("imageOpen"),
823
903
  "aria-label": t("imageOpenNamed").replace("{value}", String(label)),
824
- onClick: openImage,
825
- children: src === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("imageLoading") }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
904
+ onClick: error ? retry : openImage,
905
+ children: [src === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("imageLoading") }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
826
906
  src,
907
+ onError: fail,
908
+ onLoad: loaded,
827
909
  alt: label
828
- })
910
+ }, attempt), error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("imageLoadFailed") }) : null]
829
911
  });
830
912
  }
831
- function CodexImageToolRow({ presentation = "tool", block, sessionId, rpc, loadImage, openSketchImage, attachForEdit, getImageViewer, getInternalImageViewer, t, preference }) {
913
+ function CodexImageToolRow({ presentation = "tool", block, gallery, sessionId, rpc, loadImage, openSketchImage, attachForEdit, getImageViewer, getInternalImageViewer, t, preference }) {
832
914
  const features = (0, react.useSyncExternalStore)(preference.subscribe, preference.getSnapshot);
833
915
  const settled = block?.kind === "tool-result";
834
916
  const image = settled ? block.content.find((item) => item?.type === "image" && item.attachment !== void 0) : void 0;
@@ -865,6 +947,7 @@ window.__ModuleLoader__.load({
865
947
  features,
866
948
  attachment: image.attachment,
867
949
  original,
950
+ gallery,
868
951
  rpc,
869
952
  sessionId,
870
953
  loadImage,
@@ -905,10 +988,15 @@ window.__ModuleLoader__.load({
905
988
  });
906
989
  }
907
990
  function CodexImageOutput({ node, ...props }) {
991
+ const gallery = node.data.blocks.flatMap((block) => block.content.filter((item) => item?.type === "image" && item.attachment).map((item) => ({
992
+ attachment: item.attachment,
993
+ original: decodeImagePresentation(block?.meta)?.original
994
+ })));
908
995
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
909
996
  className: "codexImageOutput",
910
997
  children: node.data.blocks.map((block) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CodexImageToolRow, {
911
998
  block,
999
+ gallery,
912
1000
  ...props,
913
1001
  presentation: "output"
914
1002
  }, block.toolCallId))
@@ -1366,6 +1454,8 @@ window.__ModuleLoader__.load({
1366
1454
  //#endregion
1367
1455
  //#region src/client-locales.js
1368
1456
  const zh = {
1457
+ openSubscriptionSettings: "订阅设置",
1458
+ projectHomepage: "GitHub 项目主页",
1369
1459
  voiceNativeCaptureConfirm: "允许本次通话使用此电脑的麦克风和扬声器?挂断或离开会话后会停止收音。",
1370
1460
  voiceMediaHint: "窗口不支持 WebRTC 时,可在浏览器中继续同一会话。音色试听不受影响,仍使用当前订阅,无需 API Key。",
1371
1461
  voiceBrowserContinue: "在浏览器继续此会话",
@@ -1742,6 +1832,7 @@ window.__ModuleLoader__.load({
1742
1832
  forecastCompactPending: "待估",
1743
1833
  forecastCompactChanging: "重估",
1744
1834
  forecastCompactStale: "待更新",
1835
+ imageMore: "更多操作",
1745
1836
  imageEditShort: "继续编辑",
1746
1837
  forecastResolution: "暂时估不准:读数变化不足以确定速度",
1747
1838
  forecastChanging: "使用强度变化,正在重新估计",
@@ -1887,12 +1978,22 @@ window.__ModuleLoader__.load({
1887
1978
  imageEditReferenceGuide: "本次编辑的干净源图为「{sourceName}」,编号定位参考图为「{referenceName}」。坐标以图片左上角为原点,x 向右、y 向下,百分比相对于整张图片。请查看这两张图片,将它们同时作为编辑工具的参考图,并在工具提示词中完整保留下方编号、位置和修改要求。只修改源图中对应位置的内容;定位参考图上的编号、圆点和引线仅用于定位,不得绘入最终结果。若无法读取两张图片或确定位置,请说明问题,不要猜测或忽略标注。",
1888
1979
  nav: "Codex 订阅",
1889
1980
  title: "Codex 订阅",
1890
- connected: "已登录",
1981
+ savedAccounts: "已登记账号",
1891
1982
  disconnected: "未登录",
1892
1983
  accountLoading: "正在读取账户状态…",
1984
+ accountVerifying: "正在验证…",
1985
+ accountVerified: "认证有效",
1986
+ accountRenewSignIn: "登录已失效",
1987
+ accountUnverified: "暂时无法确认认证状态",
1988
+ renewAccount: "重新登录",
1989
+ renewAccountHint: "请在浏览器中使用原来的 ChatGPT 账号和工作区完成授权。",
1990
+ failed_account_mismatch: "无法确认是原来的 ChatGPT 账号和工作区。请切回原账号后重试。",
1893
1991
  browserLogin: "浏览器登录",
1894
1992
  deviceLogin: "设备代码登录",
1895
1993
  logout: "退出登录",
1994
+ accessDenied: "ChatGPT 拒绝了这次请求(HTTP 403)。请检查账号访问权限,或联系 OpenAI 支持;重新登录不一定能解决。",
1995
+ deviceLimit: "ChatGPT 不允许在这台设备使用此付费账号。请手动选择你拥有的其他获准账号,或联系 OpenAI 支持。退出登录或重置额度不会解除限制。",
1996
+ purchaseLimit: "此卡或设备关联的订阅过多,ChatGPT 已阻止本次购买。如有误,请联系 OpenAI 支持。",
1896
1997
  addAccount: "添加账号",
1897
1998
  switchAccount: "切换",
1898
1999
  removeAccount: "移除",
@@ -2025,8 +2126,6 @@ window.__ModuleLoader__.load({
2025
2126
  resetFailed: "无法使用额度重置。",
2026
2127
  accountQuotaLeft: "{label}剩余 {value}%",
2027
2128
  accountQuotaResets: "{value} 重置",
2028
- accountQuotaLoading: "正在读取额度…",
2029
- accountQuotaError: "暂时读不到这个账号的额度",
2030
2129
  accountQuotaNone: "没有额度窗口信息",
2031
2130
  resetRenewLogin: "登录状态已失效,请重新登录。",
2032
2131
  resetBlocked: "ChatGPT 的网络防护拦截了这次请求(HTTP 403),登录状态没有问题。请稍后再试,或检查网络、代理或 VPN。",
@@ -2284,6 +2383,8 @@ window.__ModuleLoader__.load({
2284
2383
  imageRemoveAnnotation: "删除标注"
2285
2384
  };
2286
2385
  const en = {
2386
+ openSubscriptionSettings: "Subscription settings",
2387
+ projectHomepage: "GitHub project",
2287
2388
  voiceNativeCaptureConfirm: "Use this computer’s microphone and speakers for this call? Capture stops when you hang up or leave the conversation.",
2288
2389
  voiceMediaHint: "If this window does not support WebRTC, continue the same conversation in a browser. Voice samples remain available. Your existing subscription is used; no API key is needed.",
2289
2390
  voiceBrowserContinue: "Continue this conversation in a browser",
@@ -2660,6 +2761,7 @@ window.__ModuleLoader__.load({
2660
2761
  forecastCompactPending: "Estimating",
2661
2762
  forecastCompactChanging: "Re-estimating",
2662
2763
  forecastCompactStale: "Stale",
2764
+ imageMore: "More actions",
2663
2765
  imageEditShort: "Edit",
2664
2766
  forecastResolution: "Not enough change to estimate the rate yet",
2665
2767
  forecastChanging: "Usage intensity changed; estimating again",
@@ -2805,12 +2907,22 @@ window.__ModuleLoader__.load({
2805
2907
  imageEditReferenceGuide: "The clean source for this edit is \"{sourceName}\"; \"{referenceName}\" is the numbered location reference. Coordinates start at the top-left, x increases rightward and y downward; percentages refer to the whole image. Inspect both images and pass both as references to the image-editing tool. Preserve every number, position and requested change below in the tool prompt. Edit the corresponding content in the clean source; numbers, dots and leader lines on the location reference are guidance only and must not appear in the final result. If either image cannot be read or a location is unclear, explain the problem instead of guessing or ignoring annotations.",
2806
2908
  nav: "Codex",
2807
2909
  title: "Codex subscription",
2808
- connected: "Signed in",
2910
+ savedAccounts: "Saved accounts",
2809
2911
  disconnected: "Not signed in",
2810
2912
  accountLoading: "Reading account status…",
2913
+ accountVerifying: "Checking sign-in…",
2914
+ accountVerified: "Sign-in verified",
2915
+ accountRenewSignIn: "Sign-in expired",
2916
+ accountUnverified: "Could not verify sign-in",
2917
+ renewAccount: "Sign in again",
2918
+ renewAccountHint: "Complete authorization in your browser with the original ChatGPT account and workspace.",
2919
+ failed_account_mismatch: "Could not verify the same ChatGPT account and workspace. Switch to the original account and try again.",
2811
2920
  browserLogin: "Browser sign-in",
2812
2921
  deviceLogin: "Device-code sign-in",
2813
2922
  logout: "Sign out",
2923
+ accessDenied: "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it.",
2924
+ deviceLimit: "ChatGPT does not allow this paid account on this device. Manually select another permitted account you own or contact OpenAI Support. Signing out or resetting usage does not clear the restriction.",
2925
+ purchaseLimit: "ChatGPT blocked this purchase because too many subscriptions are associated with this card or device. Contact OpenAI Support if this is unexpected.",
2814
2926
  addAccount: "Add account",
2815
2927
  switchAccount: "Switch",
2816
2928
  removeAccount: "Remove",
@@ -2943,8 +3055,6 @@ window.__ModuleLoader__.load({
2943
3055
  resetFailed: "Could not use the quota reset.",
2944
3056
  accountQuotaLeft: "{label} {value}% left",
2945
3057
  accountQuotaResets: "resets {value}",
2946
- accountQuotaLoading: "Reading quota…",
2947
- accountQuotaError: "The quota of this account could not be read right now",
2948
3058
  accountQuotaNone: "No quota window reported",
2949
3059
  resetRenewLogin: "Your sign-in expired. Sign in again.",
2950
3060
  resetBlocked: "ChatGPT network protection blocked this request (HTTP 403). Your sign-in is fine; try again later or check your network, proxy or VPN.",
@@ -3193,7 +3303,7 @@ window.__ModuleLoader__.load({
3193
3303
  imagePrevious: "Previous image",
3194
3304
  imageNext: "Next image",
3195
3305
  imageZoomHint: "Wheel to zoom · drag to pan · double-click for 100%",
3196
- imageActual: "100%",
3306
+ imageActual: "Actual size",
3197
3307
  imageEditDefault: "Edit this image.",
3198
3308
  imageRegionNotes: "Region changes:",
3199
3309
  imageEdit: "Continue editing in composer",
@@ -3204,6 +3314,10 @@ window.__ModuleLoader__.load({
3204
3314
  //#endregion
3205
3315
  //#region src/client-styles.js
3206
3316
  const STYLE = `
3317
+ .codexSubscription[data-embedded=true]{max-width:960px}
3318
+ .codexQuotaSettingsLink{display:block;width:100%;margin-top:8px;padding:8px 0 0;border:0;border-top:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-link,var(--dsw-alias-label-primary));font:inherit;text-align:start;cursor:pointer}
3319
+ .codexQuotaSettingsLink:hover{text-decoration:underline}
3320
+ .codexQuotaSettingsLink:focus-visible{outline:2px solid var(--dsw-alias-border-l3);outline-offset:3px;border-radius:2px}
3207
3321
  .codexSubscriptionAdvancedPreferences{display:flex;flex-direction:column;gap:10px}
3208
3322
  .codexSubscriptionAdvancedPreferences[data-others-off=true]>[data-governed=true]{opacity:.55;transition:opacity .15s}
3209
3323
  .codexSubscriptionSearchChoices.codexSubscriptionQuotaModes{display:flex;flex:0 0 auto;gap:0;grid-template-columns:none}
@@ -3285,7 +3399,6 @@ window.__ModuleLoader__.load({
3285
3399
  .codexSubscriptionAccount:last-child{border-bottom:0}
3286
3400
  .codexSubscriptionAccountMain{display:flex;flex-direction:column;gap:2px;padding:6px 0;min-width:0}
3287
3401
  .codexSubscriptionAccountQuota{display:flex;flex-wrap:wrap;gap:2px 12px;font-size:12px;color:var(--dsw-alias-text-l2)}
3288
- .codexSubscriptionAccountQuota[data-state=error]{color:var(--dsw-alias-text-danger,#c0392b)}
3289
3402
  .codexSubscriptionAccount[data-active=true] .codexSubscriptionEmail,.codexSubscriptionAccount[data-active=true]>span{font-weight:600}
3290
3403
  .codexSubscriptionEmail{max-width:100%;overflow:hidden;padding:2px 4px;border:0;border-radius:5px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}
3291
3404
  .codexSubscriptionEmail:hover{background:var(--dsw-alias-interactive-bg-hover)}
@@ -3654,8 +3767,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
3654
3767
  .codexSubscriptionLimit[data-pace=true] progress::-moz-progress-bar{background:var(--dsw-alias-state-warning-primary,#f5a300)}
3655
3768
  .codexDiagResult{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 0;border-top:1px solid var(--dsw-alias-border-l2)}
3656
3769
  .codexDiagBadge{font-size:13px;line-height:20px;font-weight:500;color:var(--dsw-alias-label-primary)}
3657
- .codexDiagResult[data-state=ok] .codexDiagBadge::before,.codexDiagResult[data-state=attention] .codexDiagBadge::before{content:'';display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:8px;background:var(--dsw-alias-state-success-primary,#1a9d58)}
3658
- .codexDiagResult[data-state=attention] .codexDiagBadge::before{background:var(--dsw-alias-state-warning-primary,#f5a300)}
3770
+ .codexDiagResult[data-state=attention] .codexDiagBadge::before{content:'';display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:8px;background:var(--dsw-alias-state-warning-primary,#f5a300)}
3659
3771
  .codexDiagTime{font-size:12px;color:var(--dsw-alias-label-tertiary)}
3660
3772
  .codexDiagFindings{list-style:none;margin:0;padding:0 0 6px;display:flex;flex-direction:column;gap:8px}
3661
3773
  .codexDiagFindings>li{display:flex;flex-direction:column;gap:2px;font-size:13px;line-height:20px}
@@ -3869,6 +3981,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
3869
3981
  height: boundedNumber(item.height, void 0),
3870
3982
  bytes: boundedNumber(item.bytes, void 0),
3871
3983
  download: downloadOf(item.download),
3984
+ reload: typeof item.reload === "function" ? item.reload : void 0,
3872
3985
  actions: actionsOf(item.actions)
3873
3986
  }];
3874
3987
  });
@@ -3879,6 +3992,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
3879
3992
  index: Math.max(0, Math.min(items.length - 1, requestedIndex)),
3880
3993
  opener: typeof HTMLElement !== "undefined" && request?.opener instanceof HTMLElement ? request.opener : void 0,
3881
3994
  source: typeof request?.source === "string" ? request.source : "dsh-codex-subscription",
3995
+ scope: typeof request?.scope === "string" ? request.scope : "",
3882
3996
  annotations: request?.annotations !== false
3883
3997
  };
3884
3998
  }
@@ -3894,6 +4008,30 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
3894
4008
  #revision = 0;
3895
4009
  #snapshot;
3896
4010
  #annotationsByImage = /* @__PURE__ */ new Map();
4011
+ #operations = /* @__PURE__ */ new Set();
4012
+ async invoke(action, context = {}, revision = this.#snapshot?.revision) {
4013
+ if (!this.#snapshot || this.#snapshot.revision !== revision) throw new Error("Image preview changed");
4014
+ this.#cancelOperations();
4015
+ const controller = new AbortController();
4016
+ this.#operations.add(controller);
4017
+ try {
4018
+ const value = await action.onInvoke({
4019
+ ...context,
4020
+ signal: controller.signal
4021
+ });
4022
+ controller.signal.throwIfAborted();
4023
+ return value;
4024
+ } finally {
4025
+ this.#operations.delete(controller);
4026
+ }
4027
+ }
4028
+ #cancelOperations() {
4029
+ for (const controller of this.#operations) controller.abort();
4030
+ this.#operations.clear();
4031
+ }
4032
+ cancelPending() {
4033
+ this.#cancelOperations();
4034
+ }
3897
4035
  constructor() {
3898
4036
  this.subscribe = (listener) => {
3899
4037
  this.#listeners.add(listener);
@@ -3902,16 +4040,25 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
3902
4040
  };
3903
4041
  };
3904
4042
  this.getSnapshot = () => this.#snapshot;
3905
- this.getAnnotationsSnapshot = () => Object.fromEntries([...this.#annotationsByImage].map(([id, annotations]) => [id, copyAnnotations(annotations)]));
4043
+ this.getAnnotationsSnapshot = () => {
4044
+ const prefix = `${this.#snapshot?.scope ?? ""}\0`;
4045
+ return Object.fromEntries([...this.#annotationsByImage].filter(([id]) => id.startsWith(prefix)).map(([id, annotations]) => [id.slice(prefix.length), copyAnnotations(annotations)]));
4046
+ };
3906
4047
  }
3907
4048
  setAnnotations(imageId, annotations) {
3908
4049
  if (typeof imageId !== "string" || imageId === "" || !Array.isArray(annotations)) return;
4050
+ imageId = `${this.#snapshot?.scope ?? ""}\0${imageId}`;
3909
4051
  if (annotations.length === 0) this.#annotationsByImage.delete(imageId);
3910
- else this.#annotationsByImage.set(imageId, copyAnnotations(annotations));
4052
+ else {
4053
+ this.#annotationsByImage.delete(imageId);
4054
+ this.#annotationsByImage.set(imageId, copyAnnotations(annotations));
4055
+ while (this.#annotationsByImage.size > 128) this.#annotationsByImage.delete(this.#annotationsByImage.keys().next().value);
4056
+ }
3911
4057
  }
3912
4058
  open(request) {
3913
4059
  const normalized = normalizeSubscriptionViewerRequest(request);
3914
4060
  if (normalized === void 0) return false;
4061
+ this.#cancelOperations();
3915
4062
  this.#revision += 1;
3916
4063
  this.#snapshot = {
3917
4064
  ...normalized,
@@ -3922,6 +4069,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
3922
4069
  }
3923
4070
  close() {
3924
4071
  if (this.#snapshot === void 0) return;
4072
+ this.#cancelOperations();
3925
4073
  const opener = this.#snapshot.opener;
3926
4074
  this.#snapshot = void 0;
3927
4075
  this.#emit();
@@ -5045,9 +5193,32 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
5045
5193
  });
5046
5194
  }
5047
5195
  //#endregion
5196
+ //#region src/http-failure.js
5197
+ const SIGN_IN_RENEW = "ChatGPT sign-in needs to be renewed";
5198
+ const ACCESS_DENIED = "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it.";
5199
+ const DEVICE_LIMIT = "ChatGPT does not allow this paid account on this device. Use another permitted account you own or contact OpenAI Support. Signing out or resetting usage does not clear this restriction.";
5200
+ const PURCHASE_LIMIT = "ChatGPT blocked this purchase because too many subscriptions are associated with this card or device. Contact OpenAI Support if this is unexpected.";
5201
+ const PUBLIC_ACCESS_MESSAGES = /* @__PURE__ */ new Set([
5202
+ ACCESS_DENIED,
5203
+ DEVICE_LIMIT,
5204
+ PURCHASE_LIMIT
5205
+ ]);
5206
+ const isAccessFailureMessage = (message) => PUBLIC_ACCESS_MESSAGES.has(message);
5207
+ //#endregion
5048
5208
  //#region src/client-shared.js
5209
+ const ACCESS_FAILURE_KEYS = /* @__PURE__ */ new Map([
5210
+ [ACCESS_DENIED, "accessDenied"],
5211
+ [DEVICE_LIMIT, "deviceLimit"],
5212
+ [PURCHASE_LIMIT, "purchaseLimit"],
5213
+ [SIGN_IN_RENEW, "resetRenewLogin"]
5214
+ ]);
5215
+ const accessFailureText = (message, t) => {
5216
+ const key = ACCESS_FAILURE_KEYS.get(message);
5217
+ return key === void 0 ? message : t(key);
5218
+ };
5049
5219
  const NS = "settings.codexSubscription";
5050
- const SUPPORT_ISSUE_URL = "https://github.com/WSL043/dsh-codex-subscription/issues/new?template=install-problem.yml";
5220
+ const PROJECT_URL = "https://github.com/WSL043/dsh-codex-subscription";
5221
+ const SUPPORT_ISSUE_URL = `${PROJECT_URL}/issues/new?template=install-problem.yml`;
5051
5222
  const QUICK_QUOTA_REFRESH_EVENT = "dsh-codex-subscription:refresh-quick-quota";
5052
5223
  const accountStatusErrorText = (error, t) => {
5053
5224
  const key = {
@@ -5130,7 +5301,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
5130
5301
  }
5131
5302
  //#endregion
5132
5303
  //#region src/version.js
5133
- const PACKAGE_VERSION = "3.2.2";
5304
+ const PACKAGE_VERSION = "3.2.4";
5134
5305
  //#endregion
5135
5306
  //#region src/client-recovery.js
5136
5307
  async function recoveryCall(rpc, endpoint, payload = {}, timeoutMs = 1e4) {
@@ -5348,7 +5519,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
5348
5519
  }
5349
5520
  //#endregion
5350
5521
  //#region src/client-composer-quota.jsx
5351
- function CodexComposerQuota({ preference, rpc, t, directory }) {
5522
+ function CodexComposerQuota({ preference, rpc, t, directory, openSettings }) {
5352
5523
  const preferenceSnapshot = usePreferenceSnapshot(preference);
5353
5524
  const current = (0, react.useSyncExternalStore)((listener) => directory.subscribe(listener), () => directory.getSnapshot()).current;
5354
5525
  const quotaEnabled = preferenceSnapshot.status === "ready" && preferenceSnapshot.quickQuotaMode !== "off" && current?.provider === "openai-codex";
@@ -5443,7 +5614,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
5443
5614
  preferenceSnapshot.quickQuotaMode !== "bar" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: `${percent(quota.remainingPercent)}%` }) : null
5444
5615
  ]
5445
5616
  }, `${quota.windowSeconds}-${index}`))
5446
- }), visible ? (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
5617
+ }), visible ? (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
5447
5618
  ref: panel,
5448
5619
  id,
5449
5620
  role: "dialog",
@@ -5456,7 +5627,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
5456
5627
  ...position,
5457
5628
  visibility: position ? "visible" : "hidden"
5458
5629
  },
5459
- children: quotas.map((quota, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
5630
+ children: [quotas.map((quota, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
5460
5631
  className: "codexQuotaDetail",
5461
5632
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
5462
5633
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: windowLabel(quota.windowSeconds, t) }),
@@ -5466,7 +5637,15 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
5466
5637
  children: shortReset(quota, t)
5467
5638
  })
5468
5639
  ] }), forecastMode ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: formatQuotaForecast(quota.forecast, t, quota) }) : null]
5469
- }, `${quota.windowSeconds}-${index}`))
5640
+ }, `${quota.windowSeconds}-${index}`)), openSettings ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
5641
+ type: "button",
5642
+ className: "codexQuotaSettingsLink",
5643
+ onClick: () => {
5644
+ dismiss();
5645
+ openSettings();
5646
+ },
5647
+ children: t("openSubscriptionSettings")
5648
+ }) : null]
5470
5649
  }), document.body) : null] });
5471
5650
  }
5472
5651
  function shortWindow(seconds, t) {
@@ -7528,6 +7707,7 @@ void main(){
7528
7707
  //#endregion
7529
7708
  //#region src/capability-preferences.jsx
7530
7709
  function CapabilityPreferences({ preference, t, section, disabled = false }) {
7710
+ const radioId = (0, react.useId)();
7531
7711
  const snapshot = (0, react.useSyncExternalStore)(preference.subscribe, preference.getSnapshot);
7532
7712
  const [domains, setDomains] = (0, react.useState)("");
7533
7713
  const [invalid, setInvalid] = (0, react.useState)(false);
@@ -7544,7 +7724,7 @@ void main(){
7544
7724
  className: "codexSubscriptionQuotaMode",
7545
7725
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
7546
7726
  type: "radio",
7547
- name: `codex-${field}`,
7727
+ name: `${radioId}-codex-${field}`,
7548
7728
  checked: snapshot[field] === value,
7549
7729
  disabled: !snapshot.writable || disabled,
7550
7730
  onChange: () => {
@@ -10466,7 +10646,7 @@ void main(){
10466
10646
  capability: areas[e.area],
10467
10647
  action: e.area,
10468
10648
  source: "network",
10469
- status: e.status === "ok" ? "completed" : "failed",
10649
+ status: e.status === "ok" ? "completed" : e.status,
10470
10650
  observedAt: e.observedAt
10471
10651
  }))].filter((e) => Number.isSafeInteger(e.observedAt) && now >= e.observedAt && now - e.observedAt <= 9e5).sort((a, b) => a.observedAt - b.observedAt);
10472
10652
  }
@@ -10624,6 +10804,7 @@ void main(){
10624
10804
  error: ["error"]
10625
10805
  };
10626
10806
  function DiagnosticsCard({ rpc, t, diagnostics }) {
10807
+ const radioId = (0, react.useId)();
10627
10808
  const [report, setReport] = (0, react.useState)();
10628
10809
  const [busy, setBusy] = (0, react.useState)(false);
10629
10810
  const [copied, setCopied] = (0, react.useState)(false);
@@ -10718,7 +10899,7 @@ void main(){
10718
10899
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10719
10900
  className: "codexDiagResult",
10720
10901
  role: "status",
10721
- "data-state": attention.length ? "attention" : "ok",
10902
+ "data-state": attention.length ? "attention" : void 0,
10722
10903
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10723
10904
  className: "codexDiagBadge",
10724
10905
  children: attention.length ? t("diagnosticsAttention").replace("{count}", String(attention.length)) : t("diagnosticsNoRecordedFailure")
@@ -10758,7 +10939,7 @@ void main(){
10758
10939
  className: "codexSubscriptionQuotaMode",
10759
10940
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
10760
10941
  type: "radio",
10761
- name: "codex-log-level",
10942
+ name: `${radioId}-codex-log-level`,
10762
10943
  checked: level === value,
10763
10944
  onChange: () => {
10764
10945
  setLevel(value);
@@ -10988,13 +11169,14 @@ void main(){
10988
11169
  //#endregion
10989
11170
  //#region src/client-preferences.jsx
10990
11171
  function QuickQuotaPreference({ preference, t }) {
11172
+ const radioId = (0, react.useId)();
10991
11173
  const snapshot = usePreferenceSnapshot(preference);
10992
11174
  const writable = snapshot.status === "ready" && snapshot.writable === true;
10993
11175
  const choice = (value, label) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
10994
11176
  className: "codexSubscriptionQuotaMode",
10995
11177
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
10996
11178
  type: "radio",
10997
- name: "codex-subscription-quota-mode",
11179
+ name: `${radioId}-codex-subscription-quota-mode`,
10998
11180
  checked: snapshot.quickQuotaMode === value,
10999
11181
  disabled: !writable,
11000
11182
  onChange: () => {
@@ -11051,13 +11233,14 @@ void main(){
11051
11233
  });
11052
11234
  }
11053
11235
  function SearchProviderPreference({ preference, t }) {
11236
+ const radioId = (0, react.useId)();
11054
11237
  const snapshot = usePreferenceSnapshot(preference);
11055
11238
  const writable = snapshot.status === "ready" && snapshot.writable === true;
11056
11239
  const choice = (value, label) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
11057
11240
  className: "codexSubscriptionQuotaMode",
11058
11241
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11059
11242
  type: "radio",
11060
- name: "codex-subscription-search-provider",
11243
+ name: `${radioId}-codex-subscription-search-provider`,
11061
11244
  checked: snapshot.searchProvider === value,
11062
11245
  disabled: !writable,
11063
11246
  onChange: () => {
@@ -11107,7 +11290,7 @@ void main(){
11107
11290
  className: "codexSubscriptionQuotaMode",
11108
11291
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11109
11292
  type: "radio",
11110
- name: "codex-subscription-fetch-provider",
11293
+ name: `${radioId}-codex-subscription-fetch-provider`,
11111
11294
  checked: snapshot.fetchProvider === value,
11112
11295
  disabled: !writable || value === "codex" && !snapshot.fetchRoutingAvailable,
11113
11296
  onChange: () => {
@@ -11126,6 +11309,7 @@ void main(){
11126
11309
  });
11127
11310
  }
11128
11311
  function InputImageDetailPreference({ preference, t }) {
11312
+ const radioId = (0, react.useId)();
11129
11313
  const snapshot = usePreferenceSnapshot(preference);
11130
11314
  const writable = snapshot.status === "ready" && snapshot.writable === true;
11131
11315
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -11146,7 +11330,7 @@ void main(){
11146
11330
  className: "codexSubscriptionQuotaMode",
11147
11331
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11148
11332
  type: "radio",
11149
- name: "codex-input-image-detail",
11333
+ name: `${radioId}-codex-input-image-detail`,
11150
11334
  checked: snapshot.inputImageDetail === value,
11151
11335
  disabled: !writable,
11152
11336
  onChange: () => {
@@ -11158,6 +11342,7 @@ void main(){
11158
11342
  });
11159
11343
  }
11160
11344
  function ReasoningSummaryPreference({ preference, t }) {
11345
+ const radioId = (0, react.useId)();
11161
11346
  const snapshot = usePreferenceSnapshot(preference);
11162
11347
  const writable = snapshot.status === "ready" && snapshot.writable === true;
11163
11348
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -11178,7 +11363,7 @@ void main(){
11178
11363
  className: "codexSubscriptionQuotaMode",
11179
11364
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11180
11365
  type: "radio",
11181
- name: "codex-reasoning-summary",
11366
+ name: `${radioId}-codex-reasoning-summary`,
11182
11367
  checked: snapshot.reasoningSummary === value,
11183
11368
  disabled: !writable,
11184
11369
  onChange: () => {
@@ -11238,6 +11423,7 @@ void main(){
11238
11423
  });
11239
11424
  }
11240
11425
  function RetryPolicyPreference({ preference, t }) {
11426
+ const radioId = (0, react.useId)();
11241
11427
  const snapshot = usePreferenceSnapshot(preference);
11242
11428
  const writable = snapshot.status === "ready" && snapshot.writable === true;
11243
11429
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -11258,7 +11444,7 @@ void main(){
11258
11444
  className: "codexSubscriptionQuotaMode",
11259
11445
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11260
11446
  type: "radio",
11261
- name: "codex-retry-policy",
11447
+ name: `${radioId}-codex-retry-policy`,
11262
11448
  checked: snapshot.retryPolicy === value,
11263
11449
  disabled: !writable,
11264
11450
  onChange: () => {
@@ -11270,6 +11456,7 @@ void main(){
11270
11456
  });
11271
11457
  }
11272
11458
  function ConnectorsPreference({ preference, t }) {
11459
+ const radioId = (0, react.useId)();
11273
11460
  const snapshot = usePreferenceSnapshot(preference);
11274
11461
  const writable = snapshot.status === "ready" && snapshot.writable === true;
11275
11462
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -11292,7 +11479,7 @@ void main(){
11292
11479
  className: "codexSubscriptionQuotaMode",
11293
11480
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11294
11481
  type: "radio",
11295
- name: "codex-connectors",
11482
+ name: `${radioId}-codex-connectors`,
11296
11483
  checked: snapshot.connectors === value,
11297
11484
  disabled: !writable,
11298
11485
  onChange: () => {
@@ -11311,6 +11498,7 @@ void main(){
11311
11498
  });
11312
11499
  }
11313
11500
  function StreamIdleTimeoutPreference({ preference, t }) {
11501
+ const radioId = (0, react.useId)();
11314
11502
  const snapshot = usePreferenceSnapshot(preference);
11315
11503
  const writable = snapshot.status === "ready" && snapshot.writable === true;
11316
11504
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -11331,7 +11519,7 @@ void main(){
11331
11519
  className: "codexSubscriptionQuotaMode",
11332
11520
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11333
11521
  type: "radio",
11334
- name: "codex-stream-idle-timeout",
11522
+ name: `${radioId}-codex-stream-idle-timeout`,
11335
11523
  checked: snapshot.streamIdleTimeoutMinutes === value,
11336
11524
  disabled: !writable,
11337
11525
  onChange: () => {
@@ -11747,6 +11935,7 @@ void main(){
11747
11935
  });
11748
11936
  }
11749
11937
  function OutputVerbosityPreference({ preference, t }) {
11938
+ const radioId = (0, react.useId)();
11750
11939
  const snapshot = usePreferenceSnapshot(preference);
11751
11940
  const writable = ready(snapshot);
11752
11941
  const values = [
@@ -11778,7 +11967,7 @@ void main(){
11778
11967
  className: "codexSubscriptionQuotaMode",
11779
11968
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11780
11969
  type: "radio",
11781
- name: "codex-output-verbosity",
11970
+ name: `${radioId}-codex-output-verbosity`,
11782
11971
  checked: snapshot.outputVerbosity === value,
11783
11972
  disabled: !writable,
11784
11973
  onChange: () => {
@@ -11790,6 +11979,7 @@ void main(){
11790
11979
  });
11791
11980
  }
11792
11981
  function Radios({ snapshot, preference, field, values, label, name, text, disabled, disabledValues = [] }) {
11982
+ const radioId = (0, react.useId)();
11793
11983
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11794
11984
  className: "codexSubscriptionQuotaModes",
11795
11985
  role: "radiogroup",
@@ -11799,7 +11989,7 @@ void main(){
11799
11989
  className: "codexSubscriptionQuotaMode",
11800
11990
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
11801
11991
  type: "radio",
11802
- name,
11992
+ name: `${radioId}-${name}`,
11803
11993
  checked: snapshot[field] === value,
11804
11994
  disabled: disabled || !snapshot.writable || disabledValues.includes(value),
11805
11995
  onChange: () => {
@@ -12173,6 +12363,7 @@ void main(){
12173
12363
  async function readLoginProgress({ flow, readFlow, readAccount }) {
12174
12364
  try {
12175
12365
  const nextFlow = await readFlow();
12366
+ if (nextFlow.phase === "failed" && isAccessFailureMessage(nextFlow.error)) return { flow: nextFlow };
12176
12367
  if (nextFlow.phase === "failed") try {
12177
12368
  const account = await readAccount();
12178
12369
  if (account?.authenticated === true) return {
@@ -12217,7 +12408,7 @@ void main(){
12217
12408
  minute: "2-digit"
12218
12409
  });
12219
12410
  /** Quota of every signed-in account (read-only; the active account does not change). */
12220
- function useAccountQuotas(rpc, ids, active = true) {
12411
+ function useAccountQuotas(rpc, ids, active = true, revision = 0) {
12221
12412
  const [entries, setEntries] = (0, react.useState)({});
12222
12413
  const [busy, setBusy] = (0, react.useState)(false);
12223
12414
  const request = (0, react.useRef)(0);
@@ -12226,10 +12417,7 @@ void main(){
12226
12417
  activeRef.current = active;
12227
12418
  const key = ids.join(",");
12228
12419
  const load = (force) => {
12229
- if (ids.length < 2) {
12230
- setEntries({});
12231
- return;
12232
- }
12420
+ if (ids.length === 0) return;
12233
12421
  if (!activeRef.current || document.visibilityState === "hidden") return;
12234
12422
  if (flight.current) {
12235
12423
  const current = flight.current;
@@ -12237,6 +12425,7 @@ void main(){
12237
12425
  return current.promise;
12238
12426
  }
12239
12427
  const id = ++request.current;
12428
+ if (force) setEntries({});
12240
12429
  setBusy(true);
12241
12430
  const current = {
12242
12431
  id,
@@ -12257,17 +12446,19 @@ void main(){
12257
12446
  return current.promise;
12258
12447
  };
12259
12448
  (0, react.useEffect)(() => {
12260
- if (ids.length < 2) {
12261
- setEntries({});
12262
- setBusy(false);
12263
- }
12449
+ setEntries({});
12450
+ setBusy(false);
12264
12451
  return () => {
12265
12452
  request.current += 1;
12266
12453
  flight.current = void 0;
12267
12454
  };
12268
- }, [key, rpc]);
12455
+ }, [
12456
+ key,
12457
+ revision,
12458
+ rpc
12459
+ ]);
12269
12460
  (0, react.useEffect)(() => {
12270
- if (ids.length < 2 || !active) return void 0;
12461
+ if (ids.length === 0 || !active) return void 0;
12271
12462
  let timer;
12272
12463
  const stop = () => {
12273
12464
  clearInterval(timer);
@@ -12277,7 +12468,7 @@ void main(){
12277
12468
  const wake = () => {
12278
12469
  stop();
12279
12470
  if (document.visibilityState === "hidden") return;
12280
- again();
12471
+ load(true);
12281
12472
  timer = setInterval(again, 6e4);
12282
12473
  };
12283
12474
  wake();
@@ -12290,6 +12481,7 @@ void main(){
12290
12481
  };
12291
12482
  }, [
12292
12483
  key,
12484
+ revision,
12293
12485
  active,
12294
12486
  rpc
12295
12487
  ]);
@@ -12299,27 +12491,43 @@ void main(){
12299
12491
  refresh: () => load(true)
12300
12492
  };
12301
12493
  }
12302
- function AccountQuota({ entry, loading, t }) {
12303
- if (entry === void 0) return loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
12304
- className: "codexSubscriptionAccountQuota",
12305
- children: t("accountQuotaLoading")
12306
- }) : null;
12307
- if (entry.error !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
12308
- className: "codexSubscriptionAccountQuota",
12309
- "data-state": "error",
12310
- children: entry.error === "ChatGPT sign-in needs to be renewed" ? t("resetRenewLogin") : t("accountQuotaError")
12494
+ function AccountQuota({ entry, loading, showQuota, t }) {
12495
+ const state = entry === void 0 ? loading ? "loading" : "unknown" : entry.error === "ChatGPT sign-in needs to be renewed" ? "disconnected" : entry.error !== void 0 || entry.usage === void 0 ? "unknown" : "connected";
12496
+ const label = {
12497
+ connected: "accountVerified",
12498
+ disconnected: "accountRenewSignIn",
12499
+ loading: "accountVerifying",
12500
+ unknown: "accountUnverified"
12501
+ }[state];
12502
+ const status = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
12503
+ className: "codexSubscriptionStatus",
12504
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
12505
+ className: "codexSubscriptionDot",
12506
+ "data-state": state,
12507
+ "aria-hidden": "true"
12508
+ }), t(label)]
12311
12509
  });
12312
- const windows = entry.usage?.rateLimits?.find((limit) => limit.id === "codex")?.windows ?? [];
12313
- if (windows.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
12510
+ if (entry?.error !== void 0 && state !== "disconnected") {
12511
+ const message = accessFailureText(entry.error, t);
12512
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", {
12513
+ className: "codexSubscriptionAccountQuota",
12514
+ role: "status",
12515
+ children: [status, message !== entry.error ? message : null]
12516
+ });
12517
+ }
12518
+ if (state !== "connected" || !showQuota) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
12314
12519
  className: "codexSubscriptionAccountQuota",
12315
- children: t("accountQuotaNone")
12520
+ role: "status",
12521
+ children: status
12316
12522
  });
12317
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
12523
+ const windows = entry.usage?.rateLimits?.find((limit) => limit.id === "codex")?.windows ?? [];
12524
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", {
12318
12525
  className: "codexSubscriptionAccountQuota",
12319
- children: windows.map((window) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [fill(t("accountQuotaLeft"), {
12526
+ role: "status",
12527
+ children: [status, windows.length === 0 ? t("accountQuotaNone") : windows.map((window) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [fill(t("accountQuotaLeft"), {
12320
12528
  label: windowLabel(window.windowSeconds, t),
12321
12529
  value: percent(window.remainingPercent)
12322
- }), window.resetsAt === void 0 ? "" : ` · ${fill(t("accountQuotaResets"), { value: when(window.resetsAt) })}`] }, window.windowSeconds))
12530
+ }), window.resetsAt === void 0 ? "" : ` · ${fill(t("accountQuotaResets"), { value: when(window.resetsAt) })}`] }, window.windowSeconds))]
12323
12531
  });
12324
12532
  }
12325
12533
  //#endregion
@@ -12328,7 +12536,8 @@ void main(){
12328
12536
  "account-claim",
12329
12537
  "network",
12330
12538
  "token-exchange",
12331
- "callback"
12539
+ "callback",
12540
+ "account-mismatch"
12332
12541
  ];
12333
12542
  function AccountEmail({ candidate, fallback, t, emailVisible, onClick }) {
12334
12543
  if (typeof candidate?.email !== "string" || candidate.email.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -12345,11 +12554,13 @@ void main(){
12345
12554
  });
12346
12555
  }
12347
12556
  const signedInIds = (account) => account?.authenticated === true ? (account.accounts ?? []).map((candidate) => candidate.id).filter((id) => typeof id === "string") : [];
12348
- function AccountCard({ rpc, t, account, setAccount, onSignedOut, active = true }) {
12557
+ function AccountCard({ rpc, t, account, setAccount, onSignedOut, active = true, revision }) {
12349
12558
  const [flow, setFlow] = (0, react.useState)();
12350
12559
  const flowGeneration = (0, react.useRef)(0);
12351
12560
  const [manualCode, setManualCode] = (0, react.useState)("");
12352
12561
  const [adding, setAdding] = (0, react.useState)(false);
12562
+ const [renewId, setRenewId] = (0, react.useState)();
12563
+ const accountFlow = adding || renewId !== void 0;
12353
12564
  const [removeId, setRemoveId] = (0, react.useState)();
12354
12565
  const [confirmSignOut, setConfirmSignOut] = (0, react.useState)(false);
12355
12566
  const [emailVisible, setEmailVisible] = (0, react.useState)(false);
@@ -12358,7 +12569,7 @@ void main(){
12358
12569
  const [emailVisibilityKey, setEmailVisibilityKey] = (0, react.useState)(accountVisibilityKey);
12359
12570
  const [busy, setBusy] = (0, react.useState)(false);
12360
12571
  const [error, setError] = (0, react.useState)();
12361
- const quotas = useAccountQuotas(rpc, signedInIds(account), active);
12572
+ const quotas = useAccountQuotas(rpc, signedInIds(account), active, revision);
12362
12573
  const call = (endpoint, payload = {}) => recoveryCall(rpc, endpoint, payload);
12363
12574
  (0, react.useEffect)(() => {
12364
12575
  if (emailVisibilityKey === accountVisibilityKey) return;
@@ -12366,18 +12577,14 @@ void main(){
12366
12577
  setEmailVisibilityKey(accountVisibilityKey);
12367
12578
  }, [accountVisibilityKey, emailVisibilityKey]);
12368
12579
  (0, react.useEffect)(() => {
12369
- if (busy || flow?.id === void 0 || [
12370
- "authenticated",
12371
- "failed",
12372
- "cancelled"
12373
- ].includes(flow.phase)) return void 0;
12580
+ if (busy || flow?.id === void 0 || ["failed", "cancelled"].includes(flow.phase)) return void 0;
12374
12581
  let live = true;
12375
12582
  let reading = false;
12376
12583
  const generation = flowGeneration.current;
12377
12584
  const timer = window.setInterval(() => {
12378
12585
  if (reading) return;
12379
12586
  reading = true;
12380
- (adding ? call("login/status", { id: flow.id }).then(async (nextFlow) => ({
12587
+ (accountFlow ? call("login/status", { id: flow.id }).then(async (nextFlow) => ({
12381
12588
  flow: nextFlow,
12382
12589
  account: nextFlow.phase === "authenticated" ? await call("status") : void 0
12383
12590
  })) : readLoginProgress({
@@ -12392,6 +12599,8 @@ void main(){
12392
12599
  setAccount(next.account);
12393
12600
  onSignedOut();
12394
12601
  setAdding(false);
12602
+ setRenewId(void 0);
12603
+ setEmailVisible(false);
12395
12604
  setFlow(void 0);
12396
12605
  notifyQuickQuota();
12397
12606
  }
@@ -12408,19 +12617,18 @@ void main(){
12408
12617
  }, [
12409
12618
  flow?.id,
12410
12619
  flow?.phase,
12411
- adding,
12620
+ accountFlow,
12412
12621
  busy
12413
12622
  ]);
12414
- const begin = (method, label) => {
12623
+ const begin = (method, target = adding ? { label: `Account ${accounts.length + 1}` } : {}) => {
12415
12624
  flowGeneration.current += 1;
12416
12625
  setFlow(void 0);
12417
12626
  setBusy(true);
12418
12627
  setError(void 0);
12419
- const loginLabel = adding && label === void 0 ? `Account ${accounts.length + 1}` : label;
12420
12628
  call("login/start", {
12421
12629
  method,
12422
12630
  openExternal: true,
12423
- ...loginLabel === void 0 ? {} : { label: loginLabel }
12631
+ ...target
12424
12632
  }).then(setFlow).catch(() => setError(t("failed"))).finally(() => setBusy(false));
12425
12633
  };
12426
12634
  const cancel = () => {
@@ -12429,9 +12637,12 @@ void main(){
12429
12637
  setBusy(true);
12430
12638
  setError(void 0);
12431
12639
  call("login/cancel", { id: flow.id }).then((next) => {
12432
- setFlow(adding ? void 0 : next);
12433
- if (adding) setAdding(false);
12434
- if (adding) return void 0;
12640
+ setFlow(accountFlow ? void 0 : next);
12641
+ if (accountFlow) {
12642
+ setAdding(false);
12643
+ setRenewId(void 0);
12644
+ return;
12645
+ }
12435
12646
  return call("status").then((account) => {
12436
12647
  if (account.authenticated === true) {
12437
12648
  setAccount(account);
@@ -12504,20 +12715,106 @@ void main(){
12504
12715
  setEmailVisible((value) => emailVisibilityKey === accountVisibilityKey ? !value : true);
12505
12716
  };
12506
12717
  const emailVisibleForAccount = emailVisible && emailVisibilityKey === accountVisibilityKey;
12718
+ const loginContent = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
12719
+ flow?.phase === "waiting_device" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12720
+ className: "codexSubscriptionFlow",
12721
+ children: [
12722
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("deviceHint") }),
12723
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
12724
+ className: "codexSubscriptionCode",
12725
+ children: flow.deviceCode?.userCode
12726
+ }),
12727
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
12728
+ href: flow.deviceCode?.verificationUri,
12729
+ target: "_blank",
12730
+ rel: "noreferrer",
12731
+ children: t("openLogin")
12732
+ }),
12733
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("waiting") }),
12734
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12735
+ type: "button",
12736
+ variant: "outline",
12737
+ disabled: busy,
12738
+ onClick: cancel,
12739
+ children: t("cancel")
12740
+ })
12741
+ ]
12742
+ }) : null,
12743
+ flow?.phase === "waiting_input" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
12744
+ className: "codexSubscriptionFlow",
12745
+ onSubmit: submit,
12746
+ children: [
12747
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("manualCode") }),
12748
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Input, {
12749
+ className: "codexSubscriptionInput",
12750
+ value: manualCode,
12751
+ onChange: (event) => setManualCode(event.currentTarget.value),
12752
+ autoComplete: "off",
12753
+ spellCheck: false
12754
+ }),
12755
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12756
+ className: "codexSubscriptionActions",
12757
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12758
+ type: "submit",
12759
+ variant: "primary",
12760
+ disabled: busy || manualCode.trim() === "",
12761
+ children: t("submit")
12762
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12763
+ type: "button",
12764
+ variant: "outline",
12765
+ disabled: busy,
12766
+ onClick: cancel,
12767
+ children: t("cancel")
12768
+ })]
12769
+ })
12770
+ ]
12771
+ }) : null,
12772
+ renewId !== void 0 && busy && flow === void 0 || ["starting", "waiting_browser"].includes(flow?.phase) ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12773
+ className: "codexSubscriptionFlow",
12774
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
12775
+ role: "status",
12776
+ children: t(renewId === void 0 ? "waiting" : "renewAccountHint")
12777
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12778
+ className: "codexSubscriptionActions",
12779
+ children: [
12780
+ flow?.authUrl === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
12781
+ href: flow.authUrl,
12782
+ target: "_blank",
12783
+ rel: "noreferrer",
12784
+ children: t("openLogin")
12785
+ }),
12786
+ renewId === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12787
+ type: "button",
12788
+ variant: "outline",
12789
+ disabled: busy,
12790
+ onClick: () => begin("device_code", { renewId }),
12791
+ children: t("deviceLogin")
12792
+ }),
12793
+ flow === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12794
+ type: "button",
12795
+ variant: "outline",
12796
+ disabled: busy,
12797
+ onClick: cancel,
12798
+ children: t("cancel")
12799
+ })
12800
+ ]
12801
+ })]
12802
+ }) : null,
12803
+ flow?.phase === "failed" || error !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
12804
+ className: "codexSubscriptionError",
12805
+ role: "alert",
12806
+ children: error ?? (isAccessFailureMessage(flow?.error) ? accessFailureText(flow.error, t) : LOGIN_FAILURES.includes(flow?.failure) ? t(`failed_${flow.failure.replace("-", "_")}`) : t("failed"))
12807
+ }) : null
12808
+ ] });
12507
12809
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12508
12810
  className: "codexSubscriptionCard",
12509
12811
  children: [
12510
12812
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12511
12813
  className: "codexSubscriptionAccountRow",
12512
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12814
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
12513
12815
  className: "codexSubscriptionStatus",
12514
12816
  role: "status",
12515
- "aria-live": "polite",
12516
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
12517
- className: "codexSubscriptionDot",
12518
- "data-state": accountReady ? signedIn ? "connected" : "disconnected" : "loading",
12519
- "aria-hidden": "true"
12520
- }), accountReady ? signedIn ? t("connected") : t("disconnected") : t("accountLoading")]
12817
+ children: accountReady ? signedIn ? t("savedAccounts") : t("disconnected") : t("accountLoading")
12521
12818
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
12522
12819
  className: "codexSubscriptionActions",
12523
12820
  children: signedIn ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
@@ -12526,6 +12823,8 @@ void main(){
12526
12823
  disabled: busy || loginVisible,
12527
12824
  onClick: () => {
12528
12825
  setFlow(void 0);
12826
+ setError(void 0);
12827
+ setRenewId(void 0);
12529
12828
  setAdding(true);
12530
12829
  },
12531
12830
  children: t("addAccount")
@@ -12545,7 +12844,7 @@ void main(){
12545
12844
  variant: "outline",
12546
12845
  disabled: busy || loginVisible,
12547
12846
  onClick: () => setConfirmSignOut(true),
12548
- children: t("signOutAll")
12847
+ children: t(accounts.length > 1 ? "signOutAll" : "logout")
12549
12848
  })] }) : accountReady && (flow === void 0 || ["failed", "cancelled"].includes(flow.phase)) ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12550
12849
  type: "button",
12551
12850
  variant: "primary",
@@ -12563,51 +12862,67 @@ void main(){
12563
12862
  }),
12564
12863
  signedIn && accounts.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
12565
12864
  className: "codexSubscriptionAccounts",
12566
- children: accounts.map((candidate) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12567
- className: "codexSubscriptionAccount",
12568
- "data-active": candidate.active,
12569
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12570
- className: "codexSubscriptionAccountMain",
12571
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountEmail, {
12572
- candidate,
12573
- fallback: candidate.label,
12574
- t,
12575
- emailVisible: emailVisibleForAccount,
12576
- onClick: toggleEmail
12577
- }), accounts.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountQuota, {
12578
- entry: quotas.entries[candidate.id],
12579
- loading: quotas.busy,
12580
- t
12581
- }) : null]
12582
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12583
- className: "codexSubscriptionActions",
12584
- children: [
12585
- candidate.active ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12586
- type: "button",
12587
- variant: "outline",
12588
- disabled: busy || loginVisible,
12589
- onClick: () => selectAccount(candidate.id),
12590
- children: t("switchAccount")
12591
- }),
12592
- accounts.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12593
- type: "button",
12594
- variant: "outline",
12595
- disabled: busy || loginVisible,
12596
- onClick: () => removeAccount(candidate.id),
12597
- children: removeId === candidate.id ? t("removeConfirm") : t("removeAccount")
12598
- }) : null,
12599
- removeId === candidate.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12600
- type: "button",
12601
- variant: "outline",
12602
- disabled: busy,
12603
- onClick: () => setRemoveId(void 0),
12604
- children: t("removeCancel")
12605
- }) : null
12606
- ]
12607
- })]
12608
- }, candidate.id))
12865
+ children: accounts.map((candidate) => {
12866
+ const entry = quotas.entries[candidate.id];
12867
+ const disabled = busy || loginVisible;
12868
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12869
+ className: "codexSubscriptionAccount",
12870
+ "data-active": candidate.active,
12871
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12872
+ className: "codexSubscriptionAccountMain",
12873
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountEmail, {
12874
+ candidate,
12875
+ fallback: candidate.label,
12876
+ t,
12877
+ emailVisible: emailVisibleForAccount,
12878
+ onClick: toggleEmail
12879
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountQuota, {
12880
+ entry,
12881
+ loading: quotas.busy,
12882
+ showQuota: accounts.length > 1,
12883
+ t
12884
+ })]
12885
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12886
+ className: "codexSubscriptionActions",
12887
+ children: [
12888
+ entry?.error === "ChatGPT sign-in needs to be renewed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12889
+ type: "button",
12890
+ variant: "outline",
12891
+ disabled,
12892
+ onClick: () => {
12893
+ setAdding(false);
12894
+ setRenewId(candidate.id);
12895
+ begin("browser", { renewId: candidate.id });
12896
+ },
12897
+ children: t("renewAccount")
12898
+ }) : null,
12899
+ candidate.active ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12900
+ type: "button",
12901
+ variant: "outline",
12902
+ disabled,
12903
+ onClick: () => selectAccount(candidate.id),
12904
+ children: t("switchAccount")
12905
+ }),
12906
+ accounts.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12907
+ type: "button",
12908
+ variant: "outline",
12909
+ disabled,
12910
+ onClick: () => removeAccount(candidate.id),
12911
+ children: removeId === candidate.id ? t("removeConfirm") : t("removeAccount")
12912
+ }) : null,
12913
+ removeId === candidate.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12914
+ type: "button",
12915
+ variant: "outline",
12916
+ disabled: busy,
12917
+ onClick: () => setRemoveId(void 0),
12918
+ children: t("removeCancel")
12919
+ }) : null
12920
+ ]
12921
+ })]
12922
+ }), renewId === candidate.id ? loginContent : null] }, candidate.id);
12923
+ })
12609
12924
  }) : null,
12610
- signedIn && adding && flow === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
12925
+ signedIn && adding && !loginVisible ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
12611
12926
  className: "codexSubscriptionFlow",
12612
12927
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12613
12928
  className: "codexSubscriptionActions",
@@ -12630,89 +12945,18 @@ void main(){
12630
12945
  type: "button",
12631
12946
  variant: "outline",
12632
12947
  disabled: busy,
12633
- onClick: () => setAdding(false),
12948
+ onClick: () => {
12949
+ setAdding(false);
12950
+ setRenewId(void 0);
12951
+ setFlow(void 0);
12952
+ setError(void 0);
12953
+ },
12634
12954
  children: t("cancel")
12635
12955
  })
12636
12956
  ]
12637
12957
  })
12638
12958
  }) : null,
12639
- flow?.phase === "waiting_device" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12640
- className: "codexSubscriptionFlow",
12641
- children: [
12642
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("deviceHint") }),
12643
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
12644
- className: "codexSubscriptionCode",
12645
- children: flow.deviceCode?.userCode
12646
- }),
12647
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
12648
- href: flow.deviceCode?.verificationUri,
12649
- target: "_blank",
12650
- rel: "noreferrer",
12651
- children: t("openLogin")
12652
- }),
12653
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("waiting") }),
12654
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12655
- type: "button",
12656
- variant: "outline",
12657
- disabled: busy,
12658
- onClick: cancel,
12659
- children: t("cancel")
12660
- })
12661
- ]
12662
- }) : null,
12663
- flow?.phase === "waiting_input" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
12664
- className: "codexSubscriptionFlow",
12665
- onSubmit: submit,
12666
- children: [
12667
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("manualCode") }),
12668
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Input, {
12669
- className: "codexSubscriptionInput",
12670
- value: manualCode,
12671
- onChange: (event) => setManualCode(event.currentTarget.value),
12672
- autoComplete: "off",
12673
- spellCheck: false
12674
- }),
12675
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12676
- className: "codexSubscriptionActions",
12677
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12678
- type: "submit",
12679
- variant: "primary",
12680
- disabled: busy || manualCode.trim() === "",
12681
- children: t("submit")
12682
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12683
- type: "button",
12684
- variant: "outline",
12685
- disabled: busy,
12686
- onClick: cancel,
12687
- children: t("cancel")
12688
- })]
12689
- })
12690
- ]
12691
- }) : null,
12692
- flow !== void 0 && ["starting", "waiting_browser"].includes(flow.phase) ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12693
- className: "codexSubscriptionFlow",
12694
- children: [
12695
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("waiting") }),
12696
- flow.authUrl === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
12697
- href: flow.authUrl,
12698
- target: "_blank",
12699
- rel: "noreferrer",
12700
- children: t("openLogin")
12701
- }),
12702
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
12703
- type: "button",
12704
- variant: "outline",
12705
- disabled: busy,
12706
- onClick: cancel,
12707
- children: t("cancel")
12708
- })
12709
- ]
12710
- }) : null,
12711
- flow?.phase === "failed" || error !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
12712
- className: "codexSubscriptionError",
12713
- role: "alert",
12714
- children: error ?? (LOGIN_FAILURES.includes(flow?.failure) ? t(`failed_${flow.failure.replace("-", "_")}`) : t("failed"))
12715
- }) : null
12959
+ renewId === void 0 ? loginContent : null
12716
12960
  ]
12717
12961
  });
12718
12962
  }
@@ -12955,7 +13199,7 @@ void main(){
12955
13199
  state.status === "error" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
12956
13200
  className: "codexSubscriptionError",
12957
13201
  role: "alert",
12958
- children: state.message
13202
+ children: accessFailureText(state.message, t)
12959
13203
  }) : null,
12960
13204
  state.status === "ready" && stats.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
12961
13205
  className: "codexSubscriptionEmpty",
@@ -13097,7 +13341,7 @@ void main(){
13097
13341
  }) : null, state.status === "error" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
13098
13342
  className: "codexSubscriptionError",
13099
13343
  role: "alert",
13100
- children: state.message
13344
+ children: accessFailureText(state.message, t)
13101
13345
  }) : null]
13102
13346
  }),
13103
13347
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -13372,6 +13616,7 @@ void main(){
13372
13616
  });
13373
13617
  }
13374
13618
  function resetCreditErrorText(error, t) {
13619
+ if (isAccessFailureMessage(error?.message)) return accessFailureText(error.message, t);
13375
13620
  return t((/* @__PURE__ */ new Map([
13376
13621
  ["ChatGPT subscription is not signed in", "resetRenewLogin"],
13377
13622
  ["ChatGPT sign-in needs to be renewed", "resetRenewLogin"],
@@ -13446,7 +13691,7 @@ void main(){
13446
13691
  error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
13447
13692
  className: "codexSubscriptionError",
13448
13693
  role: "alert",
13449
- children: error
13694
+ children: accessFailureText(error, t)
13450
13695
  }),
13451
13696
  visibleUsage?.spendControlReached === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
13452
13697
  className: "codexSubscriptionError",
@@ -13702,7 +13947,20 @@ void main(){
13702
13947
  children: items
13703
13948
  });
13704
13949
  }
13705
- function CodexSection({ preference, rpc, accountStatus, t, diagnostics, defaultModel }) {
13950
+ function ProjectLink({ t }) {
13951
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
13952
+ variant: "outline",
13953
+ size: "sm",
13954
+ title: t("projectHomepage"),
13955
+ onClick: () => window.open(PROJECT_URL, "_blank", "noopener,noreferrer"),
13956
+ children: "GitHub"
13957
+ });
13958
+ }
13959
+ /** The host owns the header and its layout; contribute only to our bundle. */
13960
+ function ProjectAction({ subject, t }) {
13961
+ return subject?.kind === "bundle" && subject.pkg.name === "dsh-codex-subscription" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProjectLink, { t }) : null;
13962
+ }
13963
+ function CodexSection({ preference, rpc, accountStatus, t, diagnostics, defaultModel, embedded = false }) {
13706
13964
  const [tab, setTab] = (0, react.useState)("start");
13707
13965
  const [visited, setVisited] = (0, react.useState)(() => /* @__PURE__ */ new Set(["start"]));
13708
13966
  const selectTab = (value) => {
@@ -13733,10 +13991,11 @@ void main(){
13733
13991
  }, [accountStatus, preference]);
13734
13992
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
13735
13993
  className: "codexSubscription",
13994
+ "data-embedded": embedded || void 0,
13736
13995
  children: [
13737
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
13996
+ embedded ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
13738
13997
  className: "codexSubscriptionHead",
13739
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", { children: t("title") })
13998
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", { children: t("title") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProjectLink, { t })]
13740
13999
  }),
13741
14000
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
13742
14001
  className: "codexSettingsTabs",
@@ -13787,7 +14046,8 @@ void main(){
13787
14046
  account,
13788
14047
  setAccount,
13789
14048
  onSignedOut: accountChanged,
13790
- active: tab === "start"
14049
+ active: tab === "start",
14050
+ revision: resetKey
13791
14051
  }),
13792
14052
  account === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageCard, {
13793
14053
  rpc,
@@ -13861,6 +14121,40 @@ void main(){
13861
14121
  });
13862
14122
  }
13863
14123
  //#endregion
14124
+ //#region src/subscription-settings-entry.js
14125
+ const PACKAGE_NAME = "dsh-codex-subscription";
14126
+ /** Both host surfaces use the same controllers, RPC client and quota cache. */
14127
+ function registerSubscriptionSettings(ctx, shared, Section, ProjectAction) {
14128
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
14129
+ name: "settings.section",
14130
+ id: "codex-subscription",
14131
+ order: 15,
14132
+ label: () => shared.t("nav"),
14133
+ locale: "settings.codexSubscription",
14134
+ inject: () => shared
14135
+ }, Section));
14136
+ ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
14137
+ name: "plugins.bundle.config",
14138
+ key: PACKAGE_NAME,
14139
+ locale: "settings.codexSubscription",
14140
+ inject: () => ({
14141
+ ...shared,
14142
+ embedded: true
14143
+ })
14144
+ }, Section));
14145
+ ctx.slots.inject("plugins.detail.actions", () => ctx.slots.register({
14146
+ name: "plugins.detail.actions",
14147
+ id: "codex-subscription-project",
14148
+ locale: "settings.codexSubscription",
14149
+ inject: () => ({ t: shared.t })
14150
+ }, ProjectAction));
14151
+ }
14152
+ /** Optional host navigation: older deployments retain their original settings entry. */
14153
+ function subscriptionSettingsOpener(ctx) {
14154
+ const navigation = ctx.get("pluginNavigation");
14155
+ return typeof navigation?.openBundle === "function" ? () => navigation.openBundle(PACKAGE_NAME) : void 0;
14156
+ }
14157
+ //#endregion
13864
14158
  //#region src/diagnostic-checks.js
13865
14159
  const states = /* @__PURE__ */ new Set([
13866
14160
  "pass",
@@ -14448,21 +14742,14 @@ void main(){
14448
14742
  t
14449
14743
  })
14450
14744
  }, DeferredImageViewer));
14451
- ctx.slots.inject("settings.section", () => ctx.slots.register({
14452
- name: "settings.section",
14453
- id: "codex-subscription",
14454
- order: 15,
14455
- label: () => t("nav"),
14456
- locale: NS,
14457
- inject: () => ({
14458
- preference,
14459
- rpc,
14460
- accountStatus,
14461
- t,
14462
- diagnostics,
14463
- defaultModel
14464
- })
14465
- }, CodexSection));
14745
+ registerSubscriptionSettings(ctx, {
14746
+ preference,
14747
+ rpc,
14748
+ accountStatus,
14749
+ t,
14750
+ diagnostics,
14751
+ defaultModel
14752
+ }, CodexSection, ProjectAction);
14466
14753
  const sessions = ctx.get("sessions");
14467
14754
  const rootDirectories = ctx.get("modelDirectories");
14468
14755
  let scopedDirectories;
@@ -14476,6 +14763,7 @@ void main(){
14476
14763
  preference,
14477
14764
  rpc,
14478
14765
  t,
14766
+ openSettings: subscriptionSettingsOpener(ctx),
14479
14767
  directory: (scopedDirectories ?? rootDirectories).directoryFor(sessionId).store
14480
14768
  })
14481
14769
  }, ComposerRight));
@@ -14580,22 +14868,28 @@ void main(){
14580
14868
  imageViewer.close();
14581
14869
  liveOpen("sketch", document.activeElement, new File([blob], name || "image.png", { type: blob.type || "image/png" }));
14582
14870
  };
14583
- const attachForEdit = (sessionId) => async (src, filename, draft, annotations = [], referenceName, sourceInDraft = false, extraFiles) => {
14871
+ const attachForEdit = (sessionId) => async (src, filename, draft, annotations = [], referenceName, sourceInDraft = false, extraFiles, operation = {}) => {
14584
14872
  const tool = Array.isArray(extraFiles);
14585
14873
  if (!preference.getSnapshot().imageEditing) throw new Error("Image editing is disabled");
14586
14874
  return withComposerSession(sessions, sessionId, async (actx) => {
14587
- const response = await fetch(src, { signal: lifetime.signal });
14588
- if (!response.ok) throw new Error("Could not read generated image");
14589
- const blob = await response.blob();
14875
+ const signal = operation.signal ? AbortSignal.any([lifetime.signal, operation.signal]) : lifetime.signal;
14876
+ signal.throwIfAborted();
14877
+ const blob = typeof src === "function" ? await src({ signal }) : await fetch(src, { signal }).then((response) => {
14878
+ if (!response.ok) throw new Error("Could not read generated image");
14879
+ return response.blob();
14880
+ });
14881
+ signal.throwIfAborted();
14590
14882
  const files = sourceInDraft ? [] : [new File([blob], filename, { type: blob.type || "image/png" })];
14591
14883
  if (annotations.length > 0) {
14592
14884
  const reference = await createAnnotatedImageReference(blob, annotations);
14593
14885
  files.push(new File([reference], referenceName, { type: "image/png" }));
14594
14886
  }
14595
14887
  if (tool) files.push(...extraFiles);
14596
- lifetime.signal.throwIfAborted();
14888
+ signal.throwIfAborted();
14597
14889
  const input = conversation.input.for(actx);
14598
14890
  if (!preference.getSnapshot().imageEditing) throw new Error("Image editing is disabled");
14891
+ const ids = input.state.getSnapshot().attachmentIds;
14892
+ if (operation.sourceId && Array.isArray(ids) && !ids.includes(operation.sourceId)) throw new Error("The source attachment was removed");
14599
14893
  if (files.length) attachImageFiles(conversation, input, files, sessionId);
14600
14894
  openComposerSession(sessions, ctx.get("uiWorkspace"), sessionId);
14601
14895
  if (sourceInDraft && !annotations.length && !tool) return;
@@ -14604,7 +14898,7 @@ void main(){
14604
14898
  else input.notify("info", draft);
14605
14899
  });
14606
14900
  };
14607
- const nativeAttachments = () => ctx.slots.entries("conversation.input.attachments").find((entry) => entry.component !== ComposerImagePreviews && entry.locale === "conversation" && !entry.inject && !entry.store && !entry.children);
14901
+ const nativeAttachments = () => nativeComposerAttachments(ctx.slots.entries("conversation.input.attachments"), ComposerImagePreviews);
14608
14902
  const watchNativeAttachments = (callback) => ctx.slots.subscribe("conversation.input.attachments", callback);
14609
14903
  const nativeTranslate = ctx.locale.bind("conversation");
14610
14904
  for (const [name, component] of [
@@ -14616,12 +14910,13 @@ void main(){
14616
14910
  ]) ctx.slots.inject(name, () => {
14617
14911
  let dispose;
14618
14912
  const sync = () => {
14619
- if (preference.getSnapshot().imageViewer) dispose ??= ctx.slots.register({
14913
+ if (preference.getSnapshot().imageViewer && (component !== ComposerImagePreviews || nativeAttachments())) dispose ??= ctx.slots.register({
14620
14914
  name,
14621
14915
  priority: -10,
14622
14916
  inject: (sessionId) => ({
14623
14917
  preference,
14624
14918
  t,
14919
+ sessionId,
14625
14920
  nativeAttachments,
14626
14921
  watchNativeAttachments,
14627
14922
  nativeTranslate,
@@ -14637,8 +14932,10 @@ void main(){
14637
14932
  };
14638
14933
  sync();
14639
14934
  const unwatch = preference.subscribe(sync);
14935
+ const unwatchNative = component === ComposerImagePreviews ? watchNativeAttachments(sync) : () => {};
14640
14936
  return () => {
14641
14937
  unwatch();
14938
+ unwatchNative();
14642
14939
  dispose?.();
14643
14940
  };
14644
14941
  });