@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.
- package/dist/auth.d.ts +2 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +7 -5
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +24 -12
- package/dist/cli.js.map +1 -1
- package/dist/cmd/build/entry-generator.d.ts.map +1 -1
- package/dist/cmd/build/entry-generator.js +26 -17
- package/dist/cmd/build/entry-generator.js.map +1 -1
- package/dist/cmd/build/vite/public-asset-path-plugin.d.ts +17 -20
- package/dist/cmd/build/vite/public-asset-path-plugin.d.ts.map +1 -1
- package/dist/cmd/build/vite/public-asset-path-plugin.js +62 -43
- package/dist/cmd/build/vite/public-asset-path-plugin.js.map +1 -1
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
- package/dist/cmd/build/vite/vite-asset-server-config.js +3 -1
- package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
- package/dist/cmd/cloud/env/org-util.d.ts +2 -1
- package/dist/cmd/cloud/env/org-util.d.ts.map +1 -1
- package/dist/cmd/cloud/env/org-util.js +4 -2
- package/dist/cmd/cloud/env/org-util.js.map +1 -1
- package/dist/cmd/cloud/stream/create.d.ts +3 -0
- package/dist/cmd/cloud/stream/create.d.ts.map +1 -0
- package/dist/cmd/cloud/stream/create.js +227 -0
- package/dist/cmd/cloud/stream/create.js.map +1 -0
- package/dist/cmd/cloud/stream/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/delete.js +2 -1
- package/dist/cmd/cloud/stream/delete.js.map +1 -1
- package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/get.js +2 -1
- package/dist/cmd/cloud/stream/get.js.map +1 -1
- package/dist/cmd/cloud/stream/index.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/index.js +10 -1
- package/dist/cmd/cloud/stream/index.js.map +1 -1
- package/dist/cmd/cloud/stream/list.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/list.js +2 -1
- package/dist/cmd/cloud/stream/list.js.map +1 -1
- package/dist/cmd/cloud/stream/util.d.ts +6 -5
- package/dist/cmd/cloud/stream/util.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/util.js +26 -5
- package/dist/cmd/cloud/stream/util.js.map +1 -1
- package/dist/cmd/upgrade/index.d.ts.map +1 -1
- package/dist/cmd/upgrade/index.js +23 -0
- package/dist/cmd/upgrade/index.js.map +1 -1
- package/dist/cmd/upgrade/npm-availability.d.ts +44 -0
- package/dist/cmd/upgrade/npm-availability.d.ts.map +1 -0
- package/dist/cmd/upgrade/npm-availability.js +73 -0
- package/dist/cmd/upgrade/npm-availability.js.map +1 -0
- package/dist/tui.d.ts +9 -1
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +39 -14
- package/dist/tui.js.map +1 -1
- package/dist/version-check.d.ts.map +1 -1
- package/dist/version-check.js +13 -2
- package/dist/version-check.js.map +1 -1
- package/package.json +6 -6
- package/src/auth.ts +9 -5
- package/src/cli.ts +44 -12
- package/src/cmd/build/entry-generator.ts +26 -17
- package/src/cmd/build/vite/public-asset-path-plugin.ts +73 -51
- package/src/cmd/build/vite/vite-asset-server-config.ts +3 -1
- package/src/cmd/cloud/env/org-util.ts +5 -2
- package/src/cmd/cloud/stream/create.ts +248 -0
- package/src/cmd/cloud/stream/delete.ts +2 -1
- package/src/cmd/cloud/stream/get.ts +2 -1
- package/src/cmd/cloud/stream/index.ts +10 -1
- package/src/cmd/cloud/stream/list.ts +2 -1
- package/src/cmd/cloud/stream/util.ts +39 -12
- package/src/cmd/upgrade/index.ts +25 -0
- package/src/cmd/upgrade/npm-availability.ts +105 -0
- package/src/tui.ts +42 -14
- 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
|
-
//
|
|
1791
|
-
//
|
|
1792
|
-
if (
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
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
|
|
1803
|
-
|
|
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
|
|
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
|
|
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
|
|
package/src/version-check.ts
CHANGED
|
@@ -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
|
|