openpond-code 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # openpond-code
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - d1479e9: updated base url
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -52,6 +52,7 @@ openpond opentool init --dir .
52
52
  Global account selection:
53
53
 
54
54
  - `--account <name>` (alias `--profile <name>`) selects which stored account/API key to use.
55
+ - `--base-url <url>` (alias `--baseurl`) selects the account entry matching that base URL when duplicate handles exist (for example, staging vs production).
55
56
  - `OPENPOND_ACCOUNT=<name>` sets the default selected account for a shell/session.
56
57
  - If omitted, CLI uses the last active stored account.
57
58
 
package/dist/cli.js CHANGED
@@ -296,9 +296,15 @@ function resolveWorkerBaseUrl(baseUrl) {
296
296
  if (host === "apps.openpond.live") {
297
297
  return null;
298
298
  }
299
- if (host === "api.openpond.ai" || host === "openpond.live" || host === "www.openpond.live") {
299
+ if (host === "apps.staging.openpond.live") {
300
+ return null;
301
+ }
302
+ if (host === "api.openpond.ai" || host === "openpond.ai" || host === "openpond.live" || host === "www.openpond.live") {
300
303
  return "https://apps.openpond.live";
301
304
  }
305
+ if (host === "api.staging-api.openpond.ai" || host === "staging.openpond.ai") {
306
+ return "https://apps.staging.openpond.live";
307
+ }
302
308
  return null;
303
309
  })();
