@indexnetwork/cli 0.9.2 → 0.9.5

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.
Files changed (2) hide show
  1. package/dist/index.js +40 -24
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -353,10 +353,10 @@ class ApiClient {
353
353
  async leaveNetwork(id) {
354
354
  await this.post(`/api/indexes/${id}/leave`, {});
355
355
  }
356
- async searchUsers(query, indexId) {
356
+ async searchUsers(query, networkId) {
357
357
  const params = new URLSearchParams({ q: query });
358
- if (indexId)
359
- params.set("indexId", indexId);
358
+ if (networkId)
359
+ params.set("indexId", networkId);
360
360
  const res = await this.get(`/api/indexes/search-users?${params.toString()}`);
361
361
  const body = await res.json();
362
362
  return body.users;
@@ -477,11 +477,12 @@ async function handleLogin(apiUrl, appUrl, store, options = {}) {
477
477
  const timeoutMs = options.timeoutMs ?? 120000;
478
478
  const baseUrl = apiUrl.replace(/\/$/, "");
479
479
  const baseAppUrl = appUrl.replace(/\/$/, "");
480
+ const callbackHost = options.callbackHost ?? "127.0.0.1";
480
481
  let resolveCallback;
481
482
  const callbackPromise = new Promise((resolve) => {
482
483
  resolveCallback = resolve;
483
484
  });
484
- const server = createServer(async (req, res) => {
485
+ const server = (options.serverFactory ?? createServer)(async (req, res) => {
485
486
  const url = new URL(req.url ?? "/", `http://localhost`);
486
487
  if (url.pathname === "/callback") {
487
488
  const sessionToken = url.searchParams.get("session_token");
@@ -504,11 +505,11 @@ async function handleLogin(apiUrl, appUrl, store, options = {}) {
504
505
  res.end("Not Found");
505
506
  });
506
507
  await new Promise((resolve) => {
507
- server.listen(0, () => resolve());
508
+ server.listen(0, callbackHost, () => resolve());
508
509
  });
509
510
  const addr = server.address();
510
511
  const port = typeof addr === "object" && addr ? addr.port : 0;
511
- const callbackUrl = `http://localhost:${port}/callback`;
512
+ const callbackUrl = `http://${callbackHost}:${port}/callback`;
512
513
  const authUrl = `${baseAppUrl}/cli-auth?callback=${encodeURIComponent(callbackUrl)}`;
513
514
  const timeout = setTimeout(() => {
514
515
  resolveCallback({
@@ -688,7 +689,8 @@ function wordWrap(text, maxWidth) {
688
689
  return lines;
689
690
  }
690
691
  function confidenceBar(confidence) {
691
- const pct = Math.round(confidence);
692
+ const normalized = confidence <= 1 ? confidence * 100 : confidence;
693
+ const pct = Math.round(normalized);
692
694
  const filled = Math.round(pct / 10);
693
695
  const empty = 10 - filled;
694
696
  return `${GREEN}${"#".repeat(filled)}${GRAY}${"-".repeat(empty)}${RESET} ${GRAY}${pct}%`;
@@ -1598,7 +1600,7 @@ async function handleIntent(client, subcommand, options) {
1598
1600
  }
1599
1601
  const result = await client.callTool("create_intent_index", {
1600
1602
  intentId: options.intentId,
1601
- indexId: options.targetId
1603
+ networkId: options.targetId
1602
1604
  });
1603
1605
  if (options.json) {
1604
1606
  console.log(JSON.stringify(result));
@@ -1618,7 +1620,7 @@ async function handleIntent(client, subcommand, options) {
1618
1620
  }
1619
1621
  const result = await client.callTool("delete_intent_index", {
1620
1622
  intentId: options.intentId,
1621
- indexId: options.targetId
1623
+ networkId: options.targetId
1622
1624
  });
1623
1625
  if (options.json) {
1624
1626
  console.log(JSON.stringify(result));
@@ -1654,7 +1656,7 @@ async function handleIntent(client, subcommand, options) {
1654
1656
  } else {
1655
1657
  for (const idx of data.indexes) {
1656
1658
  const score = idx.relevancyScore !== undefined ? ` (${idx.relevancyScore.toFixed(2)})` : "";
1657
- console.log(` ${idx.title} ${DIM}${idx.indexId.slice(0, 8)}${score}${RESET}`);
1659
+ console.log(` ${idx.title} ${DIM}${idx.networkId.slice(0, 8)}${score}${RESET}`);
1658
1660
  }
1659
1661
  }
1660
1662
  console.log();
@@ -1803,7 +1805,8 @@ async function opportunityStatusUpdate(client, id, status2, json) {
1803
1805
  success(`Opportunity ${status2 === "accepted" ? "accepted" : "rejected"}.`);
1804
1806
  }
1805
1807
  async function discoverIntroduction(client, userA, userB, hint, json) {
1806
- info("Gathering data for introduction...");
1808
+ if (!json)
1809
+ info("Gathering data for introduction...");
1807
1810
  const [membershipsA, membershipsB] = await Promise.all([
1808
1811
  client.callTool("read_index_memberships", { userId: userA }),
1809
1812
  client.callTool("read_index_memberships", { userId: userB })
@@ -1819,8 +1822,8 @@ async function discoverIntroduction(client, userA, userB, hint, json) {
1819
1822
  }
1820
1823
  const indexesA = membershipsA.data?.memberships ?? membershipsA.data?.indexes ?? [];
1821
1824
  const indexesB = membershipsB.data?.memberships ?? membershipsB.data?.indexes ?? [];
1822
- const idsA = new Set(indexesA.map((m) => m.indexId));
1823
- const shared = indexesB.filter((m) => idsA.has(m.indexId));
1825
+ const idsA = new Set(indexesA.map((m) => m.networkId));
1826
+ const shared = indexesB.filter((m) => idsA.has(m.networkId));
1824
1827
  if (shared.length === 0) {
1825
1828
  const err = "No shared indexes found between these users. They must be members of at least one common network.";
1826
1829
  if (json) {
@@ -1830,14 +1833,25 @@ async function discoverIntroduction(client, userA, userB, hint, json) {
1830
1833
  error(err, 1);
1831
1834
  return;
1832
1835
  }
1833
- const sharedIndexId = shared[0].indexId;
1834
- dim(` Found shared network: ${sharedIndexId}`);
1836
+ const sharedNetworkId = shared[0].networkId;
1837
+ if (!json)
1838
+ dim(` Found shared network: ${sharedNetworkId}`);
1835
1839
  const [profileA, profileB, intentsA, intentsB] = await Promise.all([
1836
1840
  client.callTool("read_user_profiles", { userId: userA }),
1837
1841
  client.callTool("read_user_profiles", { userId: userB }),
1838
- client.callTool("read_intents", { userId: userA, indexId: sharedIndexId }),
1839
- client.callTool("read_intents", { userId: userB, indexId: sharedIndexId })
1842
+ client.callTool("read_intents", { userId: userA, networkId: sharedNetworkId }),
1843
+ client.callTool("read_intents", { userId: userB, networkId: sharedNetworkId })
1840
1844
  ]);
1845
+ const gatherError = profileA.error ?? profileB.error ?? intentsA.error ?? intentsB.error;
1846
+ if (!profileA.success || !profileB.success || !intentsA.success || !intentsB.success) {
1847
+ const err = gatherError ?? "Failed to gather profiles and intents for introduction.";
1848
+ if (json) {
1849
+ console.log(JSON.stringify({ success: false, error: err }));
1850
+ return;
1851
+ }
1852
+ error(err, 1);
1853
+ return;
1854
+ }
1841
1855
  const extractProfile = (result2) => {
1842
1856
  if (!result2.success || !result2.data)
1843
1857
  return;
@@ -1854,10 +1868,11 @@ async function discoverIntroduction(client, userA, userB, hint, json) {
1854
1868
  return d.intents?.map((i) => ({ intentId: i.intentId ?? i.id ?? "", payload: i.payload, summary: i.summary }));
1855
1869
  };
1856
1870
  const entities = [
1857
- { userId: userA, profile: extractProfile(profileA), intents: extractIntents(intentsA), indexId: sharedIndexId },
1858
- { userId: userB, profile: extractProfile(profileB), intents: extractIntents(intentsB), indexId: sharedIndexId }
1871
+ { userId: userA, profile: extractProfile(profileA), intents: extractIntents(intentsA), networkId: sharedNetworkId },
1872
+ { userId: userB, profile: extractProfile(profileB), intents: extractIntents(intentsB), networkId: sharedNetworkId }
1859
1873
  ];
1860
- dim(" Profiles and intents gathered. Creating introduction...");
1874
+ if (!json)
1875
+ dim(" Profiles and intents gathered. Creating introduction...");
1861
1876
  const result = await client.callTool("create_opportunities", {
1862
1877
  partyUserIds: [userA, userB],
1863
1878
  entities,
@@ -2007,7 +2022,7 @@ async function networkUpdate(client, id, options, json) {
2007
2022
  error("Provide at least --title or --prompt. Usage: index network update <id> [--title <t>] [--prompt <p>]", 1);
2008
2023
  return;
2009
2024
  }
2010
- const result = await client.callTool("update_index", { indexId: id, settings });
2025
+ const result = await client.callTool("update_index", { networkId: id, settings });
2011
2026
  if (json) {
2012
2027
  console.log(JSON.stringify(result));
2013
2028
  return;
@@ -2023,7 +2038,7 @@ async function networkDelete(client, id, json) {
2023
2038
  error("Usage: index network delete <id>", 1);
2024
2039
  return;
2025
2040
  }
2026
- const result = await client.callTool("delete_index", { indexId: id });
2041
+ const result = await client.callTool("delete_index", { networkId: id });
2027
2042
  if (json) {
2028
2043
  console.log(JSON.stringify(result));
2029
2044
  return;
@@ -2569,7 +2584,8 @@ async function handleScrape(client, positionals, options) {
2569
2584
  error("Usage: index scrape <url> [--objective <text>]", 1);
2570
2585
  return;
2571
2586
  }
2572
- info(`Scraping ${url}...`);
2587
+ if (!options.json)
2588
+ info(`Scraping ${url}...`);
2573
2589
  const result = await client.callTool("scrape_url", { url, objective: options.objective });
2574
2590
  if (options.json) {
2575
2591
  console.log(JSON.stringify(result));
@@ -2648,7 +2664,7 @@ async function onboardingComplete(client, json) {
2648
2664
  // src/main.ts
2649
2665
  var DEFAULT_API_URL = "https://protocol.index.network";
2650
2666
  var DEFAULT_APP_URL = "https://index.network";
2651
- var VERSION = "0.9.2";
2667
+ var VERSION = "0.9.5";
2652
2668
  var HELP_TEXT = `
2653
2669
  Index CLI v${VERSION}
2654
2670
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indexnetwork/cli",
3
- "version": "0.9.2",
3
+ "version": "0.9.5",
4
4
  "description": "Command-line interface for Index Network",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,10 +20,10 @@
20
20
  "publish:all": "bun scripts/publish.ts"
21
21
  },
22
22
  "optionalDependencies": {
23
- "@indexnetwork/cli-linux-x64": "0.9.2",
24
- "@indexnetwork/cli-linux-arm64": "0.9.2",
25
- "@indexnetwork/cli-darwin-x64": "0.9.2",
26
- "@indexnetwork/cli-darwin-arm64": "0.9.2"
23
+ "@indexnetwork/cli-linux-x64": "0.9.5",
24
+ "@indexnetwork/cli-linux-arm64": "0.9.5",
25
+ "@indexnetwork/cli-darwin-x64": "0.9.5",
26
+ "@indexnetwork/cli-darwin-arm64": "0.9.5"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/bun": "latest"