@agentuity/cli 0.1.43 → 0.1.44

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 (72) hide show
  1. package/dist/auth.d.ts +2 -2
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +7 -5
  4. package/dist/auth.js.map +1 -1
  5. package/dist/cli.d.ts.map +1 -1
  6. package/dist/cli.js +24 -12
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cmd/build/entry-generator.d.ts.map +1 -1
  9. package/dist/cmd/build/entry-generator.js +26 -17
  10. package/dist/cmd/build/entry-generator.js.map +1 -1
  11. package/dist/cmd/build/vite/public-asset-path-plugin.d.ts +17 -20
  12. package/dist/cmd/build/vite/public-asset-path-plugin.d.ts.map +1 -1
  13. package/dist/cmd/build/vite/public-asset-path-plugin.js +62 -43
  14. package/dist/cmd/build/vite/public-asset-path-plugin.js.map +1 -1
  15. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
  16. package/dist/cmd/build/vite/vite-asset-server-config.js +3 -1
  17. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
  18. package/dist/cmd/cloud/env/org-util.d.ts +2 -1
  19. package/dist/cmd/cloud/env/org-util.d.ts.map +1 -1
  20. package/dist/cmd/cloud/env/org-util.js +4 -2
  21. package/dist/cmd/cloud/env/org-util.js.map +1 -1
  22. package/dist/cmd/cloud/stream/create.d.ts +3 -0
  23. package/dist/cmd/cloud/stream/create.d.ts.map +1 -0
  24. package/dist/cmd/cloud/stream/create.js +227 -0
  25. package/dist/cmd/cloud/stream/create.js.map +1 -0
  26. package/dist/cmd/cloud/stream/delete.d.ts.map +1 -1
  27. package/dist/cmd/cloud/stream/delete.js +2 -1
  28. package/dist/cmd/cloud/stream/delete.js.map +1 -1
  29. package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
  30. package/dist/cmd/cloud/stream/get.js +2 -1
  31. package/dist/cmd/cloud/stream/get.js.map +1 -1
  32. package/dist/cmd/cloud/stream/index.d.ts.map +1 -1
  33. package/dist/cmd/cloud/stream/index.js +10 -1
  34. package/dist/cmd/cloud/stream/index.js.map +1 -1
  35. package/dist/cmd/cloud/stream/list.d.ts.map +1 -1
  36. package/dist/cmd/cloud/stream/list.js +2 -1
  37. package/dist/cmd/cloud/stream/list.js.map +1 -1
  38. package/dist/cmd/cloud/stream/util.d.ts +6 -5
  39. package/dist/cmd/cloud/stream/util.d.ts.map +1 -1
  40. package/dist/cmd/cloud/stream/util.js +26 -5
  41. package/dist/cmd/cloud/stream/util.js.map +1 -1
  42. package/dist/cmd/upgrade/index.d.ts.map +1 -1
  43. package/dist/cmd/upgrade/index.js +23 -0
  44. package/dist/cmd/upgrade/index.js.map +1 -1
  45. package/dist/cmd/upgrade/npm-availability.d.ts +44 -0
  46. package/dist/cmd/upgrade/npm-availability.d.ts.map +1 -0
  47. package/dist/cmd/upgrade/npm-availability.js +73 -0
  48. package/dist/cmd/upgrade/npm-availability.js.map +1 -0
  49. package/dist/tui.d.ts +9 -1
  50. package/dist/tui.d.ts.map +1 -1
  51. package/dist/tui.js +39 -14
  52. package/dist/tui.js.map +1 -1
  53. package/dist/version-check.d.ts.map +1 -1
  54. package/dist/version-check.js +13 -2
  55. package/dist/version-check.js.map +1 -1
  56. package/package.json +6 -6
  57. package/src/auth.ts +9 -5
  58. package/src/cli.ts +44 -12
  59. package/src/cmd/build/entry-generator.ts +26 -17
  60. package/src/cmd/build/vite/public-asset-path-plugin.ts +73 -51
  61. package/src/cmd/build/vite/vite-asset-server-config.ts +3 -1
  62. package/src/cmd/cloud/env/org-util.ts +5 -2
  63. package/src/cmd/cloud/stream/create.ts +248 -0
  64. package/src/cmd/cloud/stream/delete.ts +2 -1
  65. package/src/cmd/cloud/stream/get.ts +2 -1
  66. package/src/cmd/cloud/stream/index.ts +10 -1
  67. package/src/cmd/cloud/stream/list.ts +2 -1
  68. package/src/cmd/cloud/stream/util.ts +39 -12
  69. package/src/cmd/upgrade/index.ts +25 -0
  70. package/src/cmd/upgrade/npm-availability.ts +105 -0
  71. package/src/tui.ts +42 -14
  72. package/src/version-check.ts +19 -3