304
310
  if (mappedHost) {
@@ -463,11 +469,26 @@ function normalizeHandle(value) {
463
469
  const trimmed = value.trim();
464
470
  return trimmed.length > 0 ? trimmed : null;
465
471
  }
472
+ function normalizeBaseUrl(value) {
473
+ if (typeof value !== "string")
474
+ return null;
475
+ const trimmed = value.trim();
476
+ if (!trimmed)
477
+ return null;
478
+ return trimmed.replace(/\/$/, "");
479
+ }
466
480
  function handleEquals(left, right) {
467
481
  return left.trim().toLowerCase() === right.trim().toLowerCase();
468
482
  }
469
- function findAccountIndex(accounts, handle) {
470
- return accounts.findIndex((candidate) => handleEquals(candidate.handle, handle));
483
+ function findAccountIndex(accounts, handle, baseUrl) {
484
+ const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
485
+ return accounts.findIndex((candidate) => {
486
+ if (!handleEquals(candidate.handle, handle))
487
+ return false;
488
+ if (!normalizedBaseUrl)
489
+ return true;
490
+ return normalizeBaseUrl(candidate.baseUrl) === normalizedBaseUrl;
491
+ });
471
492
  }
472
493
  function sanitizeSession(value) {
473
494
  if (!value || typeof value !== "object" || Array.isArray(value)) {
@@ -549,7 +570,7 @@ function normalizeGlobalConfig(raw) {
549
570
  const account = sanitizeAccount(candidate);
550
571
  if (!account)
551
572
  continue;
552
- if (findAccountIndex(accounts, account.handle) !== -1)
573
+ if (findAccountIndex(accounts, account.handle, account.baseUrl) !== -1)
553
574
  continue;
554
575
  accounts.push(account);
555
576
  }
@@ -569,12 +590,22 @@ function resolveRequestedHandle(global, explicitAccount) {
569
590
  const idx = findAccountIndex(accounts, requested);
570
591
  return idx === -1 ? requested : accounts[idx].handle;
571
592
  }
572
- function ensureAccount(accounts, handle) {
573
- const idx = findAccountIndex(accounts, handle);
593
+ function ensureAccount(accounts, handle, baseUrl) {
594
+ const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
595
+ const idx = findAccountIndex(accounts, handle, normalizedBaseUrl);
574
596
  if (idx !== -1) {
575
597
  return accounts[idx];
576
598
  }
599
+ if (!normalizedBaseUrl) {
600
+ const firstByHandle = findAccountIndex(accounts, handle);
601
+ if (firstByHandle !== -1) {
602
+ return accounts[firstByHandle];
603
+ }
604
+ }
577
605
  const next = { handle };
606
+ if (normalizedBaseUrl) {
607
+ next.baseUrl = normalizedBaseUrl;
608
+ }
578
609
  accounts.push(next);
579
610
  return next;
580
611
  }
@@ -631,7 +662,8 @@ function applyAccountPatch(global, source, options) {
631
662
  return false;
632
663
  const accounts = global.accounts ?? [];
633
664
  const handle = resolveRequestedHandle(global, source.activeHandle);
634
- const account = ensureAccount(accounts, handle);
665
+ const requestedBaseUrl = normalizeBaseUrl(hasOwn(source, "baseUrl") ? source.baseUrl ?? null : process.env.OPENPOND_BASE_URL);
666
+ const account = ensureAccount(accounts, handle, requestedBaseUrl);
635
667
  for (const key of ACCOUNT_SCOPED_KEYS) {
636
668
  if (!hasOwn(source, key))
637
669
  continue;
@@ -682,7 +714,9 @@ async function loadConfig(options = {}) {
682
714
  const global = await loadGlobalConfig();
683
715
  const accounts = global.accounts ?? [];
684
716
  const requested = resolveRequestedHandle(global, options.account);
685
- const idx = findAccountIndex(accounts, requested);
717
+ const requestedBaseUrl = normalizeBaseUrl(options.baseUrl ?? process.env.OPENPOND_BASE_URL);
718
+ const idxWithBase = findAccountIndex(accounts, requested, requestedBaseUrl);
719
+ const idx = idxWithBase !== -1 ? idxWithBase : findAccountIndex(accounts, requested);
686
720
  const account = idx === -1 ? null : accounts[idx];
687
721
  const session = account?.session;
688
722
  return {
@@ -908,14 +942,43 @@ function resolveAccountOption(options) {
908
942
  }
909
943
  return trimmed;
910
944
  }
945
+ function resolveBaseUrlOption(options) {
946
+ const raw = typeof options.baseUrl === "string" ? options.baseUrl : typeof options.baseurl === "string" ? options.baseurl : null;
947
+ if (!raw)
948
+ return null;
949
+ const trimmed = raw.trim();
950
+ if (!trimmed || trimmed === "true") {
951
+ throw new Error("baseurl must be a non-empty value");
952
+ }
953
+ return trimmed.replace(/\/$/, "");
954
+ }
911
955
  function resolveBaseUrl(config) {
912
956
  const envBase = process.env.OPENPOND_BASE_URL;
913
957
  const base = envBase || config.baseUrl || "https://openpond.ai";
914
958
  return base.replace(/\/$/, "");
915
959
  }
916
- function resolvePublicApiBaseUrl() {
960
+ function mapUiBaseToApiBase(baseUrl) {
961
+ if (!baseUrl)
962
+ return null;
963
+ const trimmed = baseUrl.replace(/\/$/, "");
964
+ try {
965
+ const url = new URL(trimmed);
966
+ const host = url.hostname.toLowerCase();
967
+ if (host === "staging.openpond.ai") {
968
+ return "https://api.staging-api.openpond.ai";
969
+ }
970
+ if (host === "openpond.ai" || host === "openpond.live" || host === "www.openpond.live") {
971
+ return "https://api.openpond.ai";
972
+ }
973
+ } catch {
974
+ return null;
975
+ }
976
+ return null;
977
+ }
978
+ function resolvePublicApiBaseUrl(config) {
917
979
  const envBase = process.env.OPENPOND_API_URL;
918
- const base = envBase || "https://api.openpond.ai";
980
+ const mapped = mapUiBaseToApiBase(process.env.OPENPOND_BASE_URL || config?.baseUrl);
981
+ const base = envBase || mapped || "https://api.openpond.ai";
919
982
  return base.replace(/\/$/, "");
920
983
  }
921
984
  function normalizeTemplateRepoUrl(input2, baseUrl) {
@@ -1193,7 +1256,7 @@ async function pollDeploymentLogs(params) {
1193
1256
  async function runTemplateStatus(_options, target) {
1194
1257
  const config = await loadConfig();
1195
1258
  const uiBase = resolveBaseUrl(config);
1196
- const apiBase = resolvePublicApiBaseUrl();
1259
+ const apiBase = resolvePublicApiBaseUrl(config);
1197
1260
  const apiKey = await ensureApiKey(config, uiBase);
1198
1261
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1199
1262
  const status = await getTemplateStatus(apiBase, apiKey, app.id);
@@ -1202,7 +1265,7 @@ async function runTemplateStatus(_options, target) {
1202
1265
  async function runTemplateBranches(_options, target) {
1203
1266
  const config = await loadConfig();
1204
1267
  const uiBase = resolveBaseUrl(config);
1205
- const apiBase = resolvePublicApiBaseUrl();
1268
+ const apiBase = resolvePublicApiBaseUrl(config);
1206
1269
  const apiKey = await ensureApiKey(config, uiBase);
1207
1270
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1208
1271
  const branches = await listTemplateBranches(apiBase, apiKey, app.id);
@@ -1211,7 +1274,7 @@ async function runTemplateBranches(_options, target) {
1211
1274
  async function runTemplateUpdate(options, target) {
1212
1275
  const config = await loadConfig();
1213
1276
  const uiBase = resolveBaseUrl(config);
1214
- const apiBase = resolvePublicApiBaseUrl();
1277
+ const apiBase = resolvePublicApiBaseUrl(config);
1215
1278
  const apiKey = await ensureApiKey(config, uiBase);
1216
1279
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1217
1280
  const envRaw = typeof options.env === "string" ? options.env : typeof options.environment === "string" ? options.environment : undefined;
@@ -1251,9 +1314,10 @@ function printHelp() {
1251
1314
  console.log("");
1252
1315
  console.log("Global options:");
1253
1316
  console.log(" --account <name> (alias: --profile <name>)");
1317
+ console.log(" --base-url <url> (alias: --baseurl)");
1254
1318
  console.log("");
1255
1319
  console.log("Env:");
1256
- console.log(" OPENPOND_API_KEY, OPENPOND_ACCOUNT, OPENPOND_API_URL, OPENPOND_TOOL_URL");
1320
+ console.log(" OPENPOND_API_KEY, OPENPOND_ACCOUNT, OPENPOND_BASE_URL, OPENPOND_API_URL, OPENPOND_TOOL_URL");
1257
1321
  }
1258
1322
  async function runLogin(options) {
1259
1323
  const config = await loadConfig();
@@ -1272,7 +1336,7 @@ async function runLogin(options) {
1272
1336
  async function runToolList(options, target) {
1273
1337
  const config = await loadConfig();
1274
1338
  const uiBase = resolveBaseUrl(config);
1275
- const apiBase = resolvePublicApiBaseUrl();
1339
+ const apiBase = resolvePublicApiBaseUrl(config);
1276
1340
  const apiKey = await ensureApiKey(config, uiBase);
1277
1341
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1278
1342
  const branch = typeof options.branch === "string" ? String(options.branch) : undefined;
@@ -1299,7 +1363,7 @@ async function runToolList(options, target) {
1299
1363
  async function runToolRun(options, target, toolName) {
1300
1364
  const config = await loadConfig();
1301
1365
  const uiBase = resolveBaseUrl(config);
1302
- const apiBase = resolvePublicApiBaseUrl();
1366
+ const apiBase = resolvePublicApiBaseUrl(config);
1303
1367
  const apiKey = await ensureApiKey(config, uiBase);
1304
1368
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1305
1369
  const branch = typeof options.branch === "string" ? String(options.branch) : undefined;
@@ -1333,7 +1397,7 @@ async function runToolRun(options, target, toolName) {
1333
1397
  async function runDeployWatch(options, target) {
1334
1398
  const config = await loadConfig();
1335
1399
  const uiBase = resolveBaseUrl(config);
1336
- const apiBase = resolvePublicApiBaseUrl();
1400
+ const apiBase = resolvePublicApiBaseUrl(config);
1337
1401
  const apiKey = await ensureApiKey(config, uiBase);
1338
1402
  const { app, handle, repo } = await resolveAppTarget(apiBase, apiKey, target);
1339
1403
  const branch = typeof options.branch === "string" ? String(options.branch) : undefined;
@@ -1363,7 +1427,7 @@ async function runRepoCreate(options, nameParts) {
1363
1427
  const config = await loadConfig();
1364
1428
  const uiBase = resolveBaseUrl(config);
1365
1429
  const apiKey = await ensureApiKey(config, uiBase);
1366
- const apiBase = resolvePublicApiBaseUrl();
1430
+ const apiBase = resolvePublicApiBaseUrl(config);
1367
1431
  const templateInput = typeof options.template === "string" ? options.template.trim() : "";
1368
1432
  if (templateInput && (options.empty === "true" || options.opentool === "true")) {
1369
1433
  throw new Error("choose one: --template or --empty/--opentool");
@@ -1576,14 +1640,14 @@ async function runAppsTools() {
1576
1640
  const config = await loadConfig();
1577
1641
  const uiBase = resolveBaseUrl(config);
1578
1642
  const apiKey = await ensureApiKey(config, uiBase);
1579
- const apiBase = resolvePublicApiBaseUrl();
1643
+ const apiBase = resolvePublicApiBaseUrl(config);
1580
1644
  const tools = await fetchToolsWithCache({ apiBase, apiKey });
1581
1645
  console.log(JSON.stringify(tools, null, 2));
1582
1646
  }
1583
1647
  async function runAppsList(options) {
1584
1648
  const config = await loadConfig();
1585
1649
  const uiBase = resolveBaseUrl(config);
1586
- const apiBase = resolvePublicApiBaseUrl();
1650
+ const apiBase = resolvePublicApiBaseUrl(config);
1587
1651
  const apiKey = await ensureApiKey(config, uiBase);
1588
1652
  const handle = typeof options.handle === "string" ? String(options.handle) : undefined;
1589
1653
  const normalizedHandle = handle ? normalizeRepoName(handle) : null;
@@ -1613,7 +1677,7 @@ async function runAppsPerformance(options) {
1613
1677
  const config = await loadConfig();
1614
1678
  const uiBase = resolveBaseUrl(config);
1615
1679
  const apiKey = await ensureApiKey(config, uiBase);
1616
- const apiBase = resolvePublicApiBaseUrl();
1680
+ const apiBase = resolvePublicApiBaseUrl(config);
1617
1681
  const appId = typeof options.appId === "string" ? String(options.appId) : undefined;
1618
1682
  const performance = await getUserPerformance(apiBase, apiKey, { appId });
1619
1683
  console.log(JSON.stringify(performance, null, 2));
@@ -1621,7 +1685,7 @@ async function runAppsPerformance(options) {
1621
1685
  async function runAppsSummary(_options, target) {
1622
1686
  const config = await loadConfig();
1623
1687
  const uiBase = resolveBaseUrl(config);
1624
- const apiBase = resolvePublicApiBaseUrl();
1688
+ const apiBase = resolvePublicApiBaseUrl(config);
1625
1689
  const apiKey = await ensureApiKey(config, uiBase);
1626
1690
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1627
1691
  const summary = await getAppRuntimeSummary(apiBase, apiKey, app.id);
@@ -1634,7 +1698,7 @@ async function runAppsAssistant(options, mode, target, contentParts) {
1634
1698
  }
1635
1699
  const config = await loadConfig();
1636
1700
  const uiBase = resolveBaseUrl(config);
1637
- const apiBase = resolvePublicApiBaseUrl();
1701
+ const apiBase = resolvePublicApiBaseUrl(config);
1638
1702
  const apiKey = await ensureApiKey(config, uiBase);
1639
1703
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1640
1704
  const result = await runAssistantMode(apiBase, apiKey, {
@@ -1648,7 +1712,7 @@ async function runAppsAgentCreate(options, contentParts) {
1648
1712
  const config = await loadConfig();
1649
1713
  const uiBase = resolveBaseUrl(config);
1650
1714
  const apiKey = await ensureApiKey(config, uiBase);
1651
- const apiBase = resolvePublicApiBaseUrl();
1715
+ const apiBase = resolvePublicApiBaseUrl(config);
1652
1716
  const prompt = (typeof options.prompt === "string" ? options.prompt : null) || contentParts.join(" ");
1653
1717
  if (!prompt.trim()) {
1654
1718
  throw new Error("usage: apps agent create --prompt <text>");
@@ -1732,7 +1796,7 @@ async function runAppsToolsExecute(options, appId, deploymentId, toolName) {
1732
1796
  const config = await loadConfig();
1733
1797
  const uiBase = resolveBaseUrl(config);
1734
1798
  const apiKey = await ensureApiKey(config, uiBase);
1735
- const apiBase = resolvePublicApiBaseUrl();
1799
+ const apiBase = resolvePublicApiBaseUrl(config);
1736
1800
  const methodRaw = typeof options.method === "string" ? String(options.method).toUpperCase() : undefined;
1737
1801
  const method = methodRaw && ["GET", "POST", "PUT", "DELETE"].includes(methodRaw) ? methodRaw : undefined;
1738
1802
  if (methodRaw && !method) {
@@ -1780,7 +1844,7 @@ async function runAppsEnvSet(options, target) {
1780
1844
  }
1781
1845
  const config = await loadConfig();
1782
1846
  const uiBase = resolveBaseUrl(config);
1783
- const apiBase = resolvePublicApiBaseUrl();
1847
+ const apiBase = resolvePublicApiBaseUrl(config);
1784
1848
  const apiKey = await ensureApiKey(config, uiBase);
1785
1849
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1786
1850
  const result = await updateAppEnvironment(apiBase, apiKey, app.id, { envVars });
@@ -1789,7 +1853,7 @@ async function runAppsEnvSet(options, target) {
1789
1853
  async function runAppsEnvGet(_options, target) {
1790
1854
  const config = await loadConfig();
1791
1855
  const uiBase = resolveBaseUrl(config);
1792
- const apiBase = resolvePublicApiBaseUrl();
1856
+ const apiBase = resolvePublicApiBaseUrl(config);
1793
1857
  const apiKey = await ensureApiKey(config, uiBase);
1794
1858
  const { app } = await resolveAppTarget(apiBase, apiKey, target);
1795
1859
  const result = await getAppEnvironment(apiBase, apiKey, app.id);
@@ -1798,7 +1862,7 @@ async function runAppsEnvGet(_options, target) {
1798
1862
  async function runAppsDeploy(options, target) {
1799
1863
  const config = await loadConfig();
1800
1864
  const uiBase = resolveBaseUrl(config);
1801
- const apiBase = resolvePublicApiBaseUrl();
1865
+ const apiBase = resolvePublicApiBaseUrl(config);
1802
1866
  const apiKey = await ensureApiKey(config, uiBase);
1803
1867
  const { app, handle, repo } = await resolveAppTarget(apiBase, apiKey, target);
1804
1868
  const envRaw = typeof options.env === "string" ? options.env : typeof options.environment === "string" ? options.environment : undefined;
@@ -1821,7 +1885,7 @@ async function runAppsPositionsTx(options) {
1821
1885
  const config = await loadConfig();
1822
1886
  const uiBase = resolveBaseUrl(config);
1823
1887
  const apiKey = await ensureApiKey(config, uiBase);
1824
- const apiBase = resolvePublicApiBaseUrl();
1888
+ const apiBase = resolvePublicApiBaseUrl(config);
1825
1889
  const methodRaw = typeof options.method === "string" ? String(options.method).toUpperCase() : "POST";
1826
1890
  const method = methodRaw === "GET" ? "GET" : "POST";
1827
1891
  if (methodRaw !== "GET" && methodRaw !== "POST") {
@@ -1889,7 +1953,7 @@ async function runAppsStoreEvents(options) {
1889
1953
  const config = await loadConfig();
1890
1954
  const uiBase = resolveBaseUrl(config);
1891
1955
  const apiKey = await ensureApiKey(config, uiBase);
1892
- const apiBase = resolvePublicApiBaseUrl();
1956
+ const apiBase = resolvePublicApiBaseUrl(config);
1893
1957
  const query = resolveStoreEventsParams(options);
1894
1958
  const result = await submitPositionsTx(apiBase, apiKey, {
1895
1959
  method: "GET",
@@ -1901,7 +1965,7 @@ async function runAppsTradeFacts(options) {
1901
1965
  const config = await loadConfig();
1902
1966
  const uiBase = resolveBaseUrl(config);
1903
1967
  const apiKey = await ensureApiKey(config, uiBase);
1904
- const apiBase = resolvePublicApiBaseUrl();
1968
+ const apiBase = resolvePublicApiBaseUrl(config);
1905
1969
  const appId = typeof options.appId === "string" ? options.appId : undefined;
1906
1970
  const performance = await getUserPerformance(apiBase, apiKey, { appId });
1907
1971
  if (performance && typeof performance === "object" && "trades" in performance && Array.isArray(performance.trades)) {
@@ -1913,9 +1977,16 @@ async function runAppsTradeFacts(options) {
1913
1977
  async function main() {
1914
1978
  const { command, options, rest } = parseArgs(process.argv.slice(2));
1915
1979
  const selectedAccount = resolveAccountOption(options);
1980
+ const selectedBaseUrl = resolveBaseUrlOption(options);
1916
1981
  if (selectedAccount) {
1917
1982
  process.env.OPENPOND_ACCOUNT = selectedAccount;
1918
1983
  }
1984
+ if (!selectedAccount && typeof options.handle === "string" && options.handle.trim().length > 0) {
1985
+ process.env.OPENPOND_ACCOUNT = options.handle.trim();
1986
+ }
1987
+ if (selectedBaseUrl) {
1988
+ process.env.OPENPOND_BASE_URL = selectedBaseUrl;
1989
+ }
1919
1990
  if (!command || command === "help") {
1920
1991
  printHelp();
1921
1992
  return;
package/dist/config.d.ts CHANGED
@@ -26,6 +26,7 @@ export type LocalConfig = {
26
26
  };
27
27
  export type LoadConfigOptions = {
28
28
  account?: string;
29
+ baseUrl?: string;
29
30
  };
30
31
  export declare function getConfigPath(): string;
31
32
  export declare function loadGlobalConfig(): Promise<LocalConfig>;
package/dist/index.js CHANGED
@@ -356,9 +356,15 @@ function resolveWorkerBaseUrl(baseUrl) {
356
356
  if (host === "apps.openpond.live") {
357
357
  return null;
358
358
  }
359
- if (host === "api.openpond.ai" || host === "openpond.live" || host === "www.openpond.live") {
359
+ if (host === "apps.staging.openpond.live") {
360
+ return null;
361
+ }
362
+ if (host === "api.openpond.ai" || host === "openpond.ai" || host === "openpond.live" || host === "www.openpond.live") {
360
363
  return "https://apps.openpond.live";
361
364
  }
365
+ if (host === "api.staging-api.openpond.ai" || host === "staging.openpond.ai") {
366
+ return "https://apps.staging.openpond.live";
367
+ }
362
368
  return null;
363
369
  })();
364
370
  if (mappedHost) {
@@ -859,11 +865,26 @@ function normalizeHandle(value) {
859
865
  const trimmed = value.trim();
860
866
  return trimmed.length > 0 ? trimmed : null;
861
867
  }
868
+ function normalizeBaseUrl(value) {
869
+ if (typeof value !== "string")
870
+ return null;
871
+ const trimmed = value.trim();
872
+ if (!trimmed)
873
+ return null;
874
+ return trimmed.replace(/\/$/, "");
875
+ }
862
876
  function handleEquals(left, right) {
863
877
  return left.trim().toLowerCase() === right.trim().toLowerCase();
864
878
  }
865
- function findAccountIndex(accounts, handle) {
866
- return accounts.findIndex((candidate) => handleEquals(candidate.handle, handle));
879
+ function findAccountIndex(accounts, handle, baseUrl) {
880
+ const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
881
+ return accounts.findIndex((candidate) => {
882
+ if (!handleEquals(candidate.handle, handle))
883
+ return false;
884
+ if (!normalizedBaseUrl)
885
+ return true;
886
+ return normalizeBaseUrl(candidate.baseUrl) === normalizedBaseUrl;
887
+ });
867
888
  }
868
889
  function sanitizeSession(value) {
869
890
  if (!value || typeof value !== "object" || Array.isArray(value)) {
@@ -945,7 +966,7 @@ function normalizeGlobalConfig(raw) {
945
966
  const account = sanitizeAccount(candidate);
946
967
  if (!account)
947
968
  continue;
948
- if (findAccountIndex(accounts, account.handle) !== -1)
969
+ if (findAccountIndex(accounts, account.handle, account.baseUrl) !== -1)
949
970
  continue;
950
971
  accounts.push(account);
951
972
  }
@@ -965,12 +986,22 @@ function resolveRequestedHandle(global, explicitAccount) {
965
986
  const idx = findAccountIndex(accounts, requested);
966
987
  return idx === -1 ? requested : accounts[idx].handle;
967
988
  }
968
- function ensureAccount(accounts, handle) {
969
- const idx = findAccountIndex(accounts, handle);
989
+ function ensureAccount(accounts, handle, baseUrl) {
990
+ const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
991
+ const idx = findAccountIndex(accounts, handle, normalizedBaseUrl);
970
992
  if (idx !== -1) {
971
993
  return accounts[idx];
972
994
  }
995
+ if (!normalizedBaseUrl) {
996
+ const firstByHandle = findAccountIndex(accounts, handle);
997
+ if (firstByHandle !== -1) {
998
+ return accounts[firstByHandle];
999
+ }
1000
+ }
973
1001
  const next = { handle };
1002
+ if (normalizedBaseUrl) {
1003
+ next.baseUrl = normalizedBaseUrl;
1004
+ }
974
1005
  accounts.push(next);
975
1006
  return next;
976
1007
  }
@@ -1027,7 +1058,8 @@ function applyAccountPatch(global, source, options) {
1027
1058
  return false;
1028
1059
  const accounts = global.accounts ?? [];
1029
1060
  const handle = resolveRequestedHandle(global, source.activeHandle);
1030
- const account = ensureAccount(accounts, handle);
1061
+ const requestedBaseUrl = normalizeBaseUrl(hasOwn(source, "baseUrl") ? source.baseUrl ?? null : process.env.OPENPOND_BASE_URL);
1062
+ const account = ensureAccount(accounts, handle, requestedBaseUrl);
1031
1063
  for (const key of ACCOUNT_SCOPED_KEYS) {
1032
1064
  if (!hasOwn(source, key))
1033
1065
  continue;
@@ -1078,7 +1110,9 @@ async function loadConfig(options = {}) {
1078
1110
  const global = await loadGlobalConfig();
1079
1111
  const accounts = global.accounts ?? [];
1080
1112
  const requested = resolveRequestedHandle(global, options.account);
1081
- const idx = findAccountIndex(accounts, requested);
1113
+ const requestedBaseUrl = normalizeBaseUrl(options.baseUrl ?? process.env.OPENPOND_BASE_URL);
1114
+ const idxWithBase = findAccountIndex(accounts, requested, requestedBaseUrl);
1115
+ const idx = idxWithBase !== -1 ? idxWithBase : findAccountIndex(accounts, requested);
1082
1116
  const account = idx === -1 ? null : accounts[idx];
1083
1117
  const session = account?.session;
1084
1118
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openpond-code",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "OpenPond CLI (API key only)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",