@ilivemylife/graph-sdk 1.0.3 → 1.0.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.
package/dist/cli.mjs CHANGED
@@ -523,7 +523,7 @@ function createApolloClient(options) {
523
523
  const { token, httpUrl, wsUrl, enableSubscriptions, webSocketImpl } = options;
524
524
  const requestHeaders = {
525
525
  "access-token": token,
526
- "x-client": `sdk/${"1.0.3"}`
526
+ "x-client": `sdk/${"1.0.5"}`
527
527
  };
528
528
  const httpLink = createHttpLink({
529
529
  uri: httpUrl,
@@ -536,7 +536,7 @@ function createApolloClient(options) {
536
536
  if (enableSubscriptions) {
537
537
  const wsClientOptions = {
538
538
  url: wsUrl,
539
- connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.3"}` }
539
+ connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.5"}` }
540
540
  };
541
541
  if (webSocketImpl) {
542
542
  wsClientOptions.webSocketImpl = webSocketImpl;
@@ -1068,41 +1068,16 @@ function createGraphClient(options) {
1068
1068
  }
1069
1069
 
1070
1070
  // src/cli.ts
1071
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
1072
- import { homedir } from "os";
1071
+ import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
1072
+ import { join as join2 } from "path";
1073
+
1074
+ // src/config.ts
1075
+ import { existsSync, readFileSync, writeFileSync as writeFileSync2, mkdirSync } from "fs";
1073
1076
  import { join } from "path";
1074
- async function resolveTextValue(value) {
1075
- if (!value) return void 0;
1076
- if (value === "-") {
1077
- return readFromStdin();
1078
- }
1079
- if (value.startsWith("@")) {
1080
- const filePath = value.slice(1);
1081
- if (!existsSync(filePath)) {
1082
- throw new Error(`File not found: ${filePath}`);
1083
- }
1084
- return readFileSync(filePath, "utf-8");
1085
- }
1086
- return value;
1087
- }
1088
- async function readFromStdin() {
1089
- return new Promise((resolve, reject) => {
1090
- let data = "";
1091
- if (process.stdin.isTTY) {
1092
- reject(new Error("No input from stdin. Pipe content or use @filename instead."));
1093
- return;
1094
- }
1095
- process.stdin.setEncoding("utf8");
1096
- process.stdin.on("data", (chunk) => {
1097
- data += chunk;
1098
- });
1099
- process.stdin.on("end", () => resolve(data));
1100
- process.stdin.on("error", reject);
1101
- });
1102
- }
1077
+ import { homedir as homedir2 } from "os";
1103
1078
  var CONFIG_DIRNAME = ".ilivemylife";
1104
1079
  var CONFIG_FILENAME = "config.json";
1105
- var GLOBAL_CONFIG_DIR = join(homedir(), CONFIG_DIRNAME);
1080
+ var GLOBAL_CONFIG_DIR = join(homedir2(), CONFIG_DIRNAME);
1106
1081
  var GLOBAL_CONFIG_FILE = join(GLOBAL_CONFIG_DIR, CONFIG_FILENAME);
1107
1082
  function findLocalConfigFile(startDir = process.cwd()) {
1108
1083
  let dir = startDir;
@@ -1118,30 +1093,59 @@ function findLocalConfigFile(startDir = process.cwd()) {
1118
1093
  }
1119
1094
  return null;
1120
1095
  }
1121
- function loadConfig() {
1096
+ function loadLocalConfig() {
1122
1097
  const localConfigFile = findLocalConfigFile();
1123
1098
  if (localConfigFile) {
1124
1099
  try {
1125
1100
  return JSON.parse(readFileSync(localConfigFile, "utf-8"));
1126
- } catch (error) {
1127
- console.error("Warning: Could not load local config:", error.message);
1101
+ } catch {
1102
+ return null;
1128
1103
  }
1129
1104
  }
1105
+ return null;
1106
+ }
1107
+ function loadGlobalConfig() {
1130
1108
  try {
1131
1109
  if (existsSync(GLOBAL_CONFIG_FILE)) {
1132
1110
  return JSON.parse(readFileSync(GLOBAL_CONFIG_FILE, "utf-8"));
1133
1111
  }
1134
- } catch (error) {
1135
- console.error("Warning: Could not load global config:", error.message);
1112
+ } catch {
1113
+ }
1114
+ return null;
1115
+ }
1116
+ function loadConfig() {
1117
+ return loadLocalConfig() || loadGlobalConfig() || {};
1118
+ }
1119
+ function readEnvToken() {
1120
+ const envPath = join(process.cwd(), ".env");
1121
+ if (!existsSync(envPath)) return void 0;
1122
+ try {
1123
+ const content = readFileSync(envPath, "utf-8");
1124
+ const match = content.match(/^ILML_TOKEN\s*=\s*["']?([^"'\r\n]+)["']?/m);
1125
+ return match ? match[1].trim() : void 0;
1126
+ } catch {
1127
+ return void 0;
1136
1128
  }
1137
- return {};
1129
+ }
1130
+ function resolveToken() {
1131
+ return resolveTokenWithSource().token;
1132
+ }
1133
+ function resolveTokenWithSource() {
1134
+ const localConfig = loadLocalConfig();
1135
+ if (localConfig?.token) return { token: localConfig.token, source: "local" };
1136
+ const envToken = readEnvToken();
1137
+ if (envToken) return { token: envToken, source: "env-file" };
1138
+ const globalConfig = loadGlobalConfig();
1139
+ if (globalConfig?.token) return { token: globalConfig.token, source: "global" };
1140
+ if (process.env.ILML_TOKEN) return { token: process.env.ILML_TOKEN, source: "env-var" };
1141
+ return { token: void 0, source: null };
1138
1142
  }
1139
1143
  function saveConfig(config) {
1140
1144
  try {
1141
1145
  if (!existsSync(GLOBAL_CONFIG_DIR)) {
1142
1146
  mkdirSync(GLOBAL_CONFIG_DIR, { recursive: true });
1143
1147
  }
1144
- writeFileSync(GLOBAL_CONFIG_FILE, JSON.stringify(config, null, 2));
1148
+ writeFileSync2(GLOBAL_CONFIG_FILE, JSON.stringify(config, null, 2));
1145
1149
  return true;
1146
1150
  } catch (error) {
1147
1151
  console.error("Failed to save config:", error.message);
@@ -1155,35 +1159,49 @@ function saveConfigLocal(config) {
1155
1159
  if (!existsSync(localDir)) {
1156
1160
  mkdirSync(localDir, { recursive: true });
1157
1161
  }
1158
- writeFileSync(localFile, JSON.stringify(config, null, 2));
1162
+ writeFileSync2(localFile, JSON.stringify(config, null, 2));
1159
1163
  return localFile;
1160
1164
  } catch (error) {
1161
1165
  console.error("Failed to save local config:", error.message);
1162
1166
  return null;
1163
1167
  }
1164
1168
  }
1165
- function readEnvToken() {
1166
- const envPath = join(process.cwd(), ".env");
1167
- if (!existsSync(envPath)) return void 0;
1168
- try {
1169
- const content = readFileSync(envPath, "utf-8");
1170
- const match = content.match(/^ILML_TOKEN\s*=\s*["']?([^"'\r\n]+)["']?/m);
1171
- return match ? match[1].trim() : void 0;
1172
- } catch {
1173
- return void 0;
1169
+
1170
+ // src/cli.ts
1171
+ async function resolveTextValue(value) {
1172
+ if (!value) return void 0;
1173
+ if (value === "-") {
1174
+ return readFromStdin();
1175
+ }
1176
+ if (value.startsWith("@")) {
1177
+ const filePath = value.slice(1);
1178
+ if (!existsSync2(filePath)) {
1179
+ throw new Error(`File not found: ${filePath}`);
1180
+ }
1181
+ return readFileSync2(filePath, "utf-8");
1174
1182
  }
1183
+ return value;
1175
1184
  }
1176
- function getStoredToken() {
1177
- const config = loadConfig();
1178
- if (config.token) return config.token;
1179
- const envToken = readEnvToken();
1180
- if (envToken) return envToken;
1181
- return process.env.ILML_TOKEN;
1185
+ async function readFromStdin() {
1186
+ return new Promise((resolve, reject) => {
1187
+ let data = "";
1188
+ if (process.stdin.isTTY) {
1189
+ reject(new Error("No input from stdin. Pipe content or use @filename instead."));
1190
+ return;
1191
+ }
1192
+ process.stdin.setEncoding("utf8");
1193
+ process.stdin.on("data", (chunk) => {
1194
+ data += chunk;
1195
+ });
1196
+ process.stdin.on("end", () => resolve(data));
1197
+ process.stdin.on("error", reject);
1198
+ });
1182
1199
  }
1200
+ var getStoredToken = resolveToken;
1183
1201
  function getActiveConfigPath() {
1184
1202
  const localConfig = findLocalConfigFile();
1185
1203
  if (localConfig) return localConfig + " (local)";
1186
- if (existsSync(GLOBAL_CONFIG_FILE)) return GLOBAL_CONFIG_FILE + " (global)";
1204
+ if (existsSync2(GLOBAL_CONFIG_FILE)) return GLOBAL_CONFIG_FILE + " (global)";
1187
1205
  return GLOBAL_CONFIG_FILE + " (not found)";
1188
1206
  }
1189
1207
  var _graph = null;
@@ -1563,7 +1581,7 @@ async function cmdLogout(args = []) {
1563
1581
  const forceGlobal = args.includes("--global") || args.includes("-g");
1564
1582
  const logoutAll = args.includes("--all") || args.includes("-a");
1565
1583
  const localConfigFile = findLocalConfigFile();
1566
- const globalConfigExists = existsSync(GLOBAL_CONFIG_FILE);
1584
+ const globalConfigExists = existsSync2(GLOBAL_CONFIG_FILE);
1567
1585
  let logoutFromLocal = false;
1568
1586
  let logoutFromGlobal = false;
1569
1587
  if (logoutAll) {
@@ -1595,7 +1613,7 @@ async function cmdLogout(args = []) {
1595
1613
  let loggedOutFrom = [];
1596
1614
  if (logoutFromLocal && localConfigFile) {
1597
1615
  try {
1598
- const localConfig = JSON.parse(readFileSync(localConfigFile, "utf-8"));
1616
+ const localConfig = JSON.parse(readFileSync2(localConfigFile, "utf-8"));
1599
1617
  const userName = localConfig.user?.displayName || localConfig.user?.email || "Unknown";
1600
1618
  delete localConfig.token;
1601
1619
  delete localConfig.user;
@@ -1608,7 +1626,7 @@ async function cmdLogout(args = []) {
1608
1626
  }
1609
1627
  if (logoutFromGlobal) {
1610
1628
  try {
1611
- const globalConfig = existsSync(GLOBAL_CONFIG_FILE) ? JSON.parse(readFileSync(GLOBAL_CONFIG_FILE, "utf-8")) : {};
1629
+ const globalConfig = existsSync2(GLOBAL_CONFIG_FILE) ? JSON.parse(readFileSync2(GLOBAL_CONFIG_FILE, "utf-8")) : {};
1612
1630
  const userName = globalConfig.user?.displayName || globalConfig.user?.email || "Unknown";
1613
1631
  delete globalConfig.token;
1614
1632
  delete globalConfig.user;
@@ -1650,14 +1668,21 @@ async function cmdMe() {
1650
1668
  console.log(`User ID: ${user.id || "N/A"}`);
1651
1669
  console.log(`Root node: ${user.rootItemId || "N/A"}`);
1652
1670
  console.log("\u2550".repeat(60));
1653
- if (user.rootItemId && (user.rootItemId !== config.rootItemId || !config.user?.displayName)) {
1654
- config.rootItemId = user.rootItemId;
1655
- config.user = {
1656
- id: user.id,
1657
- email: user.email,
1658
- displayName: name
1659
- };
1660
- saveConfig(config);
1671
+ const { source } = resolveTokenWithSource();
1672
+ if (source === "local" || source === "global") {
1673
+ if (user.rootItemId && (user.rootItemId !== config.rootItemId || !config.user?.displayName)) {
1674
+ config.rootItemId = user.rootItemId;
1675
+ config.user = {
1676
+ id: user.id,
1677
+ email: user.email,
1678
+ displayName: name
1679
+ };
1680
+ if (source === "local") {
1681
+ saveConfigLocal(config);
1682
+ } else {
1683
+ saveConfig(config);
1684
+ }
1685
+ }
1661
1686
  }
1662
1687
  } catch (error) {
1663
1688
  console.error("Token is invalid or expired:", error.message);
@@ -2358,7 +2383,7 @@ async function cmdUpdate() {
2358
2383
  const { execSync } = await import("child_process");
2359
2384
  console.log("Checking for updates...");
2360
2385
  try {
2361
- const currentVersion = "1.0.3";
2386
+ const currentVersion = "1.0.5";
2362
2387
  let latestVersion;
2363
2388
  try {
2364
2389
  const result = execSync("npm view @ilivemylife/graph-sdk version", { encoding: "utf-8" }).trim();
@@ -2388,21 +2413,23 @@ async function cmdDoctor() {
2388
2413
  console.log("\u2550".repeat(60));
2389
2414
  let issues = 0;
2390
2415
  console.log(`
2391
- [Version] ${"1.0.3"}`);
2416
+ [Version] ${"1.0.5"}`);
2392
2417
  const localConfigPath = findLocalConfigFile();
2393
- const globalExists = existsSync(GLOBAL_CONFIG_FILE);
2418
+ const globalExists = existsSync2(GLOBAL_CONFIG_FILE);
2394
2419
  console.log("\n[Config Files]");
2395
2420
  console.log(" Priority: local config > .env > global config > env var\n");
2421
+ const { source: activeSource } = resolveTokenWithSource();
2422
+ const envToken = readEnvToken();
2396
2423
  if (localConfigPath) {
2397
2424
  console.log(` Local config: ${localConfigPath}`);
2398
2425
  try {
2399
- const localData = JSON.parse(readFileSync(localConfigPath, "utf-8"));
2426
+ const localData = JSON.parse(readFileSync2(localConfigPath, "utf-8"));
2400
2427
  if (localData.user) {
2401
2428
  console.log(` User: ${localData.user.displayName || localData.user.email}`);
2402
2429
  }
2403
2430
  if (localData.token) {
2404
2431
  console.log(` Token: ${localData.token.substring(0, 10)}...`);
2405
- console.log(" \u2190 ACTIVE (takes priority)");
2432
+ if (activeSource === "local") console.log(" \u2190 ACTIVE");
2406
2433
  } else {
2407
2434
  console.log(' Token: (missing \u2014 run "ilml login --local")');
2408
2435
  }
@@ -2417,15 +2444,13 @@ async function cmdDoctor() {
2417
2444
  console.log(` Global config: ${GLOBAL_CONFIG_FILE}`);
2418
2445
  if (globalExists) {
2419
2446
  try {
2420
- const globalData = JSON.parse(readFileSync(GLOBAL_CONFIG_FILE, "utf-8"));
2447
+ const globalData = JSON.parse(readFileSync2(GLOBAL_CONFIG_FILE, "utf-8"));
2421
2448
  if (globalData.user) {
2422
2449
  console.log(` User: ${globalData.user.displayName || globalData.user.email}`);
2423
2450
  }
2424
2451
  if (globalData.token) {
2425
2452
  console.log(` Token: ${globalData.token.substring(0, 10)}...`);
2426
- if (!localConfigPath) {
2427
- console.log(" \u2190 ACTIVE");
2428
- }
2453
+ if (activeSource === "global") console.log(" \u2190 ACTIVE");
2429
2454
  } else {
2430
2455
  console.log(' Token: (missing \u2014 run "ilml login")');
2431
2456
  }
@@ -2437,15 +2462,12 @@ async function cmdDoctor() {
2437
2462
  console.log(` To create: ilml login`);
2438
2463
  }
2439
2464
  console.log("");
2440
- const envPath = join(process.cwd(), ".env");
2441
- const envToken = readEnvToken();
2465
+ const envPath = join2(process.cwd(), ".env");
2442
2466
  console.log(` .env file: ${envPath}`);
2443
- if (existsSync(envPath)) {
2467
+ if (existsSync2(envPath)) {
2444
2468
  if (envToken) {
2445
2469
  console.log(` ILML_TOKEN: ${envToken.substring(0, 10)}...`);
2446
- if (!localConfigPath) {
2447
- console.log(" \u2190 ACTIVE");
2448
- }
2470
+ if (activeSource === "env-file") console.log(" \u2190 ACTIVE");
2449
2471
  } else {
2450
2472
  console.log(" (exists but no ILML_TOKEN found)");
2451
2473
  }
@@ -2454,7 +2476,7 @@ async function cmdDoctor() {
2454
2476
  }
2455
2477
  console.log("");
2456
2478
  console.log(` ILML_TOKEN env: ${process.env.ILML_TOKEN ? `set (${process.env.ILML_TOKEN.substring(0, 10)}...)` : "not set"}`);
2457
- if (process.env.ILML_TOKEN && !localConfigPath && !envToken && !globalExists) {
2479
+ if (activeSource === "env-var") {
2458
2480
  console.log(" \u2190 ACTIVE");
2459
2481
  }
2460
2482
  const hasAnyAuth = localConfigPath || envToken || globalExists || process.env.ILML_TOKEN;
@@ -2508,7 +2530,7 @@ async function cmdUninstall() {
2508
2530
  console.log("\n[Step 1] Remove the npm package:");
2509
2531
  console.log(" npm uninstall -g @ilivemylife/graph-sdk");
2510
2532
  console.log("\n[Step 2] Remove global config (contains your token):");
2511
- if (existsSync(GLOBAL_CONFIG_DIR)) {
2533
+ if (existsSync2(GLOBAL_CONFIG_DIR)) {
2512
2534
  console.log(` Found: ${GLOBAL_CONFIG_DIR}`);
2513
2535
  try {
2514
2536
  const { readdirSync } = await import("fs");
@@ -2529,7 +2551,7 @@ async function cmdUninstall() {
2529
2551
  console.log("\n[Step 3] Remove local project configs (if any):");
2530
2552
  const localConfig = findLocalConfigFile();
2531
2553
  if (localConfig) {
2532
- const localDir = join(localConfig, "..");
2554
+ const localDir = join2(localConfig, "..");
2533
2555
  console.log(` Found in current project: ${localDir}`);
2534
2556
  console.log("\n To remove:");
2535
2557
  if (process.platform === "win32") {
@@ -2564,8 +2586,8 @@ async function cmdUninstall() {
2564
2586
  console.log(" (already clean)");
2565
2587
  }
2566
2588
  console.log("\n[Step 5] Remove MCP server config (if using Claude Code):");
2567
- const claudeSettingsPath = join(homedir(), ".claude", "settings.json");
2568
- if (existsSync(claudeSettingsPath)) {
2589
+ const claudeSettingsPath = join2(homedir(), ".claude", "settings.json");
2590
+ if (existsSync2(claudeSettingsPath)) {
2569
2591
  console.log(` Found: ${claudeSettingsPath}`);
2570
2592
  console.log(' Edit this file and remove "ilml" from "mcpServers"');
2571
2593
  } else {
@@ -2579,11 +2601,11 @@ async function cmdUninstall() {
2579
2601
  console.log("\u2550".repeat(60));
2580
2602
  }
2581
2603
  function showVersion() {
2582
- console.log(`@ilivemylife/graph-sdk v${"1.0.3"}`);
2604
+ console.log(`@ilivemylife/graph-sdk v${"1.0.5"}`);
2583
2605
  }
2584
2606
  function showHelp() {
2585
2607
  console.log(`
2586
- @ilivemylife/graph-sdk v${"1.0.3"}
2608
+ @ilivemylife/graph-sdk v${"1.0.5"}
2587
2609
  CLI for iLiveMyLife Knowledge Graph
2588
2610
 
2589
2611
  USAGE
package/dist/client.cjs CHANGED
@@ -623,7 +623,7 @@ function createApolloClient(options) {
623
623
  const { token, httpUrl, wsUrl, enableSubscriptions, webSocketImpl } = options;
624
624
  const requestHeaders = {
625
625
  "access-token": token,
626
- "x-client": `sdk/${"1.0.3"}`
626
+ "x-client": `sdk/${"1.0.5"}`
627
627
  };
628
628
  const httpLink = createHttpLink({
629
629
  uri: httpUrl,
@@ -636,7 +636,7 @@ function createApolloClient(options) {
636
636
  if (enableSubscriptions) {
637
637
  const wsClientOptions = {
638
638
  url: wsUrl,
639
- connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.3"}` }
639
+ connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.5"}` }
640
640
  };
641
641
  if (webSocketImpl) {
642
642
  wsClientOptions.webSocketImpl = webSocketImpl;
package/dist/client.mjs CHANGED
@@ -550,7 +550,7 @@ function createApolloClient(options) {
550
550
  const { token, httpUrl, wsUrl, enableSubscriptions, webSocketImpl } = options;
551
551
  const requestHeaders = {
552
552
  "access-token": token,
553
- "x-client": `sdk/${"1.0.3"}`
553
+ "x-client": `sdk/${"1.0.5"}`
554
554
  };
555
555
  const httpLink = createHttpLink({
556
556
  uri: httpUrl,
@@ -563,7 +563,7 @@ function createApolloClient(options) {
563
563
  if (enableSubscriptions) {
564
564
  const wsClientOptions = {
565
565
  url: wsUrl,
566
- connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.3"}` }
566
+ connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.5"}` }
567
567
  };
568
568
  if (webSocketImpl) {
569
569
  wsClientOptions.webSocketImpl = webSocketImpl;
@@ -8,9 +8,6 @@ import {
8
8
  ListToolsRequestSchema
9
9
  } from "@modelcontextprotocol/sdk/types.js";
10
10
  import { createRequire } from "module";
11
- import { existsSync, readFileSync } from "fs";
12
- import { join } from "path";
13
- import { homedir } from "os";
14
11
 
15
12
  // src/client.ts
16
13
  import apolloCore2 from "@apollo/client/core/core.cjs";
@@ -543,7 +540,7 @@ function createApolloClient(options) {
543
540
  const { token, httpUrl, wsUrl, enableSubscriptions, webSocketImpl } = options;
544
541
  const requestHeaders = {
545
542
  "access-token": token,
546
- "x-client": `sdk/${"1.0.3"}`
543
+ "x-client": `sdk/${"1.0.5"}`
547
544
  };
548
545
  const httpLink = createHttpLink({
549
546
  uri: httpUrl,
@@ -556,7 +553,7 @@ function createApolloClient(options) {
556
553
  if (enableSubscriptions) {
557
554
  const wsClientOptions = {
558
555
  url: wsUrl,
559
- connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.3"}` }
556
+ connectionParams: { "access-token": token, "x-client": `sdk/${"1.0.5"}` }
560
557
  };
561
558
  if (webSocketImpl) {
562
559
  wsClientOptions.webSocketImpl = webSocketImpl;
@@ -1087,6 +1084,73 @@ function createGraphClient(options) {
1087
1084
  return client;
1088
1085
  }
1089
1086
 
1087
+ // src/config.ts
1088
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
1089
+ import { join } from "path";
1090
+ import { homedir } from "os";
1091
+ var CONFIG_DIRNAME = ".ilivemylife";
1092
+ var CONFIG_FILENAME = "config.json";
1093
+ var GLOBAL_CONFIG_DIR = join(homedir(), CONFIG_DIRNAME);
1094
+ var GLOBAL_CONFIG_FILE = join(GLOBAL_CONFIG_DIR, CONFIG_FILENAME);
1095
+ function findLocalConfigFile(startDir = process.cwd()) {
1096
+ let dir = startDir;
1097
+ const root = process.platform === "win32" ? dir.split("\\")[0] + "\\" : "/";
1098
+ while (dir !== root) {
1099
+ const configPath = join(dir, CONFIG_DIRNAME, CONFIG_FILENAME);
1100
+ if (existsSync(configPath)) {
1101
+ return configPath;
1102
+ }
1103
+ const parent = join(dir, "..");
1104
+ if (parent === dir) break;
1105
+ dir = parent;
1106
+ }
1107
+ return null;
1108
+ }
1109
+ function loadLocalConfig() {
1110
+ const localConfigFile = findLocalConfigFile();
1111
+ if (localConfigFile) {
1112
+ try {
1113
+ return JSON.parse(readFileSync(localConfigFile, "utf-8"));
1114
+ } catch {
1115
+ return null;
1116
+ }
1117
+ }
1118
+ return null;
1119
+ }
1120
+ function loadGlobalConfig() {
1121
+ try {
1122
+ if (existsSync(GLOBAL_CONFIG_FILE)) {
1123
+ return JSON.parse(readFileSync(GLOBAL_CONFIG_FILE, "utf-8"));
1124
+ }
1125
+ } catch {
1126
+ }
1127
+ return null;
1128
+ }
1129
+ function readEnvToken() {
1130
+ const envPath = join(process.cwd(), ".env");
1131
+ if (!existsSync(envPath)) return void 0;
1132
+ try {
1133
+ const content = readFileSync(envPath, "utf-8");
1134
+ const match = content.match(/^ILML_TOKEN\s*=\s*["']?([^"'\r\n]+)["']?/m);
1135
+ return match ? match[1].trim() : void 0;
1136
+ } catch {
1137
+ return void 0;
1138
+ }
1139
+ }
1140
+ function resolveToken() {
1141
+ return resolveTokenWithSource().token;
1142
+ }
1143
+ function resolveTokenWithSource() {
1144
+ const localConfig = loadLocalConfig();
1145
+ if (localConfig?.token) return { token: localConfig.token, source: "local" };
1146
+ const envToken = readEnvToken();
1147
+ if (envToken) return { token: envToken, source: "env-file" };
1148
+ const globalConfig = loadGlobalConfig();
1149
+ if (globalConfig?.token) return { token: globalConfig.token, source: "global" };
1150
+ if (process.env.ILML_TOKEN) return { token: process.env.ILML_TOKEN, source: "env-var" };
1151
+ return { token: void 0, source: null };
1152
+ }
1153
+
1090
1154
  // src/constants.ts
1091
1155
  var SYS_WALLET_TAG = "#txn-wallet#";
1092
1156
  var SYS_DEVICES_TAG = "#txn-devices#";
@@ -1112,43 +1176,6 @@ function hasHighPrivacyTag(node) {
1112
1176
  // src/mcp-server.ts
1113
1177
  var require2 = createRequire(import.meta.url);
1114
1178
  var VERSION = require2("../package.json").version;
1115
- var CONFIG_DIRNAME = ".ilivemylife";
1116
- var CONFIG_FILENAME = "config.json";
1117
- function resolveToken() {
1118
- let dir = process.cwd();
1119
- const root = process.platform === "win32" ? dir.split("\\")[0] + "\\" : "/";
1120
- while (dir !== root) {
1121
- const configPath = join(dir, CONFIG_DIRNAME, CONFIG_FILENAME);
1122
- if (existsSync(configPath)) {
1123
- try {
1124
- const config = JSON.parse(readFileSync(configPath, "utf-8"));
1125
- if (config.token) return config.token;
1126
- } catch {
1127
- }
1128
- }
1129
- const parent = join(dir, "..");
1130
- if (parent === dir) break;
1131
- dir = parent;
1132
- }
1133
- const envPath = join(process.cwd(), ".env");
1134
- if (existsSync(envPath)) {
1135
- try {
1136
- const content = readFileSync(envPath, "utf-8");
1137
- const match = content.match(/^ILML_TOKEN\s*=\s*["']?([^"'\r\n]+)["']?/m);
1138
- if (match) return match[1].trim();
1139
- } catch {
1140
- }
1141
- }
1142
- const globalConfig = join(homedir(), CONFIG_DIRNAME, CONFIG_FILENAME);
1143
- if (existsSync(globalConfig)) {
1144
- try {
1145
- const config = JSON.parse(readFileSync(globalConfig, "utf-8"));
1146
- if (config.token) return config.token;
1147
- } catch {
1148
- }
1149
- }
1150
- return process.env.ILML_TOKEN;
1151
- }
1152
1179
  var _graph = null;
1153
1180
  function getGraph() {
1154
1181
  if (!_graph) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilivemylife/graph-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "SDK and CLI for iLiveMyLife Knowledge Graph",
5
5
  "license": "UNLICENSED",
6
6
  "engines": {