@appsoftwareltd/etherpk-mcp 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -626,6 +626,15 @@ var ASSET_CHUNK_PLAINTEXT_BYTES = 4194304;
626
626
  function assetChunkCount(size) {
627
627
  return Math.max(1, Math.ceil(size / ASSET_CHUNK_PLAINTEXT_BYTES));
628
628
  }
629
+ z.strictObject({
630
+ /** Sync+ can be bought now. */
631
+ billingEnabled: z.boolean(),
632
+ /** The price as the account site writes it, currency included. Shown as text, never parsed. */
633
+ priceDisplay: z.string().min(1).max(32).regex(/^[^\p{Cc}\p{Cf}<>]+$/u),
634
+ billingInterval: z.enum(["month", "year"]),
635
+ /** Days of trial a first subscription starts with; 0 for none. */
636
+ trialDays: z.number().int().min(0).max(366)
637
+ });
629
638
  /** Whether `text` is a short link a Sync Server opens: one of Google's share links. */
630
639
  function isShortMapLink(text) {
631
640
  let url;
@@ -714,7 +723,7 @@ function looksLikeAgentSetupCode(value) {
714
723
  }
715
724
  var package_default = {
716
725
  name: "@appsoftwareltd/etherpk-mcp",
717
- version: "0.20.0",
726
+ version: "0.21.0",
718
727
  license: "Elastic-2.0",
719
728
  description: "EtherPK Headless Client: an MCP server over a synced knowledge graph, run beside the agent on the user's own machine.",
720
729
  type: "module",
@@ -8298,6 +8307,56 @@ async function findGraphByName(records, vault, wanted, readMeta) {
8298
8307
  }
8299
8308
  return null;
8300
8309
  }
8310
+ // ../client/src/lib/document/ebook/ebook-state.ts
8311
+ /**
8312
+ * A place in an EBook. An element's id is part of one, and an id can hold spaces or quotes, so the shape is
8313
+ * checked and not the characters. It only ever goes back to the frame or into a percent-encoded link.
8314
+ */
8315
+ var isEbookCfi = (value) => typeof value === "string" && value.length <= 2e3 && /^epubcfi\(\P{Cc}+\)$/u.test(value);
8316
+ var MAX_NAME$1 = 300;
8317
+ var isText$1 = (value) => typeof value === "string" && value !== "";
8318
+ var isHash = (value) => typeof value === "string" && /^[0-9a-f]{64}$/.test(value);
8319
+ var isFraction = (value) => typeof value === "number" && value >= 0 && value <= 1;
8320
+ var CHECKS = {
8321
+ id: isText$1,
8322
+ target: isText$1,
8323
+ name: isText$1,
8324
+ hash: isHash,
8325
+ cfi: isEbookCfi,
8326
+ fraction: isFraction,
8327
+ createdAt: (value) => typeof value === "number"
8328
+ };
8329
+ function sanitizeOne$1(raw) {
8330
+ if (typeof raw !== "object" || raw === null) return null;
8331
+ const r = raw;
8332
+ if (!Object.entries(CHECKS).every(([key, valid]) => valid(r[key]))) return null;
8333
+ const { id, hash, target, name, cfi, fraction, createdAt } = r;
8334
+ return {
8335
+ id,
8336
+ hash,
8337
+ target,
8338
+ name: name.slice(0, MAX_NAME$1),
8339
+ cfi,
8340
+ fraction,
8341
+ createdAt,
8342
+ ...isText$1(r.chapter) ? { chapter: r.chapter.slice(0, MAX_NAME$1) } : {}
8343
+ };
8344
+ }
8345
+ /** Keep the well-formed entries, the first of each id. */
8346
+ function sanitizeEbookBookmarks(raw) {
8347
+ if (!Array.isArray(raw)) return [];
8348
+ const seen = /* @__PURE__ */ new Set();
8349
+ const out = [];
8350
+ for (const entry of raw) {
8351
+ const clean = sanitizeOne$1(entry);
8352
+ if (clean && !seen.has(clean.id) && out.length < 2e3) {
8353
+ seen.add(clean.id);
8354
+ out.push(clean);
8355
+ }
8356
+ }
8357
+ return out;
8358
+ }
8359
+ Promise.resolve();
8301
8360
  var MAX_NAME = 300;
8302
8361
  var isText = (value) => typeof value === "string" && value !== "";
8303
8362
  var isWhole = (value) => typeof value === "number" && Number.isInteger(value) && value >= 1;
@@ -10394,7 +10453,9 @@ var MEMBER_LIST_KINDS = [
10394
10453
  "bookmarks",
10395
10454
  "memberFlags",
10396
10455
  "pdfStates",
10397
- "pdfBookmarks"
10456
+ "pdfBookmarks",
10457
+ "ebookStates",
10458
+ "ebookBookmarks"
10398
10459
  ];
10399
10460
  /** Which Yjs type each kind is, so a type received but never asked for by name is read as the right one. */
10400
10461
  var MEMBER_LIST_IS_ARRAY = {
@@ -10403,7 +10464,9 @@ var MEMBER_LIST_IS_ARRAY = {
10403
10464
  bookmarks: false,
10404
10465
  memberFlags: false,
10405
10466
  pdfStates: false,
10406
- pdfBookmarks: false
10467
+ pdfBookmarks: false,
10468
+ ebookStates: false,
10469
+ ebookBookmarks: false
10407
10470
  };
10408
10471
  /** `kind` and member key of a per-member type's name, or null for any other root-doc type. */
10409
10472
  function memberListName(name) {
@@ -11557,6 +11620,35 @@ function createGraphSync(deps) {
11557
11620
  }
11558
11621
  };
11559
11622
  },
11623
+ ebookBookmarks(member) {
11624
+ requireMemberKey(member, "ebookBookmarks");
11625
+ const map = root.doc.getMap(`ebookBookmarks:${member}`);
11626
+ return {
11627
+ list: () => sanitizeEbookBookmarks([...map.values()]),
11628
+ apply(change) {
11629
+ root.doc.transact(() => {
11630
+ for (const id of change.remove) map.delete(id);
11631
+ for (const bookmark of change.put) map.set(bookmark.id, bookmark);
11632
+ });
11633
+ },
11634
+ observe(listener) {
11635
+ map.observe(listener);
11636
+ return () => map.unobserve(listener);
11637
+ }
11638
+ };
11639
+ },
11640
+ ebookStateIndex(member) {
11641
+ const map = root.doc.getMap(`ebookStates:${member}`);
11642
+ return {
11643
+ hashes: () => [...map.keys()],
11644
+ add(hash) {
11645
+ if (!map.has(hash)) map.set(hash, Date.now());
11646
+ },
11647
+ remove(hash) {
11648
+ map.delete(hash);
11649
+ }
11650
+ };
11651
+ },
11560
11652
  pdfStateIndex(member) {
11561
11653
  const map = root.doc.getMap(`pdfStates:${member}`);
11562
11654
  return {
@@ -16850,6 +16942,7 @@ var MIME_TYPES = {
16850
16942
  avif: "image/avif",
16851
16943
  bmp: "image/bmp",
16852
16944
  pdf: "application/pdf",
16945
+ epub: "application/epub+zip",
16853
16946
  txt: "text/plain",
16854
16947
  csv: "text/csv",
16855
16948
  json: "application/json",
@@ -28916,7 +29009,8 @@ async function unlockByDeviceApproval(api, io) {
28916
29009
  const where = io.clientUrl ? `open EtherPK at ${io.clientUrl}` : "open EtherPK in a browser";
28917
29010
  io.say("");
28918
29011
  io.say(`To approve this device, ${where} (any page - it need not be a note) on any device where this account's`);
28919
- io.say("Encryption Keys are unlocked. A prompt will appear there, and this terminal then shows a code to compare.");
29012
+ io.say("Encryption Keys are unlocked. A prompt appears on each of them: choose Show the code on the one you approve");
29013
+ io.say("from, and this terminal then shows the same code.");
28920
29014
  io.say("");
28921
29015
  io.say("Waiting (up to ten minutes)…");
28922
29016
  const abandon = async () => {
@@ -28945,6 +29039,7 @@ async function unlockByDeviceApproval(api, io) {
28945
29039
  if (approved && io.codesMatch()) return approved;
28946
29040
  if (approved && !toldApproved) {
28947
29041
  toldApproved = true;
29042
+ io.say("");
28948
29043
  io.say("EtherPK approved this device. Press y if it showed the same code.");
28949
29044
  }
28950
29045
  await io.sleep(APPROVAL_POLL_MS);
@@ -29411,10 +29506,13 @@ async function login(args) {
29411
29506
  pat: token
29412
29507
  }).catch(abandon);
29413
29508
  console.log(`Connected to ${syncServer} as ${account.principal.email ?? account.principal.name ?? account.principal.id}.`);
29414
- const byRecoveryCode = async () => unlockByRecoveryCode(account.api, process.env.ETHERPK_RECOVERY_CODE ?? await ask("Recovery Code: ", {
29415
- secret: true,
29416
- hint: "set ETHERPK_RECOVERY_CODE"
29417
- }));
29509
+ const byRecoveryCode = async () => {
29510
+ console.log("");
29511
+ return unlockByRecoveryCode(account.api, process.env.ETHERPK_RECOVERY_CODE ?? await ask("Recovery Code: ", {
29512
+ secret: true,
29513
+ hint: "set ETHERPK_RECOVERY_CODE"
29514
+ }));
29515
+ };
29418
29516
  const vaultKey = await (args["recovery-code"] ? byRecoveryCode() : approveOrFallBack(account, byRecoveryCode)).catch(abandon);
29419
29517
  if (accessTokenKind(token) === "standard") {
29420
29518
  const given = token;
@@ -29427,6 +29525,7 @@ async function login(args) {
29427
29525
  if (!await tokenStillWorks(syncServer, given)) return fail(`Could not swap the access token for an Agent Token (${reason}), and the access token you gave no longer works. Run login again with an Agent Setup Code.`);
29428
29526
  return fail(`Could not swap the access token for an Agent Token (${reason}). Nothing was kept on this computer: run login again.`);
29429
29527
  });
29528
+ console.log("");
29430
29529
  console.log(`The access token you gave has been revoked. This computer now holds an Agent Token, limited to the routes an agent needs. If you used that access token anywhere else, create a new one at ${syncServer}/account/tokens.`);
29431
29530
  }
29432
29531
  if (previous) {
@@ -29434,7 +29533,10 @@ async function login(args) {
29434
29533
  if (before && before.pat !== token && await revokeHeldToken({
29435
29534
  syncServer,
29436
29535
  token: before.pat
29437
- })) console.log(`Revoked the token this computer held for ${syncServer} before this login.`);
29536
+ })) {
29537
+ console.log("");
29538
+ console.log(`Revoked the token this computer held for ${syncServer} before this login.`);
29539
+ }
29438
29540
  }
29439
29541
  const where = await saveLogin({
29440
29542
  config,
@@ -29446,11 +29548,19 @@ async function login(args) {
29446
29548
  },
29447
29549
  keychain: keychain()
29448
29550
  });
29551
+ console.log("");
29449
29552
  console.log(where === path ? `Encryption Keys unlocked and kept in ${path} (owner-only). Anyone who can read your files on this machine can read this account, as with a signed-in browser. Never let an agent read, print or search that file.` : `Encryption Keys unlocked and kept in ${where}; ${path} names only the server. A program you run can still ask ${where} for them, so run only agents you trust with this account.`);
29450
29553
  const others = Object.keys(config.servers).filter((server) => server !== syncServer);
29451
- if (others.length > 0) console.log(`Also logged in to ${others.join(", ")} - commands now need --sync-server <url> to say which.`);
29554
+ if (others.length > 0) {
29555
+ console.log("");
29556
+ console.log(`Also logged in to ${others.join(", ")} - commands now need --sync-server <url> to say which.`);
29557
+ }
29452
29558
  const restarted = await stopHosts(process.env, "a new login for its server", ({ status }) => status.target.kind === "synced" && status.target.server === syncServer);
29453
- if (restarted.length > 0) console.log(`Stopped the background process of ${restarted.length === 1 ? "one graph" : `${restarted.length} graphs`} served with the previous login. Agents start a new one with this login on their next call.`);
29559
+ if (restarted.length > 0) {
29560
+ console.log("");
29561
+ console.log(`Stopped the background process of ${restarted.length === 1 ? "one graph" : `${restarted.length} graphs`} served with the previous login. Agents start a new one with this login on their next call.`);
29562
+ }
29563
+ console.log("");
29454
29564
  await listGraphs({
29455
29565
  syncServer,
29456
29566
  pat: token,
@@ -29491,7 +29601,8 @@ async function approveOrFallBack(account, byRecoveryCode) {
29491
29601
  const onSignal = (name) => controls.onSignal(name);
29492
29602
  for (const name of quitSignals) process.once(name, onSignal);
29493
29603
  if (interactive) {
29494
- console.log("(Press r to type your Recovery Code instead.)");
29604
+ console.log("");
29605
+ console.log("**Press r to type your Recovery Code instead.**");
29495
29606
  stdin.setRawMode(true);
29496
29607
  } else stdin.on("end", onInputEnd);
29497
29608
  stdin.resume();
@@ -29516,6 +29627,7 @@ async function approveOrFallBack(account, byRecoveryCode) {
29516
29627
  if (!abandoned) throw new Error("unreachable");
29517
29628
  if (controls.mismatched) fail("The codes did not match, so the request was cancelled. Something between this computer and your other device may have interfered. Run login again, or pass --recovery-code.");
29518
29629
  if (controls.inputClosed) fail("Device approval needs someone to confirm the code it shows. Run login in a terminal and press y when the codes match, or pass --recovery-code, or set ETHERPK_RECOVERY_CODE.");
29630
+ console.log("");
29519
29631
  console.log("Approval cancelled - unlocking with your Recovery Code instead.");
29520
29632
  return byRecoveryCode();
29521
29633
  }