@agimon-ai/po-file-edit 0.0.0-alpha.203 → 0.0.0-alpha.205

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.
@@ -1,8 +1,8 @@
1
- import { createApiClient, defineChannelFile, defineFileLinks, defineNativePlugin, defineSessionStore, encodeBase64, nativeApiTransport, sessionApiAddress, t, useLocale, useT } from "@agimon-ai/po-core/native";
1
+ import { createApiClient, defineChannelFile, defineFileLinks, defineFill, defineNativePlugin, defineSessionStore, encodeBase64, nativeApiTransport, sessionApiAddress, t, useLocale, useT } from "@agimon-ai/po-core/native";
2
2
  import { View } from "react-native-unistyles/components/native/View";
3
3
  import { Text } from "react-native-unistyles/components/native/Text";
4
4
  import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
5
- import { Button, CloseIcon, CodeBlock, CopyButton, DownloadIcon, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, KebabIcon, Label, Markdown, SegmentedControl, Sheet, SheetBody, SheetContent, SheetHeader, SheetTitle, Textarea, fontOf } from "@agimon-ai/po-native-components";
5
+ import { Button, CloseIcon, CodeBlock, CopyButton, DownloadIcon, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, EmptyState, KebabIcon, Label, LockIcon, Markdown, SegmentedControl, Sheet, SheetBody, SheetContent, SheetHeader, SheetTitle, Textarea, fontOf } from "@agimon-ai/po-native-components";
6
6
  import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