@@ -0,0 +1,105 @@
1
+ /**
2
+ * npm registry availability checking utilities.
3
+ * Used to verify a version is available on npm before attempting upgrade.
4
+ */
5
+
6
+ const NPM_REGISTRY_URL = 'https://registry.npmjs.org';
7
+ const PACKAGE_NAME = '@agentuity/cli';
8
+
9
+ /** Default timeout for quick checks (implicit version check) */
10
+ const QUICK_CHECK_TIMEOUT_MS = 1000;
11
+
12
+ /** Default timeout for explicit upgrade command */
13
+ const EXPLICIT_CHECK_TIMEOUT_MS = 5000;
14
+
15
+ export interface CheckNpmOptions {
16
+ /** Timeout in milliseconds (default: 5000 for explicit, 1000 for quick) */
17
+ timeoutMs?: number;
18
+ }
19
+
20
+ /**
21
+ * Check if a specific version of @agentuity/cli is available on npm registry.
22
+ * Uses the npm registry API directly for faster response than `npm view`.
23
+ *
24
+ * @param version - Version to check (with or without 'v' prefix)
25
+ * @param options - Optional configuration
26
+ * @returns true if version is available, false otherwise
27
+ */
28
+ export async function isVersionAvailableOnNpm(
29
+ version: string,
30
+ options: CheckNpmOptions = {}
31
+ ): Promise<boolean> {
32
+ const { timeoutMs = EXPLICIT_CHECK_TIMEOUT_MS } = options;
33
+ const normalizedVersion = version.replace(/^v/, '');
34
+ const url = `${NPM_REGISTRY_URL}/${encodeURIComponent(PACKAGE_NAME)}/${normalizedVersion}`;
35
+
36
+ try {
37
+ const response = await fetch(url, {
38
+ method: 'HEAD', // Only need to check existence, not full metadata
39
+ signal: AbortSignal.timeout(timeoutMs),
40
+ headers: {
41
+ Accept: 'application/json',
42
+ },
43
+ });
44
+ return response.ok;
45
+ } catch {
46
+ // Network error or timeout - assume not available
47
+ return false;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Quick check if a version is available on npm with a short timeout.
53
+ * Used for implicit version checks (auto-upgrade flow) to avoid blocking the user's command.
54
+ *
55
+ * @param version - Version to check (with or without 'v' prefix)
56
+ * @returns true if version is available, false if unavailable or timeout
57
+ */
58
+ export async function isVersionAvailableOnNpmQuick(version: string): Promise<boolean> {
59
+ return isVersionAvailableOnNpm(version, { timeoutMs: QUICK_CHECK_TIMEOUT_MS });
60
+ }
61
+
62
+ export interface WaitForNpmOptions {
63
+ /** Maximum number of attempts (default: 6) */
64
+ maxAttempts?: number;
65
+ /** Initial delay between attempts in ms (default: 2000) */
66
+ initialDelayMs?: number;
67
+ /** Maximum delay between attempts in ms (default: 10000) */
68
+ maxDelayMs?: number;
69
+ /** Callback called before each retry */
70
+ onRetry?: (attempt: number, delayMs: number) => void;
71
+ }
72
+
73
+ /**
74
+ * Wait for a version to become available on npm with exponential backoff.
75
+ *
76
+ * @param version - Version to wait for (with or without 'v' prefix)
77
+ * @param options - Configuration options
78
+ * @returns true if version became available, false if timed out
79
+ */
80
+ export async function waitForNpmAvailability(
81
+ version: string,
82
+ options: WaitForNpmOptions = {}
83
+ ): Promise<boolean> {
84
+ const { maxAttempts = 6, initialDelayMs = 2000, maxDelayMs = 10000, onRetry } = options;
85
+
86
+ // First check - no delay
87
+ if (await isVersionAvailableOnNpm(version)) {
88
+ return true;
89
+ }
90
+
91
+ // Retry with exponential backoff
92
+ let delay = initialDelayMs;
93
+ for (let attempt = 1; attempt < maxAttempts; attempt++) {
94
+ onRetry?.(attempt, delay);
95
+ await new Promise((resolve) => setTimeout(resolve, delay));
96
+
97
+ if (await isVersionAvailableOnNpm(version)) {
98
+ return true;
99
+ }
100
+
101
+ delay = Math.min(Math.round(delay * 1.5), maxDelayMs);
102
+ }
103
+
104
+ return false;
105
+ }
package/src/tui.ts CHANGED
@@ -1764,9 +1764,18 @@ export async function prompt(message: string): Promise<string> {
1764
1764
  });
1765
1765
  }
