@agimon-ai/po-file-edit 0.0.0-alpha.196 → 0.0.0-alpha.198

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,4 +1,4 @@
1
- import { createApiClient, defineChannelFile, defineFileLinks, defineNativePlugin, defineSessionStore, encodeBase64, nativeApiTransport, sessionApiAddress, t, useT } from "@agimon-ai/po-core/native";
1
+ import { createApiClient, defineChannelFile, defineFileLinks, 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";
@@ -169,14 +169,13 @@ const PATH_QUERY_PARAM = "path";
169
169
  * file contents in both directions, which is the worst thing in the cockpit to
170
170
  * hand a tunnel's relay in the clear.
171
171
  */
172
- const UNREACHABLE = "The session is unreachable.";
173
172
  function isRecord(value) {
174
173
  return typeof value === "object" && value !== null && !Array.isArray(value);
175
174
  }
176
175
  /** The message a reader is shown: the route's own words, or why there were none. */
177
176
  function messageOf(result) {
178
- if (result.status === 0) return UNREACHABLE;
179
- return result.error === "" ? `The session answered ${result.status}.` : result.error;
177
+ if (result.status === 0) return t("fileEdit.error.unreachable", "The session is unreachable.");
178
+ return result.error === "" ? t("fileEdit.error.status", "The session answered {status}.", { status: result.status }) : result.error;
180
179
  }
181
180
  async function fetchFileDetail(sessionId, filePath) {
182
181
  const result = await api.session(sessionId).detail({ query: { [PATH_QUERY_PARAM]: filePath } });
@@ -186,7 +185,7 @@ async function fetchFileDetail(sessionId, filePath) {
186
185
  };
187
186
  if (!isRecord(result.data)) return {
188
187
  ok: false,
189
- error: "The session answered with no detail."
188
+ error: t("fileEdit.error.noDetail", "The session answered with no detail.")
190
189
  };
191
190
  return {
192
191
  ok: true,
@@ -202,7 +201,7 @@ async function fetchFilePreview(sessionId, filePath) {
202
201
  };
203
202
  if (!isRecord(result.data)) return {
204
203
  ok: false,
205
- error: "The session answered with no file."
204
+ error: t("fileEdit.error.noFile", "The session answered with no file.")
206
205
  };
207
206
  return {
208
207
  ok: true,
@@ -221,7 +220,7 @@ async function saveFileContent(sessionId, filePath, expectedHash, content) {
221
220
  return {
222
221
  ok: false,
223
222
  stale: true,
224
- error: result.ok ? "The file changed since it was opened." : messageOf(result),
223
+ error: result.ok ? t("fileEdit.error.changed", "The file changed since it was opened.") : messageOf(result),
225
224
  ...hash === void 0 ? {} : { hash }
226
225
  };
227
226
  }
@@ -252,43 +251,43 @@ async function deleteFile(sessionId, filePath) {
252
251
  /** Binds a save to this package's guarded sealed route and one file version. */
253
252
  async function prepareFileSave(sessionId, path, signal) {
254
253
  const load = async (headers, signal) => {
255
- if (signal.aborted) throw new Error("Download cancelled.");
254
+ if (signal.aborted) throw new Error(t("fileEdit.error.cancelled", "Download cancelled."));
256
255
  const result = await api.session(sessionId).file({
257
256
  query: { path },
258
257
  headers,
259
258
  signal
260
259
  });
261
- if (!result.ok && result.status !== 416) throw new Error(result.error || "File could not be read.");
262
- if (!result.response) throw new Error("File could not be read.");
260
+ if (!result.ok && result.status !== 416) throw new Error(result.error || t("fileEdit.error.read", "File could not be read."));
261
+ if (!result.response) throw new Error(t("fileEdit.error.read", "File could not be read."));
263
262
  return result.response;
264
263
  };
265
264
  const probe = await load({ Range: "bytes=0-0" }, signal);
266
- if (signal.aborted) throw new Error("Download cancelled.");
265
+ if (signal.aborted) throw new Error(t("fileEdit.error.cancelled", "Download cancelled."));
267
266
  const range = /^bytes 0-0\/(\d+)$/u.exec(probe.headers.get("content-range") ?? "");
268
267
  const empty = probe.status === 416 && probe.headers.get("content-range") === "bytes */0" || probe.status === 200 && probe.headers.get("content-length") === "0";
269
- if (!empty && (probe.status !== 206 || !range)) throw new Error("The file does not support bounded downloads.");
268
+ if (!empty && (probe.status !== 206 || !range)) throw new Error(t("fileEdit.error.bounded", "The file does not support bounded downloads."));
270
269
  const size = empty ? 0 : Number(range[1]);
271
- if (!Number.isSafeInteger(size) || size < 0) throw new Error("Invalid file size.");
272
- if ((await probe.arrayBuffer()).byteLength !== (empty ? 0 : 1)) throw new Error("Invalid file response.");
270
+ if (!Number.isSafeInteger(size) || size < 0) throw new Error(t("fileEdit.error.size", "Invalid file size."));
271
+ if ((await probe.arrayBuffer()).byteLength !== (empty ? 0 : 1)) throw new Error(t("fileEdit.error.response", "Invalid file response."));
273
272
  const version = probe.headers.get("etag");
274
- if (!version) throw new Error("The file has no version validator.");
273
+ if (!version) throw new Error(t("fileEdit.error.validator", "The file has no version validator."));
275
274
  return {
276
275
  name: path.split(/[\\/]/u).at(-1) ?? "",
277
276
  mimeType: probe.headers.get("content-type")?.split(";")[0]?.trim() || "application/octet-stream",
278
277
  size,
279
278
  signal,
280
279
  read: async (offset, count, signal) => {
281
- if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(count) || offset < 0 || count < 1 || count > 1048576 || offset + count > size) throw new Error("Invalid download range.");
280
+ if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(count) || offset < 0 || count < 1 || count > 1048576 || offset + count > size) throw new Error(t("fileEdit.error.range", "Invalid download range."));
282
281
  const end = offset + count - 1;
283
282
  const response = await load({
284
283
  Range: `bytes=${offset}-${end}`,
285
284
  "If-Match": version
286
285
  }, signal);
287
- if (signal.aborted) throw new Error("Download cancelled.");
288
- if (response.status !== 206 || response.headers.get("etag") !== version || response.headers.get("content-range") !== `bytes ${offset}-${end}/${size}`) throw new Error("The file changed or its range response is invalid.");
286
+ if (signal.aborted) throw new Error(t("fileEdit.error.cancelled", "Download cancelled."));
287
+ if (response.status !== 206 || response.headers.get("etag") !== version || response.headers.get("content-range") !== `bytes ${offset}-${end}/${size}`) throw new Error(t("fileEdit.error.rangeChanged", "The file changed or its range response is invalid."));
289
288
  const bytes = new Uint8Array(await response.arrayBuffer());
290
- if (signal.aborted) throw new Error("Download cancelled.");
291
- if (bytes.byteLength !== count) throw new Error("The file response is incomplete.");
289
+ if (signal.aborted) throw new Error(t("fileEdit.error.cancelled", "Download cancelled."));
290
+ if (bytes.byteLength !== count) throw new Error(t("fileEdit.error.incomplete", "The file response is incomplete."));
292
291
  return bytes;
293
292
  }
294
293
  };
@@ -299,6 +298,7 @@ const ROW_STEP = 200;
299
298
  /** Mount only the disclosed prefix; source line numbers and single-line comment anchors stay intact. */
300
299
  function FileDiff({ hunks, comment, initialRows = ROW_STEP, label = "file-diff" }) {
301
300
  const t = useT();
301
+ const locale = useLocale();
302
302
  const [limit, setLimit] = useState(initialRows);
303
303
  const total = useMemo(() => hunks.reduce((count, hunk) => count + hunk.rows.length, 0), [hunks]);
304
304
  const visible = useMemo(() => {
@@ -351,8 +351,8 @@ function FileDiff({ hunks, comment, initialRows = ROW_STEP, label = "file-diff"
351
351
  accessibilityLiveRegion: "polite",
352
352
  style: styles$3.meta,
353
353
  children: t("fileEdit.ui.showingValue1OfValue2Rows", "Showing {value1} of {value2} rows", {
354
- value1: Math.min(limit, total).toLocaleString("en-US"),
355
- value2: total.toLocaleString("en-US")
354
+ value1: Math.min(limit, total).toLocaleString(locale),
355
+ value2: total.toLocaleString(locale)
356
356
  })
357
357
  }), limit < total ? /* @__PURE__ */ jsx(Button, {
358
358
  variant: "outline",