lilac-graph 0.1.0 → 0.1.2

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.
@@ -1309,19 +1309,22 @@ var ApiError = class extends Error {
1309
1309
  code;
1310
1310
  version;
1311
1311
  };
1312
+ function apiError(status, text) {
1313
+ const parsed = text ? JSON.parse(text) : void 0;
1314
+ return new ApiError(
1315
+ status,
1316
+ parsed?.error ?? "http_error",
1317
+ parsed?.message ?? `The server answered ${status}`,
1318
+ typeof parsed?.version === "number" ? parsed.version : void 0
1319
+ );
1320
+ }
1312
1321
  function controlPlane({ server, token, fetch }) {
1313
1322
  async function send(method, route, headers, body) {
1314
1323
  if (token) headers.authorization = `Bearer ${token}`;
1315
1324
  const response = await fetch(`${server}${route}`, { method, headers, body });
1316
1325
  const text = await response.text();
1317
1326
  if (response.status >= 200 && response.status < 300) return text;
1318
- const parsed = text ? JSON.parse(text) : void 0;
1319
- throw new ApiError(
1320
- response.status,
1321
- parsed?.error ?? "http_error",
1322
- parsed?.message ?? `The server answered ${response.status}`,
1323
- typeof parsed?.version === "number" ? parsed.version : void 0
1324
- );
1327
+ throw apiError(response.status, text);
1325
1328
  }
1326
1329
  async function call(method, route, body) {
1327
1330
  const headers = { accept: "application/json" };
@@ -1341,6 +1344,7 @@ function controlPlane({ server, token, fetch }) {
1341
1344
  machines: () => call("GET", "/v1/machines"),
1342
1345
  revokeMachine: (id) => call("DELETE", `/v1/machines/${encodeURIComponent(id)}`),
1343
1346
  environments: () => call("GET", "/v1/environments"),
1347
+ /** With `projectId` the environment joins that synced project; it needs `gitUrl`, and a worker on protocol 2 (else 409 `worker_too_old`). */
1344
1348
  createProject: (id, body) => call("POST", `${env(id)}/projects`, body),
1345
1349
  closeProject: (id, path2) => call("POST", `${env(id)}/projects/close`, { path: path2 }),
1346
1350
  /** The caller's saved teams. */
@@ -1355,10 +1359,21 @@ function controlPlane({ server, token, fetch }) {
1355
1359
  pullGraph: (name, since) => call("GET", `/v1/graphs/${encodeURIComponent(name)}?since=${since}`),
1356
1360
  /** A stale `baseRev` is a 409 with code `stale`. The caller pulls and tries again. */
1357
1361
  pushGraph: (name, body) => call("POST", `/v1/graphs/${encodeURIComponent(name)}/push`, body),
1362
+ /** The caller's synced projects. */
1363
+ syncProjects: () => call("GET", "/v1/projects"),
1364
+ createSyncProject: (name) => call("POST", "/v1/projects", { name }),
1365
+ /** Removes the platform's copy of the chat. Every machine keeps its own file. */
1366
+ deleteSyncProject: (id) => call("DELETE", `/v1/projects/${encodeURIComponent(id)}`),
1367
+ syncProject: (id) => call("GET", `/v1/projects/${encodeURIComponent(id)}`),
1368
+ /** Where agents run. A bad machine (not an environment, or revoked) is a 400. `rev` bumps on the change. */
1369
+ patchSyncProject: (id, body) => call("PATCH", `/v1/projects/${encodeURIComponent(id)}`, body),
1370
+ sendLines: (id, body) => call("POST", `/v1/projects/${encodeURIComponent(id)}/lines`, body),
1371
+ /** Waits up to `wait` seconds (at most 25) for a line after `after`, so a new one arrives within seconds. */
1372
+ pullLines: (id, after, wait = 0) => call("GET", `/v1/projects/${encodeURIComponent(id)}/lines?after=${after}&wait=${wait}`),
1358
1373
  /** The graphs this token reaches. */
1359
1374
  graphs: () => call("GET", "/v1/graphs"),
1360
1375
  /** Make a graph with its one line `about`. One that exists keeps its rows and takes the new line. */
1361
- putGraph: (name, about) => call("PUT", graph(name), { about }),
1376
+ putGraph: (name, about) => call("PUT", graph(name), about === void 0 ? {} : { about }),
1362
1377
  /** Set the one line of a group (a tag path such as `tasks/design`). Empty text removes it. */
1363
1378
  putGroup: (name, path2, about) => call(
1364
1379
  "PUT",
@@ -1377,6 +1392,8 @@ function controlPlane({ server, token, fetch }) {
1377
1392
  editRow: (name, id, edit) => call("PATCH", `${graph(name)}/rows/${encodeURIComponent(id)}`, edit),
1378
1393
  /** A row for a web link; the same link twice is one row. */
1379
1394
  addLink: (name, body) => call("POST", `${graph(name)}/rows`, body),
1395
+ /** A token for one graph that exists. The app login may make nothing broader: that is a 403. */
1396
+ createApiToken: (body) => call("POST", "/v1/api-tokens", body),
1380
1397
  /** Path, row and sha256 of every original in the graph. */
1381
1398
  listFiles: (name) => call("GET", `${graph(name)}/files`),
1382
1399
  /** One file at `path` as a row. The same bytes again change nothing; `group` places a new row only. */
@@ -1395,6 +1412,15 @@ function controlPlane({ server, token, fetch }) {
1395
1412
  )
1396
1413
  );
1397
1414
  },
1415
+ /** The file a row is, as stored. A row with none is a 404. */
1416
+ getOriginal: async (name, id) => {
1417
+ const response = await fetch(`${server}${rowFile(name, id, "original")}`, {
1418
+ method: "GET",
1419
+ headers: token ? { authorization: `Bearer ${token}` } : {}
1420
+ });
1421
+ if (response.status !== 200) throw apiError(response.status, await response.text());
1422
+ return new Uint8Array(await response.arrayBuffer());
1423
+ },
1398
1424
  /** A row's HTML artefact, as stored. A row with none is a 404. */
1399
1425
  getArtefact: (name, id) => send("GET", rowFile(name, id, "artefact"), { accept: "text/html" }),
1400
1426
  /** Replace the artefact if it is still the version `base` names; else a 412 with code `changed`. */
@@ -1598,7 +1624,7 @@ var GUIDE = [
1598
1624
  "",
1599
1625
  "1. `lilac-graph map` shows what the graph is about, its groups, its newest rows and its size. If it says the graph is small enough to read whole, `read` every row and skip the rest.",
1600
1626
  '2. `lilac-graph search "your question in plain words"` returns the best passages, each with its row, its part number and a link. `--exact` finds an exact string. `--limit 1-25` caps the hits and `--budget 200-20000` the answer size in tokens.',
1601
- "3. `lilac-graph read <row> --part <n>` reads one part of a row, and `--part 3-5` a range. `read <row>` alone lists the parts, the summary and the related rows.",
1627
+ "3. `lilac-graph read <row> --part <n>` reads one part of a row, and `--part 3-5` a range. `read <row>` alone lists the parts, the summary and the related rows, and shows the text itself when the row has one part.",
1602
1628
  "4. Follow links: `read` the rows named under `related` or `One step away`, then search again with new words.",
1603
1629
  "",
1604
1630
  "Cite a row by its link. If nothing matches, say so. Do not guess.",
@@ -1607,10 +1633,11 @@ var GUIDE = [
1607
1633
  "",
1608
1634
  " lilac-graph add ./notes --group tasks",
1609
1635
  "",
1610
- "- One row per file, known by its path (`notes/a.md`). Run it again and nothing changes. A changed file updates its row.",
1636
+ "- One row per file, known by its path (`notes/a.md`). Run it again and nothing changes. A changed file updates its row; `--group` places new rows only, so move a row with `set`.",
1611
1637
  "- A folder is walked. Hidden files, `node_modules` and what `.gitignore` lists are skipped. A subfolder becomes a subgroup.",
1612
1638
  "- A link from one Markdown file to another becomes a related link.",
1613
1639
  "- `lilac-graph add https://example.com/page` adds a web link. `--dry-run` shows what would be added.",
1640
+ "- When adding a paper, give it a real `--title`, then `set` a summary and `--relate` the rows it belongs with. Related links are drawn from the summary, and a bare URL only gets citations.",
1614
1641
  "- Text is read from Markdown, plain text, code, HTML and PDF. Other files are found by title and summary only.",
1615
1642
  '- `lilac-graph new <name> --about "One line"` makes a graph.',
1616
1643
  "",
@@ -1662,7 +1689,8 @@ function explain(error, prog, server) {
1662
1689
  429: ["Too many requests. Wait a moment, then run the command again.", 1]
1663
1690
  };
1664
1691
  const [hint, code2] = next[error.status] ?? ["", 1];
1665
- throw new GraphError([error.message.replace(/\.$/, ""), hint].filter(Boolean).join(". "), code2);
1692
+ const useHint = error.status !== 403 || !error.message;
1693
+ throw new GraphError([error.message.replace(/\.$/, ""), useHint && hint].filter(Boolean).join(". "), code2);
1666
1694
  }
1667
1695
  var renderGroups = (groups, indent = "") => groups.flatMap((group) => [
1668
1696
  `${indent}${group.path} (${group.count})${group.about ? ` ${group.about}` : ""}`,
@@ -1675,6 +1703,7 @@ function renderMap(map) {
1675
1703
  const newest = map.newest.map((row) => ` ${row.row} ${row.title} ${row.date}`);
1676
1704
  return [
1677
1705
  `${map.name}${map.about ? ` ${map.about}` : ""}`,
1706
+ map.url,
1678
1707
  `${map.rows} ${map.rows === 1 ? "row" : "rows"}, ${size}`,
1679
1708
  ...groups.length ? ["", "Groups:", ...groups] : [],
1680
1709
  ...newest.length ? ["", "Newest:", ...newest] : []
@@ -1761,15 +1790,15 @@ var COMMANDS = {
1761
1790
  async run({ api, args: [name], flags }) {
1762
1791
  if (!NAME.test(name))
1763
1792
  throw new GraphError("A graph name is letters, digits, . _ - and at most 64 characters.", 2);
1764
- const about = (flags.about ?? "").trim();
1765
- if (/[\r\n]/.test(about) || about.length > ABOUT_MAX)
1793
+ const about = flags.about?.trim();
1794
+ if (about !== void 0 && (/[\r\n]/.test(about) || about.length > ABOUT_MAX))
1766
1795
  throw new GraphError(`--about is one line of at most ${ABOUT_MAX} characters.`, 2);
1767
1796
  if (flags["dry-run"]) return `Would make graph ${name}${about ? `: ${about}` : ""}`;
1768
1797
  const { created } = await api().putGraph(name, about);
1769
1798
  return render(
1770
1799
  flags,
1771
1800
  { name, created },
1772
- () => created ? `Made graph ${name}` : `Graph ${name} already exists. \`map\` shows what it holds.`
1801
+ () => created ? `Made graph ${name}` : `Graph ${name} already exists, rows kept${about ? "; its line is now the one you gave" : ""}. \`map\` shows what it holds.`
1773
1802
  );
1774
1803
  }
1775
1804
  },
@@ -1824,7 +1853,9 @@ var COMMANDS = {
1824
1853
  return render(flags, part, () => renderPart(part));
1825
1854
  }
1826
1855
  const row = await api().readRow(graph(), id);
1827
- return render(flags, row, () => renderRow(row));
1856
+ const only = row.parts.length === 1 ? await api().readPart(graph(), id, "1") : void 0;
1857
+ return render(flags, row, () => [renderRow(row), only && `
1858
+ ${only.text}`].filter(Boolean).join("\n"));
1828
1859
  }
1829
1860
  },
1830
1861
  set: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lilac-graph",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Fill and read a Lilac knowledge graph from any agent: map, search, read, add, set. One file, no dependencies, needs only Node.",