1766
1766
 
1767
+ /**
1768
+ * Select an organization from a list.
1769
+ *
1770
+ * @param orgs - List of organizations to choose from
1771
+ * @param initial - Preferred org ID to pre-select (from saved preferences)
1772
+ * @param autoSelect - If true, auto-select preferred org without prompting (for --confirm or non-interactive)
1773
+ * @returns The selected organization ID
1774
+ */
1767
1775
  export async function selectOrganization(
1768
1776
  orgs: OrganizationList,
1769
- initial?: string
1777
+ initial?: string,
1778
+ autoSelect?: boolean
1770
1779
  ): Promise<string> {
1771
1780
  if (orgs.length === 0) {
1772
1781
  fatal(
@@ -1775,6 +1784,7 @@ export async function selectOrganization(
1775
1784
  );
1776
1785
  }
1777
1786
 
1787
+ // 1. Environment variable always takes precedence
1778
1788
  if (process.env.AGENTUITY_CLOUD_ORG_ID) {
1779
1789
  const org = orgs.find((o) => o.id === process.env.AGENTUITY_CLOUD_ORG_ID);
1780
1790
  if (org) {
@@ -1782,41 +1792,59 @@ export async function selectOrganization(
1782
1792
  }
1783
1793
  }
1784
1794
 
1785
- // Auto-select if only one org (regardless of TTY mode)
1795
+ // 2. Auto-select if only one org (regardless of TTY mode or autoSelect)
1786
1796
  if (orgs.length === 1 && orgs[0]) {
1787
1797
  return orgs[0].id;
1788
1798
  }
1789
1799
 
1790
- // Use saved preference if available (regardless of TTY mode)
1791
- // This allows consistent behavior without prompting on every command
1792
- if (initial) {
1793
- const initialOrg = orgs.find((o) => o.id === initial);
1794
- if (initialOrg) {
1795
- return initialOrg.id;
1800
+ // 3. Auto-select mode (--confirm flag or explicit autoSelect)
1801
+ // Use preferred org if set, otherwise fall back to first org
1802
+ if (autoSelect) {
1803
+ if (initial) {
1804
+ const initialOrg = orgs.find((o) => o.id === initial);
1805
+ if (initialOrg) {
1806
+ return initialOrg.id;
1807
+ }
1808
+ }
1809
+ // Fall back to first org with warning
1810
+ const firstOrg = orgs[0];
1811
+ if (firstOrg) {
1812
+ warning(
1813
+ `Multiple organizations found. Auto-selecting first org: ${firstOrg.name}. ` +
1814
+ `Set AGENTUITY_CLOUD_ORG_ID, use --org-id, or run 'agentuity auth org select' to set a default.`
1815
+ );
1816
+ return firstOrg.id;
1796
1817
  }
1797
1818
  }
1798
1819
 
1799
- // Check for non-interactive environment (check both stdin and stdout)
1820
+ // 4. Check for non-interactive environment (check both stdin and stdout)
1800
1821
  const isNonInteractive = !process.stdin.isTTY || !process.stdout.isTTY;
1801
1822
  if (isNonInteractive) {
1802
- // In non-interactive mode with multiple orgs, auto-select first org
1803
- // This allows scripts and CI/CD to work without explicit org selection
1823
+ // In non-interactive mode, use preferred org if set
1824
+ if (initial) {
1825
+ const initialOrg = orgs.find((o) => o.id === initial);
1826
+ if (initialOrg) {
1827
+ return initialOrg.id;
1828
+ }
1829
+ }
1830
+ // Fall back to first org with warning
1804
1831
  const firstOrg = orgs[0];
1805
1832
  if (firstOrg) {
1806
1833
  warning(
1807
1834
  `Multiple organizations found. Auto-selecting first org: ${firstOrg.name}. ` +
1808
- `Set AGENTUITY_CLOUD_ORG_ID or use --org-id to specify a different org.`
1835
+ `Set AGENTUITY_CLOUD_ORG_ID, use --org-id, or run 'agentuity auth org select' to set a default.`
1809
1836
  );
1810
1837
  return firstOrg.id;
1811
1838
  }
1812
1839
  }
1813
1840
 
1814
- // Interactive mode with no saved preference - prompt user
1841
+ // 5. Interactive mode - show selector with preferred org pre-selected
1842
+ const initialIndex = initial ? orgs.findIndex((o) => o.id === initial) : 0;
1815
1843
  const response = await enquirer.prompt<{ action: string }>({
1816
1844
  type: 'select',
1817
1845
  name: 'action',
1818
1846
  message: 'Select an organization',
1819
- initial: 0,
1847
+ initial: initialIndex >= 0 ? initialIndex : 0,
1820
1848
  choices: orgs.map((o) => ({ message: o.name, name: o.id })),
1821
1849
  });
1822
1850
 
@@ -233,18 +233,34 @@ export async function checkForUpdates(
233
233
  const currentVersion = getVersion();
234
234
  const latestVersion = await fetchLatestVersion();
235
235
 
236
- // Update the timestamp since we successfully checked
237
- await updateCheckTimestamp(config, logger);
238
-
239
236
  // Compare versions
240
237
  const normalizedCurrent = currentVersion.replace(/^v/, '');
241
238
  const normalizedLatest = latestVersion.replace(/^v/, '');
242
239
 
243
240
  if (normalizedCurrent === normalizedLatest) {
241
+ // Update timestamp - we confirmed we're on latest version
242
+ await updateCheckTimestamp(config, logger);
244
243
  logger.trace('Already on latest version: %s', currentVersion);
245
244
  return;
246
245
  }
247
246
 
247
+ // Quick npm availability check before prompting (short timeout, no retries)
248
+ // This avoids blocking the user's command if npm is slow or version not yet available
249
+ const { isVersionAvailableOnNpmQuick } = await import('./cmd/upgrade/npm-availability');
250
+ const isAvailable = await isVersionAvailableOnNpmQuick(latestVersion);
251
+
252
+ if (!isAvailable) {
253
+ // Don't update timestamp - we want to check again soon since npm may propagate
254
+ logger.debug(
255
+ 'Version %s not yet available on npm, skipping upgrade prompt',
256
+ latestVersion
257
+ );
258
+ return;
259
+ }
260
+
261
+ // Update timestamp - npm availability confirmed, we can proceed with prompt
262
+ await updateCheckTimestamp(config, logger);
263
+
248
264
  // New version available - prompt user
249
265
  const shouldUpgrade = await promptUpgrade(currentVersion, latestVersion);
250
266