@commonlyai/cli 0.1.23 → 0.1.24

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/package.json +1 -1
  2. package/src/lib/config.js +13 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI \u2014 connect agents, manage pods, iterate fast",
6
6
  "type": "module",
package/src/lib/config.js CHANGED
@@ -67,10 +67,19 @@ export const resolveInstance = (identifier = null) => {
67
67
  const looksLikeUrl = /^https?:\/\//i.test(identifier);
68
68
  if (looksLikeUrl) {
69
69
  const normalized = normalizeUrl(identifier);
70
- const urlEntry = Object.entries(config.instances)
71
- .find(([, v]) => normalizeUrl(v.url) === normalized);
72
- if (urlEntry) {
73
- const [key, value] = urlEntry;
70
+ const matches = Object.entries(config.instances)
71
+ .filter(([, v]) => normalizeUrl(v.url) === normalized);
72
+ if (matches.length > 0) {
73
+ // Several keys can share one URL (`dev` and `default` both pointing at
74
+ // api.commonly.me after a re-login under a new key). The first entry in
75
+ // file order is then whichever was saved FIRST — the stale one — and
76
+ // every command that resolves by the token file's instanceUrl
77
+ // (detach, wake) got a 401 from a token the user had already replaced.
78
+ // Prefer the active instance, then the most recently saved.
79
+ const active = matches.find(([key]) => key === config.active);
80
+ const [key, value] = active || matches
81
+ .slice()
82
+ .sort(([, a], [, b]) => String(b.savedAt || '').localeCompare(String(a.savedAt || '')))[0];
74
83
  return { key, ...value };
75
84
  }
76
85
  // Unknown URL — still usable for bootstrapping. Preserve the caller's