7
7
  import { StyleSheet } from "react-native-unistyles";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -197,7 +197,8 @@ async function fetchFilePreview(sessionId, filePath) {
197
197
  const result = await api.session(sessionId).preview({ query: { [PATH_QUERY_PARAM]: filePath } });
198
198
  if (!result.ok) return {
199
199
  ok: false,
200
- error: messageOf(result)
200
+ error: messageOf(result),
201
+ status: result.status
201
202
  };
202
203
  if (!isRecord(result.data)) return {
203
204
  ok: false,
@@ -658,7 +659,9 @@ function FilePanel({ filePath, relPath, ...props }) {
658
659
  const [confirmingDelete, setConfirmingDelete] = useState(false);
659
660
  const [busy, setBusy] = useState(false);
660
661
  const [note, setNote] = useState();
662
+ const [failure, setFailure] = useState();
661
663
  const [reviewError, setReviewError] = useState();
664
+ const [attempt, setAttempt] = useState(0);
662
665
  const outside = relPath === ".." || relPath.startsWith("../") || relPath.startsWith("/") || relPath.startsWith("..\\") || /^[a-z]:[\\/]/iu.test(relPath);
663
666
  const writable = sessionId !== null && !outside && working !== void 0 && !working.unavailable;
664
667
  useEffect(() => {
@@ -671,6 +674,7 @@ function FilePanel({ filePath, relPath, ...props }) {
671
674
  storeDetail(sessionId, result.detail);
672
675
  setSource(void 0);
673
676
  setNote(void 0);
677
+ setFailure(void 0);
674
678
  } else storeError(sessionId, filePath, result.error);
675
679
  }).catch((failure) => {
676
680
  if (!cancelled) storeError(sessionId, filePath, failure instanceof Error ? failure.message : String(failure));
@@ -681,8 +685,17 @@ function FilePanel({ filePath, relPath, ...props }) {
681
685
  }, [
682
686
  sessionId,
683
687
  filePath,
684
- revision
688
+ revision,
689
+ attempt
685
690
  ]);
691
+ const failed = (title, retry) => (error) => {
692
+ setNote(void 0);
693
+ setFailure({
694
+ title,
695
+ message: error instanceof Error ? error.message : String(error),
696
+ retry
697
+ });
698
+ };
686
699
  const downloadController = useRef(void 0);
687
700
  useEffect(() => () => downloadController.current?.abort(), [sessionId, relPath]);
688
701
  const download = async () => {
@@ -690,11 +703,12 @@ function FilePanel({ filePath, relPath, ...props }) {
690
703
  const controller = new AbortController();
691
704
  downloadController.current = controller;
692
705
  setBusy(true);
706
+ setFailure(void 0);
693
707
  try {
694
708
  await props.nativeSaveFile(await prepareFileSave(sessionId, relPath, controller.signal));
695
709
  if (!controller.signal.aborted) setNote("saved");
696
710
  } catch (error) {
697
- if (!controller.signal.aborted) setNote(error instanceof Error ? error.message : String(error));
711
+ if (!controller.signal.aborted) failed(t("fileEdit.ui.downloadFailed", "Couldn't download this file"), () => void download())(error);
698
712
  } finally {
699
713
  setBusy(false);
700
714
  }
@@ -702,10 +716,12 @@ function FilePanel({ filePath, relPath, ...props }) {
702
716
  const save = async () => {
703
717
  if (!writable || sessionId === null || !working || source === void 0 || busy) return;
704
718
  setBusy(true);
719
+ setFailure(void 0);
720
+ const saveFailed = failed(t("fileEdit.ui.saveFailed", "Couldn't save this file"), () => void save());
705
721
  try {
706
722
  const result = await saveFileContent(sessionId, filePath, working.hash, source);
707
723
  if (!result.ok) {
708
- setNote(result.error);
724
+ saveFailed(result.error);
709
725
  return;
710
726
  }
711
727
  setNote("saved");
@@ -715,7 +731,7 @@ function FilePanel({ filePath, relPath, ...props }) {
715
731
  setSource(void 0);
716
732
  } else storeError(sessionId, filePath, refreshed.error);
717
733
  } catch (failure) {
718
- setNote(failure instanceof Error ? failure.message : String(failure));
734
+ saveFailed(failure);
719
735
  } finally {
720
736
  setBusy(false);
721
737
  }
@@ -723,17 +739,19 @@ function FilePanel({ filePath, relPath, ...props }) {
723
739
  const remove = async () => {
724
740
  if (!writable || sessionId === null || busy) return;
725
741
  setBusy(true);
742
+ setFailure(void 0);
743
+ const deleteFailed = failed(t("fileEdit.ui.deleteFailed", "Couldn't delete this file"), () => void remove());
726
744
  try {
727
745
  const result = await deleteFile(sessionId, filePath);
728
746
  if (!result.ok) {
729
- storeError(sessionId, filePath, result.error);
747
+ deleteFailed(result.error);
730
748
  setConfirmingDelete(false);
731
749
  } else {
732
750
  setConfirmingDelete(false);
733
751
  closeTransientTab(fileTabId(filePath));
734
752
  }
735
753
  } catch (failure) {
736
- storeError(sessionId, filePath, failure instanceof Error ? failure.message : String(failure));
754
+ deleteFailed(failure);
737
755
  setConfirmingDelete(false);
738
756
  } finally {
739
757
  setBusy(false);
@@ -797,9 +815,20 @@ function FilePanel({ filePath, relPath, ...props }) {
797
815
  })
798
816
  ] })] })]
799
817
  }),
800
- view !== "edit" && note ? /* @__PURE__ */ jsx(Text, {
801
- style: note === "saved" ? styles$1.success : styles$1.error,
802
- children: note === "saved" ? t("fileEdit.ui.saved", "saved") : note
818
+ failure ? /* @__PURE__ */ jsx(EmptyState, {
819
+ size: "compact",
820
+ surface: "plain",
821
+ tone: "error",
822
+ title: failure.title,
823
+ description: failure.message,
824
+ action: {
825
+ label: t("fileEdit.ui.tryAgain", "Try again"),
826
+ onAction: failure.retry,
827
+ loading: busy
828
+ }
829
+ }) : view !== "edit" && note === "saved" ? /* @__PURE__ */ jsx(Text, {
830
+ style: styles$1.success,
831
+ children: t("fileEdit.ui.saved", "saved")
803
832
  }) : null,
804
833
  /* @__PURE__ */ jsx(SegmentedControl, {
805
834
  accessibilityLabel: t("fileEdit.ui.fileView", "file view"),
@@ -825,10 +854,15 @@ function FilePanel({ filePath, relPath, ...props }) {
825
854
  style: styles$1.meta,
826
855
  children: t("fileEdit.ui.readingThisFileSHistory", "reading this file's history…")
827
856
  }) : null,
828
- error ? /* @__PURE__ */ jsx(Text, {
829
- accessibilityRole: "alert",
830
- style: styles$1.error,
831
- children: error
857
+ error ? /* @__PURE__ */ jsx(EmptyState, {
858
+ tone: "error",
859
+ title: t("fileEdit.ui.historyFailed", "Couldn't load this file"),
860
+ description: error,
861
+ action: {
862
+ label: t("fileEdit.ui.tryAgain", "Try again"),
863
+ onAction: () => setAttempt((value) => value + 1),
864
+ loading
865
+ }
832
866
  }) : null,
833
867
  detail ? view === "diff" ? /* @__PURE__ */ jsxs(Fragment, { children: [
834
868
  /* @__PURE__ */ jsxs(Text, {
@@ -913,9 +947,9 @@ function FilePanel({ filePath, relPath, ...props }) {
913
947
  ] }) : /* @__PURE__ */ jsx(Text, {
914
948
  style: styles$1.meta,
915
949
  children: working?.reason ?? t("fileEdit.ui.thisFileCannotBeEdited", "this file cannot be edited")
916
- }), note ? /* @__PURE__ */ jsx(Text, {
917
- style: note === "saved" ? styles$1.success : styles$1.error,
918
- children: note === "saved" ? t("fileEdit.ui.saved", "saved") : note
950
+ }), note === "saved" ? /* @__PURE__ */ jsx(Text, {
951
+ style: styles$1.success,
952
+ children: t("fileEdit.ui.saved", "saved")
919
953
  }) : null] }) : working ? /* @__PURE__ */ jsx(FilePreview, {
920
954
  ...props,
921
955
  path: relPath,
@@ -938,10 +972,16 @@ function FilePanel({ filePath, relPath, ...props }) {
938
972
  onPress: sendReview,
939
973
  children: t("fileEdit.ui.sendReviewValue1", "send review ({value1})", { value1: comments.length })
940
974
  }),
941
- reviewError ? /* @__PURE__ */ jsx(Text, {
942
- accessibilityRole: "alert",
943
- style: styles$1.error,
944
- children: t("fileEdit.ui.reviewNotSentValue1", "review not sent: {value1}", { value1: reviewError })
975
+ reviewError ? /* @__PURE__ */ jsx(EmptyState, {
976
+ size: "compact",
977
+ surface: "plain",
978
+ tone: "error",
979
+ title: t("fileEdit.ui.reviewNotSent", "Couldn't send the review"),
980
+ description: reviewError,
981
+ action: {
982
+ label: t("fileEdit.ui.tryAgain", "Try again"),
983
+ onAction: sendReview
984
+ }
945
985
  }) : null,
946
986
  comments.map((comment) => /* @__PURE__ */ jsxs(View, { children: [/* @__PURE__ */ jsxs(Text, {
947
987
  style: styles$1.meta,
@@ -1051,11 +1091,6 @@ const styles$1 = StyleSheet.create((theme) => ({
1051
1091
  color: theme.colors.dim,
1052
1092
  uni__dependencies: [0]
1053
1093
  },
1054
- error: {
1055
- fontSize: theme.fontSize.sm,
1056
- color: theme.colors.red,
1057
- uni__dependencies: [0]
1058
- },
1059
1094
  success: {
1060
1095
  fontSize: theme.fontSize.sm,
1061
1096
  color: theme.colors.green,
@@ -1081,6 +1116,7 @@ function fileKind(path) {
1081
1116
  function FilePreviewPanel({ filePath, ...props }) {
1082
1117
  const t = useT();
1083
1118
  const [loaded, setLoaded] = useState();
1119
+ const [attempt, setAttempt] = useState(0);
1084
1120
  useEffect(() => {
1085
1121
  if (props.sessionId === null) return;
1086
1122
  const sessionId = props.sessionId;
@@ -1089,27 +1125,36 @@ function FilePreviewPanel({ filePath, ...props }) {
1089
1125
  if (!cancelled) setLoaded(result.ok ? {
1090
1126
  sessionId,
1091
1127
  path: filePath,
1092
- preview: result.preview
1128
+ preview: result.preview,
1129
+ attempt
1093
1130
  } : {
1094
1131
  sessionId,
1095
1132
  path: filePath,
1096
- error: result.error
1133
+ error: result.error,
1134
+ denied: result.status === 403,
1135
+ attempt
1097
1136
  });
1098
1137
  }).catch((failure) => {
1099
1138
  if (!cancelled) setLoaded({
1100
1139
  sessionId,
1101
1140
  path: filePath,
1102
- error: failure instanceof Error ? failure.message : String(failure)
1141
+ error: failure instanceof Error ? failure.message : String(failure),
1142
+ attempt
1103
1143
  });
1104
1144
  });
1105
1145
  return () => {
1106
1146
  cancelled = true;
1107
1147
  };
1108
- }, [props.sessionId, filePath]);
1148
+ }, [
1149
+ props.sessionId,
1150
+ filePath,
1151
+ attempt
1152
+ ]);
1109
1153
  const current = loaded?.path === filePath && loaded.sessionId === props.sessionId ? loaded : void 0;
1110
1154
  const controller = useRef(void 0);
1111
1155
  const [saving, setSaving] = useState(false);
1112
1156
  const [note, setNote] = useState();
1157
+ const [saveFailed, setSaveFailed] = useState();
1113
1158
  useEffect(() => () => controller.current?.abort(), [props.sessionId, filePath]);
1114
1159
  const save = async () => {
1115
1160
  if (props.sessionId === null || !props.nativeSaveFile || controller.current) return;
@@ -1119,9 +1164,12 @@ function FilePreviewPanel({ filePath, ...props }) {
1119
1164
  setNote(void 0);
1120
1165
  try {
1121
1166
  await props.nativeSaveFile(await prepareFileSave(props.sessionId, filePath, active.signal));
1122
- if (!active.signal.aborted) setNote("Saved.");
1167
+ if (!active.signal.aborted) {
1168
+ setSaveFailed(void 0);
1169
+ setNote(t("fileEdit.ui.downloadSaved", "Saved."));
1170
+ }
1123
1171
  } catch (error) {
1124
- if (!active.signal.aborted) setNote(error instanceof Error ? error.message : String(error));
1172
+ if (!active.signal.aborted) setSaveFailed(error instanceof Error ? error.message : String(error));
1125
1173
  } finally {
1126
1174
  if (controller.current === active) controller.current = void 0;
1127
1175
  setSaving(false);
@@ -1131,7 +1179,8 @@ function FilePreviewPanel({ filePath, ...props }) {
1131
1179
  controller.current?.abort();
1132
1180
  controller.current = void 0;
1133
1181
  setSaving(false);
1134
- setNote("Download cancelled.");
1182
+ setSaveFailed(void 0);
1183
+ setNote(t("fileEdit.ui.downloadCancelled", "Download cancelled."));
1135
1184
  };
1136
1185
  const handlers = useRef({
1137
1186
  save,
@@ -1171,14 +1220,20 @@ function FilePreviewPanel({ filePath, ...props }) {
1171
1220
  t
1172
1221
  ]);
1173
1222
  const relPath = current?.preview?.relPath ?? filePath;
1174
- const body = offline ? /* @__PURE__ */ jsx(Text, {
1175
- accessibilityRole: "alert",
1176
- style: styles.error,
1177
- children: t("fileEdit.ui.theSessionIsUnavailable", "The session is unavailable.")
1178
- }) : current?.error ? /* @__PURE__ */ jsx(Text, {
1179
- accessibilityRole: "alert",
1180
- style: styles.error,
1181
- children: current.error
1223
+ const retrying = current !== void 0 && current.attempt !== attempt;
1224
+ const body = offline ? /* @__PURE__ */ jsx(EmptyState, { title: t("fileEdit.ui.theSessionIsUnavailable", "The session is unavailable.") }) : current?.error && current.denied ? /* @__PURE__ */ jsx(EmptyState, {
1225
+ icon: /* @__PURE__ */ jsx(LockIcon, { size: 20 }),
1226
+ title: t("fileEdit.ui.previewDenied", "This file can't be opened here"),
1227
+ description: current.error
1228
+ }) : current?.error ? /* @__PURE__ */ jsx(EmptyState, {
1229
+ tone: "error",
1230
+ title: t("fileEdit.ui.previewFailed", "Couldn't load this file"),
1231
+ description: current.error,
1232
+ action: {
1233
+ label: t("fileEdit.ui.tryAgain", "Try again"),
1234
+ onAction: () => setAttempt((value) => value + 1),
1235
+ loading: retrying
1236
+ }
1182
1237
  }) : current?.preview ? /* @__PURE__ */ jsx(FilePreview, {
1183
1238
  ...props,
1184
1239
  path: current.preview.relPath,
@@ -1218,7 +1273,18 @@ function FilePreviewPanel({ filePath, ...props }) {
1218
1273
  }) : null
1219
1274
  ]
1220
1275
  }),
1221
- note ? /* @__PURE__ */ jsx(Text, {
1276
+ saveFailed ? /* @__PURE__ */ jsx(EmptyState, {
1277
+ size: "compact",
1278
+ surface: "plain",
1279
+ tone: "error",
1280
+ title: t("fileEdit.ui.saveFailed", "Couldn't save this file"),
1281
+ description: saveFailed,
1282
+ action: {
1283
+ label: t("fileEdit.ui.tryAgain", "Try again"),
1284
+ onAction: () => void save(),
1285
+ loading: saving
1286
+ }
1287
+ }) : note ? /* @__PURE__ */ jsx(Text, {
1222
1288
  accessibilityLiveRegion: "polite",
1223
1289
  style: styles.meta,
1224
1290
  children: note
@@ -1292,12 +1358,6 @@ const styles = StyleSheet.create((theme, rt) => ({
1292
1358
  fontSize: theme.fontSize.sm,
1293
1359
  color: theme.colors.dim,
1294
1360
  uni__dependencies: [0]
1295
- },
1296
- error: {
1297
- fontFamily: fontOf(theme.fontFamily.sans),
1298
- fontSize: theme.fontSize.sm,
1299
- color: theme.colors.red,
1300
- uni__dependencies: [0]
1301
1361
  }
1302
1362
  }));
1303
1363
  //#endregion
@@ -1342,6 +1402,36 @@ var files_native_default = defineFileLinks({
1342
1402
  }
1343
1403
  });
1344
1404
  //#endregion
1405
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/Filechanges.help.guides.native.ts
1406
+ var Filechanges_help_guides_native_default = defineFill({
1407
+ slot: "help.guides",
1408
+ id: "Filechanges",
1409
+ order: 120,
1410
+ data: {
1411
+ version: 1,
1412
+ category: "files",
1413
+ labelKey: "fileEdit.guides.fileChanges",
1414
+ label: "File changes",
1415
+ guides: [{
1416
+ id: "about",
1417
+ questionKey: "fileEdit.guides.whatFileChangesAreTracked",
1418
+ question: "What file changes are tracked?",
1419
+ order: 0,
1420
+ answerKey: "fileEdit.guides.fileChangesRecordsFilesChangedThroughSessionToolsAndCapturesContentForDiffsWithoutRequiringGitBinaryFilesAndContentAbove1MiBAreListedWithoutCapturedContent",
1421
+ answer: "File changes records files changed through session tools and captures content for diffs without requiring Git. Binary files and content above 1 MiB are listed without captured content.",
1422
+ keywords: ["diff", "tracking"]
1423
+ }, {
1424
+ id: "use",
1425
+ questionKey: "fileEdit.guides.howDoIReviewFileChanges",
1426
+ question: "How do I review file changes?",
1427
+ order: 1,
1428
+ answerKey: "fileEdit.guides.selectAFileInTheActivityDockToOpenItsTabAndInspectTheDiffOrPreviewSelectTextToAddCommentsThenChooseSendReviewToSendTheQueuedCommentsTogether",
1429
+ answer: "Select a file in the activity dock to open its tab and inspect the diff or preview. Select text to add comments, then choose send review to send the queued comments together.",
1430
+ keywords: ["comments", "review"]
1431
+ }]
1432
+ }
1433
+ });
1434
+ //#endregion
1345
1435
  //#region generated/native.ts
1346
1436
  const via = (identity, value) => value === void 0 ? void 0 : {
1347
1437
  ...identity,
@@ -1356,6 +1446,12 @@ const nativePlugin = defineNativePlugin({
1356
1446
  },
1357
1447
  get fileLinks() {
1358
1448
  return files_native_default;
1449
+ },
1450
+ get fills() {
1451
+ return [via({
1452
+ slot: "help.guides",
1453
+ id: "filechanges"
1454
+ }, Filechanges_help_guides_native_default)];
1359
1455
  }
1360
1456
  }
1361
1457
  });