agent-media-cli 1.0.0
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/LICENSE +199 -0
- package/README.md +59 -0
- package/dist/commands/alias.d.ts +3 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +245 -0
- package/dist/commands/alias.js.map +1 -0
- package/dist/commands/apikey.d.ts +3 -0
- package/dist/commands/apikey.d.ts.map +1 -0
- package/dist/commands/apikey.js +282 -0
- package/dist/commands/apikey.js.map +1 -0
- package/dist/commands/cancel.d.ts +9 -0
- package/dist/commands/cancel.d.ts.map +1 -0
- package/dist/commands/cancel.js +101 -0
- package/dist/commands/cancel.js.map +1 -0
- package/dist/commands/completions.d.ts +15 -0
- package/dist/commands/completions.d.ts.map +1 -0
- package/dist/commands/completions.js +293 -0
- package/dist/commands/completions.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +327 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/credits.d.ts +18 -0
- package/dist/commands/credits.d.ts.map +1 -0
- package/dist/commands/credits.js +459 -0
- package/dist/commands/credits.js.map +1 -0
- package/dist/commands/debug.d.ts +20 -0
- package/dist/commands/debug.d.ts.map +1 -0
- package/dist/commands/debug.js +291 -0
- package/dist/commands/debug.js.map +1 -0
- package/dist/commands/delete.d.ts +3 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +273 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/commands/doctor.d.ts +14 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +468 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/download.d.ts +3 -0
- package/dist/commands/download.d.ts.map +1 -0
- package/dist/commands/download.js +165 -0
- package/dist/commands/download.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +358 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/inspect.d.ts +10 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +376 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/list.d.ts +13 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +198 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/login.d.ts +15 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +123 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +12 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +85 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/models.d.ts +10 -0
- package/dist/commands/models.d.ts.map +1 -0
- package/dist/commands/models.js +137 -0
- package/dist/commands/models.js.map +1 -0
- package/dist/commands/plan.d.ts +13 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +134 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/pricing.d.ts +14 -0
- package/dist/commands/pricing.d.ts.map +1 -0
- package/dist/commands/pricing.js +166 -0
- package/dist/commands/pricing.js.map +1 -0
- package/dist/commands/profile.d.ts +9 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +236 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/retry.d.ts +3 -0
- package/dist/commands/retry.d.ts.map +1 -0
- package/dist/commands/retry.js +424 -0
- package/dist/commands/retry.js.map +1 -0
- package/dist/commands/status.d.ts +9 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +182 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/subscribe.d.ts +3 -0
- package/dist/commands/subscribe.d.ts.map +1 -0
- package/dist/commands/subscribe.js +263 -0
- package/dist/commands/subscribe.js.map +1 -0
- package/dist/commands/text.d.ts +3 -0
- package/dist/commands/text.d.ts.map +1 -0
- package/dist/commands/text.js +263 -0
- package/dist/commands/text.js.map +1 -0
- package/dist/commands/update.d.ts +13 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +211 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/usage.d.ts +13 -0
- package/dist/commands/usage.d.ts.map +1 -0
- package/dist/commands/usage.js +344 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/commands/version.d.ts +8 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +26 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/commands/whoami.d.ts +9 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +76 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api.d.ts +518 -0
- package/dist/lib/api.d.ts.map +1 -0
- package/dist/lib/api.js +582 -0
- package/dist/lib/api.js.map +1 -0
- package/dist/lib/config.d.ts +33 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +91 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/credentials.d.ts +60 -0
- package/dist/lib/credentials.d.ts.map +1 -0
- package/dist/lib/credentials.js +152 -0
- package/dist/lib/credentials.js.map +1 -0
- package/dist/lib/errors.d.ts +20 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +77 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/output.d.ts +33 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +77 -0
- package/dist/lib/output.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright 2026 agent-media contributors. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Configuration management for the agent-media CLI.
|
|
4
|
+
*
|
|
5
|
+
* Stores config at ~/.agent-media/config.json (or AGENT_MEDIA_CONFIG_DIR).
|
|
6
|
+
*
|
|
7
|
+
* Supported keys:
|
|
8
|
+
* - api_url: Supabase Edge Functions URL
|
|
9
|
+
* - output_format: default output format (human/json/quiet)
|
|
10
|
+
* - default_model: default model for generate command
|
|
11
|
+
* - auto_open_browser: whether to auto-open browser on login (default: true)
|
|
12
|
+
* - download_dir: default download directory
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
15
|
+
import { homedir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
export const CONFIG_DIR = process.env['AGENT_MEDIA_CONFIG_DIR'] ?? join(homedir(), '.agent-media');
|
|
18
|
+
export const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
19
|
+
/** All recognized configuration keys. */
|
|
20
|
+
export const VALID_CONFIG_KEYS = [
|
|
21
|
+
'api_url',
|
|
22
|
+
'output_format',
|
|
23
|
+
'default_model',
|
|
24
|
+
'auto_open_browser',
|
|
25
|
+
'download_dir',
|
|
26
|
+
];
|
|
27
|
+
/** Default values for configuration keys. */
|
|
28
|
+
export const CONFIG_DEFAULTS = {
|
|
29
|
+
auto_open_browser: true,
|
|
30
|
+
output_format: 'human',
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Check whether a string is a valid configuration key.
|
|
34
|
+
*/
|
|
35
|
+
export function isValidConfigKey(key) {
|
|
36
|
+
return VALID_CONFIG_KEYS.includes(key);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Ensure the config directory exists.
|
|
40
|
+
*/
|
|
41
|
+
function ensureConfigDir() {
|
|
42
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
43
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Load the config file. Returns an empty object if it does not exist.
|
|
48
|
+
*/
|
|
49
|
+
export function loadConfig() {
|
|
50
|
+
if (!existsSync(CONFIG_FILE)) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const raw = readFileSync(CONFIG_FILE, 'utf-8');
|
|
55
|
+
return JSON.parse(raw);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Save the config object to disk.
|
|
63
|
+
*/
|
|
64
|
+
export function saveConfig(config) {
|
|
65
|
+
ensureConfigDir();
|
|
66
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a single config value by key.
|
|
70
|
+
*/
|
|
71
|
+
export function getConfigValue(key) {
|
|
72
|
+
const config = loadConfig();
|
|
73
|
+
return config[key];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set a single config value and persist to disk.
|
|
77
|
+
*/
|
|
78
|
+
export function setConfigValue(key, value) {
|
|
79
|
+
const config = loadConfig();
|
|
80
|
+
config[key] = value;
|
|
81
|
+
saveConfig(config);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Reset the config file by removing it entirely, restoring defaults.
|
|
85
|
+
*/
|
|
86
|
+
export function resetConfig() {
|
|
87
|
+
if (existsSync(CONFIG_FILE)) {
|
|
88
|
+
unlinkSync(CONFIG_FILE);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAE/D;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAA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CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,eAAe,EAAE,CAAC;IAClB,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;AAC9E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,KAAc;IACxD,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACpB,UAAU,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare const DEFAULT_PROFILE = "default";
|
|
2
|
+
export interface CredentialProfile {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
email: string;
|
|
5
|
+
userId: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CredentialsStore {
|
|
9
|
+
currentProfile: string;
|
|
10
|
+
profiles: Record<string, CredentialProfile>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Load the credentials store from disk. Returns an empty store if the
|
|
14
|
+
* file does not exist or is malformed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadCredentials(): CredentialsStore;
|
|
17
|
+
/**
|
|
18
|
+
* Persist the credentials store to disk.
|
|
19
|
+
*/
|
|
20
|
+
export declare function saveCredentials(store: CredentialsStore): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get the active profile name, respecting:
|
|
23
|
+
* 1. Explicit --profile flag
|
|
24
|
+
* 2. AGENT_MEDIA_PROFILE env var
|
|
25
|
+
* 3. The currentProfile field in the store
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveProfileName(flagProfile?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get the API key for the resolved profile.
|
|
30
|
+
*
|
|
31
|
+
* Resolution order:
|
|
32
|
+
* 1. AGENT_MEDIA_API_KEY env var (bypasses profile system entirely)
|
|
33
|
+
* 2. Profile-based lookup from credentials.json
|
|
34
|
+
*
|
|
35
|
+
* Returns null if no credentials are found.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getApiKey(profileName?: string): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Get the full credential profile for a given profile name.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getProfile(profileName?: string): CredentialProfile | null;
|
|
42
|
+
/**
|
|
43
|
+
* Save credentials for a profile.
|
|
44
|
+
*/
|
|
45
|
+
export declare function saveProfile(profileName: string, profile: CredentialProfile): void;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a specific profile from the store.
|
|
48
|
+
* If the deleted profile was the current one, resets to the first
|
|
49
|
+
* remaining profile or DEFAULT_PROFILE.
|
|
50
|
+
*/
|
|
51
|
+
export declare function deleteProfile(profileName: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Delete all profiles and remove the credentials file entirely.
|
|
54
|
+
*/
|
|
55
|
+
export declare function clearAllCredentials(): void;
|
|
56
|
+
/**
|
|
57
|
+
* List all profile names in the store.
|
|
58
|
+
*/
|
|
59
|
+
export declare function listProfiles(): string[];
|
|
60
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/lib/credentials.ts"],"names":[],"mappings":"AA6BA,eAAO,MAAM,eAAe,YAAY,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAC7C;AAWD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAelD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAM7D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAM/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS7D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAIzE;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,iBAAiB,GACzB,IAAI,CAQN;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAa1D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAGvC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Copyright 2026 agent-media contributors. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Credential store for the agent-media CLI.
|
|
4
|
+
*
|
|
5
|
+
* Manages API keys and profiles at ~/.agent-media/credentials.json
|
|
6
|
+
* (or AGENT_MEDIA_CONFIG_DIR). Supports multiple named profiles for
|
|
7
|
+
* multi-account usage.
|
|
8
|
+
*
|
|
9
|
+
* File format:
|
|
10
|
+
* {
|
|
11
|
+
* "currentProfile": "default",
|
|
12
|
+
* "profiles": {
|
|
13
|
+
* "default": {
|
|
14
|
+
* "apiKey": "ma_xxxxx",
|
|
15
|
+
* "email": "user@example.com",
|
|
16
|
+
* "userId": "uuid",
|
|
17
|
+
* "createdAt": "ISO8601"
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
23
|
+
import { join } from 'node:path';
|
|
24
|
+
import { CONFIG_DIR } from './config.js';
|
|
25
|
+
const CREDENTIALS_FILE = join(CONFIG_DIR, 'credentials.json');
|
|
26
|
+
export const DEFAULT_PROFILE = 'default';
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the config directory exists.
|
|
29
|
+
*/
|
|
30
|
+
function ensureDir() {
|
|
31
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
32
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load the credentials store from disk. Returns an empty store if the
|
|
37
|
+
* file does not exist or is malformed.
|
|
38
|
+
*/
|
|
39
|
+
export function loadCredentials() {
|
|
40
|
+
if (!existsSync(CREDENTIALS_FILE)) {
|
|
41
|
+
return { currentProfile: DEFAULT_PROFILE, profiles: {} };
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const raw = readFileSync(CREDENTIALS_FILE, 'utf-8');
|
|
45
|
+
const data = JSON.parse(raw);
|
|
46
|
+
// Basic shape validation
|
|
47
|
+
if (!data.profiles || typeof data.profiles !== 'object') {
|
|
48
|
+
return { currentProfile: DEFAULT_PROFILE, profiles: {} };
|
|
49
|
+
}
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return { currentProfile: DEFAULT_PROFILE, profiles: {} };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Persist the credentials store to disk.
|
|
58
|
+
*/
|
|
59
|
+
export function saveCredentials(store) {
|
|
60
|
+
ensureDir();
|
|
61
|
+
writeFileSync(CREDENTIALS_FILE, JSON.stringify(store, null, 2) + '\n', {
|
|
62
|
+
encoding: 'utf-8',
|
|
63
|
+
mode: 0o600, // rw------- owner-only
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the active profile name, respecting:
|
|
68
|
+
* 1. Explicit --profile flag
|
|
69
|
+
* 2. AGENT_MEDIA_PROFILE env var
|
|
70
|
+
* 3. The currentProfile field in the store
|
|
71
|
+
*/
|
|
72
|
+
export function resolveProfileName(flagProfile) {
|
|
73
|
+
if (flagProfile)
|
|
74
|
+
return flagProfile;
|
|
75
|
+
const envProfile = process.env['AGENT_MEDIA_PROFILE'];
|
|
76
|
+
if (envProfile)
|
|
77
|
+
return envProfile;
|
|
78
|
+
const store = loadCredentials();
|
|
79
|
+
return store.currentProfile || DEFAULT_PROFILE;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the API key for the resolved profile.
|
|
83
|
+
*
|
|
84
|
+
* Resolution order:
|
|
85
|
+
* 1. AGENT_MEDIA_API_KEY env var (bypasses profile system entirely)
|
|
86
|
+
* 2. Profile-based lookup from credentials.json
|
|
87
|
+
*
|
|
88
|
+
* Returns null if no credentials are found.
|
|
89
|
+
*/
|
|
90
|
+
export function getApiKey(profileName) {
|
|
91
|
+
// Env var always wins
|
|
92
|
+
const envKey = process.env['AGENT_MEDIA_API_KEY'];
|
|
93
|
+
if (envKey)
|
|
94
|
+
return envKey;
|
|
95
|
+
const store = loadCredentials();
|
|
96
|
+
const name = resolveProfileName(profileName);
|
|
97
|
+
const profile = store.profiles[name];
|
|
98
|
+
return profile?.apiKey ?? null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the full credential profile for a given profile name.
|
|
102
|
+
*/
|
|
103
|
+
export function getProfile(profileName) {
|
|
104
|
+
const store = loadCredentials();
|
|
105
|
+
const name = resolveProfileName(profileName);
|
|
106
|
+
return store.profiles[name] ?? null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Save credentials for a profile.
|
|
110
|
+
*/
|
|
111
|
+
export function saveProfile(profileName, profile) {
|
|
112
|
+
const store = loadCredentials();
|
|
113
|
+
store.profiles[profileName] = profile;
|
|
114
|
+
// If this is the first profile, make it the current one
|
|
115
|
+
if (Object.keys(store.profiles).length === 1) {
|
|
116
|
+
store.currentProfile = profileName;
|
|
117
|
+
}
|
|
118
|
+
saveCredentials(store);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Delete a specific profile from the store.
|
|
122
|
+
* If the deleted profile was the current one, resets to the first
|
|
123
|
+
* remaining profile or DEFAULT_PROFILE.
|
|
124
|
+
*/
|
|
125
|
+
export function deleteProfile(profileName) {
|
|
126
|
+
const store = loadCredentials();
|
|
127
|
+
if (!store.profiles[profileName])
|
|
128
|
+
return false;
|
|
129
|
+
delete store.profiles[profileName];
|
|
130
|
+
if (store.currentProfile === profileName) {
|
|
131
|
+
const remaining = Object.keys(store.profiles);
|
|
132
|
+
store.currentProfile = remaining[0] ?? DEFAULT_PROFILE;
|
|
133
|
+
}
|
|
134
|
+
saveCredentials(store);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Delete all profiles and remove the credentials file entirely.
|
|
139
|
+
*/
|
|
140
|
+
export function clearAllCredentials() {
|
|
141
|
+
if (existsSync(CREDENTIALS_FILE)) {
|
|
142
|
+
unlinkSync(CREDENTIALS_FILE);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* List all profile names in the store.
|
|
147
|
+
*/
|
|
148
|
+
export function listProfiles() {
|
|
149
|
+
const store = loadCredentials();
|
|
150
|
+
return Object.keys(store.profiles);
|
|
151
|
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,eAAe,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured CLI error with an error code and optional suggestion.
|
|
3
|
+
*/
|
|
4
|
+
export declare class CLIError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly suggestion?: string;
|
|
7
|
+
constructor(message: string, options: {
|
|
8
|
+
code: string;
|
|
9
|
+
suggestion?: string;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Display a user-friendly error message and exit.
|
|
14
|
+
*
|
|
15
|
+
* - CLIError: shows code, message, and optional suggestion.
|
|
16
|
+
* - Generic Error: shows the message with contextual suggestion.
|
|
17
|
+
* - Unknown: shows a generic message with troubleshooting hint.
|
|
18
|
+
*/
|
|
19
|
+
export declare function handleError(error: unknown): never;
|
|
20
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;CAM5E;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CA2BjD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2026 agent-media contributors. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Error handling utilities for the agent-media CLI.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
/**
|
|
7
|
+
* Structured CLI error with an error code and optional suggestion.
|
|
8
|
+
*/
|
|
9
|
+
export class CLIError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
suggestion;
|
|
12
|
+
constructor(message, options) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'CLIError';
|
|
15
|
+
this.code = options.code;
|
|
16
|
+
this.suggestion = options.suggestion;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Display a user-friendly error message and exit.
|
|
21
|
+
*
|
|
22
|
+
* - CLIError: shows code, message, and optional suggestion.
|
|
23
|
+
* - Generic Error: shows the message with contextual suggestion.
|
|
24
|
+
* - Unknown: shows a generic message with troubleshooting hint.
|
|
25
|
+
*/
|
|
26
|
+
export function handleError(error) {
|
|
27
|
+
if (error instanceof CLIError) {
|
|
28
|
+
console.error(chalk.red(`\u2717 ${error.message}`));
|
|
29
|
+
if (error.suggestion) {
|
|
30
|
+
console.error(chalk.yellow(` \u2192 ${error.suggestion}`));
|
|
31
|
+
}
|
|
32
|
+
console.error(chalk.dim(` Error code: ${error.code}`));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
if (error instanceof Error) {
|
|
36
|
+
console.error(chalk.red(`\u2717 ${error.message}`));
|
|
37
|
+
// Provide contextual suggestions for common generic error types
|
|
38
|
+
const suggestion = inferSuggestion(error);
|
|
39
|
+
if (suggestion) {
|
|
40
|
+
console.error(chalk.yellow(` \u2192 ${suggestion}`));
|
|
41
|
+
}
|
|
42
|
+
console.error(chalk.dim(` Error code: UNEXPECTED_ERROR`));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
console.error(chalk.red('\u2717 An unexpected error occurred.'));
|
|
46
|
+
console.error(chalk.yellow(` \u2192 Run 'agent-media doctor' to diagnose common issues.`));
|
|
47
|
+
console.error(chalk.dim(` Error code: UNKNOWN_ERROR`));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Infer a helpful suggestion from a generic Error based on common patterns.
|
|
52
|
+
*/
|
|
53
|
+
function inferSuggestion(error) {
|
|
54
|
+
const msg = error.message.toLowerCase();
|
|
55
|
+
// Network / fetch failures
|
|
56
|
+
if (msg.includes('fetch') || msg.includes('enotfound') || msg.includes('econnrefused')) {
|
|
57
|
+
return "Check your internet connection or run 'agent-media doctor' to verify API connectivity.";
|
|
58
|
+
}
|
|
59
|
+
// Timeout
|
|
60
|
+
if (msg.includes('timeout') || msg.includes('aborted') || error.name === 'AbortError') {
|
|
61
|
+
return 'The request timed out. Check your network or try again later.';
|
|
62
|
+
}
|
|
63
|
+
// Permission denied
|
|
64
|
+
if (msg.includes('eacces') || msg.includes('permission denied')) {
|
|
65
|
+
return 'Check file permissions. You may need to run with elevated privileges.';
|
|
66
|
+
}
|
|
67
|
+
// File system
|
|
68
|
+
if (msg.includes('enoent') || msg.includes('no such file')) {
|
|
69
|
+
return 'A required file or directory was not found. Check the path and try again.';
|
|
70
|
+
}
|
|
71
|
+
// JSON parse errors
|
|
72
|
+
if (msg.includes('json') && (msg.includes('parse') || msg.includes('unexpected token'))) {
|
|
73
|
+
return 'Received an invalid response. The API may be temporarily unavailable.';
|
|
74
|
+
}
|
|
75
|
+
return "Run 'agent-media doctor' to diagnose common issues.";
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAE/D;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,UAAU,CAAU;IAE7B,YAAY,OAAe,EAAE,OAA8C;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,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AC;IACjF,CAAC;IAED,OAAO,qDAAqD,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Ora } from 'ora';
|
|
2
|
+
import type { OutputMode } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detect the output mode based on CLI flags.
|
|
5
|
+
*/
|
|
6
|
+
export declare function detectOutputMode(options: {
|
|
7
|
+
json?: boolean;
|
|
8
|
+
quiet?: boolean;
|
|
9
|
+
}): OutputMode;
|
|
10
|
+
/**
|
|
11
|
+
* Print a formatted table to stdout.
|
|
12
|
+
*
|
|
13
|
+
* In human mode, renders an aligned ASCII table with header.
|
|
14
|
+
* In JSON mode, outputs the rows as an array of objects keyed by headers.
|
|
15
|
+
* In quiet mode, outputs each row's first column value, one per line.
|
|
16
|
+
*/
|
|
17
|
+
export declare function printTable(headers: string[], rows: string[][], options?: {
|
|
18
|
+
json?: boolean;
|
|
19
|
+
quiet?: boolean;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Print data as formatted JSON to stdout.
|
|
23
|
+
*/
|
|
24
|
+
export declare function printJson(data: unknown): void;
|
|
25
|
+
/**
|
|
26
|
+
* Print minimal output for piping / scripting.
|
|
27
|
+
*/
|
|
28
|
+
export declare function printQuiet(value: string | string[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Create an ora spinner instance.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createSpinner(text: string): Ora;
|
|
33
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAOA,OAAY,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,UAAU,CAIzF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,EAAE,EAAE,EAChB,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5C,IAAI,CAmCN;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAQzD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAE/C"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2026 agent-media contributors. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Output formatting utilities for human, JSON, and quiet modes.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
/**
|
|
8
|
+
* Detect the output mode based on CLI flags.
|
|
9
|
+
*/
|
|
10
|
+
export function detectOutputMode(options) {
|
|
11
|
+
if (options.json)
|
|
12
|
+
return 'json';
|
|
13
|
+
if (options.quiet)
|
|
14
|
+
return 'quiet';
|
|
15
|
+
return 'human';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Print a formatted table to stdout.
|
|
19
|
+
*
|
|
20
|
+
* In human mode, renders an aligned ASCII table with header.
|
|
21
|
+
* In JSON mode, outputs the rows as an array of objects keyed by headers.
|
|
22
|
+
* In quiet mode, outputs each row's first column value, one per line.
|
|
23
|
+
*/
|
|
24
|
+
export function printTable(headers, rows, options) {
|
|
25
|
+
const mode = detectOutputMode(options ?? {});
|
|
26
|
+
if (mode === 'json') {
|
|
27
|
+
const data = rows.map((row) => {
|
|
28
|
+
const obj = {};
|
|
29
|
+
headers.forEach((header, i) => {
|
|
30
|
+
obj[header.toLowerCase().replace(/\s+/g, '_')] = row[i] ?? '';
|
|
31
|
+
});
|
|
32
|
+
return obj;
|
|
33
|
+
});
|
|
34
|
+
printJson(data);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (mode === 'quiet') {
|
|
38
|
+
printQuiet(rows.map((row) => row[0] ?? ''));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Human mode: calculate column widths and render aligned table
|
|
42
|
+
const colWidths = headers.map((header, i) => Math.max(header.length, ...rows.map((row) => (row[i] ?? '').length)));
|
|
43
|
+
const headerLine = headers.map((h, i) => h.padEnd(colWidths[i])).join(' ');
|
|
44
|
+
const separator = colWidths.map((w) => '─'.repeat(w)).join('──');
|
|
45
|
+
console.log(chalk.bold(headerLine));
|
|
46
|
+
console.log(chalk.dim(separator));
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
const line = row.map((cell, i) => cell.padEnd(colWidths[i])).join(' ');
|
|
49
|
+
console.log(line);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Print data as formatted JSON to stdout.
|
|
54
|
+
*/
|
|
55
|
+
export function printJson(data) {
|
|
56
|
+
console.log(JSON.stringify(data, null, 2));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Print minimal output for piping / scripting.
|
|
60
|
+
*/
|
|
61
|
+
export function printQuiet(value) {
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
for (const v of value) {
|
|
64
|
+
console.log(v);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.log(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create an ora spinner instance.
|
|
73
|
+
*/
|
|
74
|
+
export function createSpinner(text) {
|
|
75
|
+
return ora({ text, spinner: 'dots' });
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAE/D;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAiB,MAAM,KAAK,CAAC;AAGpC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA4C;IAC3E,IAAI,OAAO,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IAChC,IAAI,OAAO,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,OAAiB,EACjB,IAAgB,EAChB,OAA6C;IAE7C,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE7C,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC5B,MAAM,GAAG,GAA2B,EAAE,CAAC;YACvC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC5B,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAChE,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;QACH,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,OAAO;IACT,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,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AAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwB;IACjD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific type definitions.
|
|
3
|
+
*/
|
|
4
|
+
export interface GlobalOptions {
|
|
5
|
+
json?: boolean;
|
|
6
|
+
quiet?: boolean;
|
|
7
|
+
noColor?: boolean;
|
|
8
|
+
verbose?: boolean;
|
|
9
|
+
profile?: string;
|
|
10
|
+
}
|
|
11
|
+
export type OutputMode = 'human' | 'json' | 'quiet';
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+DAA+D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agent-media-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"description": "Open-source CLI for unified AI video and image generation",
|
|
8
|
+
"homepage": "https://agent-media.ai",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/yuvalsuede/agent-media.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ai",
|
|
15
|
+
"video",
|
|
16
|
+
"image",
|
|
17
|
+
"generation",
|
|
18
|
+
"cli",
|
|
19
|
+
"terminal",
|
|
20
|
+
"media"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"bin": {
|
|
25
|
+
"agent-media": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"lint": "eslint src/",
|
|
36
|
+
"prepublishOnly": "npm run build"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"chalk": "^5.4.1",
|
|
40
|
+
"commander": "^13.1.0",
|
|
41
|
+
"open": "^10.1.0",
|
|
42
|
+
"ora": "^8.2.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.13.4",
|
|
46
|
+
"typescript": "^5.7.3"
|
|
47
|
+
}
|
|
48
|
+
}
|