@ph0ny/cli 0.1.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/README.md +155 -0
- package/bin/phony.js +2 -0
- package/dist/commands/agents.d.ts +14 -0
- package/dist/commands/agents.d.ts.map +1 -0
- package/dist/commands/agents.js +145 -0
- package/dist/commands/agents.js.map +1 -0
- package/dist/commands/auth.d.ts +11 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +50 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/call.d.ts +17 -0
- package/dist/commands/call.d.ts.map +1 -0
- package/dist/commands/call.js +165 -0
- package/dist/commands/call.js.map +1 -0
- package/dist/commands/campaign.d.ts +11 -0
- package/dist/commands/campaign.d.ts.map +1 -0
- package/dist/commands/campaign.js +26 -0
- package/dist/commands/campaign.js.map +1 -0
- package/dist/commands/contacts.d.ts +6 -0
- package/dist/commands/contacts.d.ts.map +1 -0
- package/dist/commands/contacts.js +45 -0
- package/dist/commands/contacts.js.map +1 -0
- package/dist/commands/conversations.d.ts +6 -0
- package/dist/commands/conversations.d.ts.map +1 -0
- package/dist/commands/conversations.js +58 -0
- package/dist/commands/conversations.js.map +1 -0
- package/dist/commands/domains.d.ts +6 -0
- package/dist/commands/domains.d.ts.map +1 -0
- package/dist/commands/domains.js +70 -0
- package/dist/commands/domains.js.map +1 -0
- package/dist/commands/keys.d.ts +13 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +58 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/knowledge.d.ts +9 -0
- package/dist/commands/knowledge.d.ts.map +1 -0
- package/dist/commands/knowledge.js +180 -0
- package/dist/commands/knowledge.js.map +1 -0
- package/dist/commands/observability.d.ts +6 -0
- package/dist/commands/observability.d.ts.map +1 -0
- package/dist/commands/observability.js +97 -0
- package/dist/commands/observability.js.map +1 -0
- package/dist/commands/products.d.ts +6 -0
- package/dist/commands/products.d.ts.map +1 -0
- package/dist/commands/products.js +70 -0
- package/dist/commands/products.js.map +1 -0
- package/dist/commands/providers.d.ts +9 -0
- package/dist/commands/providers.d.ts.map +1 -0
- package/dist/commands/providers.js +70 -0
- package/dist/commands/providers.js.map +1 -0
- package/dist/commands/raw.d.ts +8 -0
- package/dist/commands/raw.d.ts.map +1 -0
- package/dist/commands/raw.js +46 -0
- package/dist/commands/raw.js.map +1 -0
- package/dist/commands/tasks.d.ts +6 -0
- package/dist/commands/tasks.d.ts.map +1 -0
- package/dist/commands/tasks.js +120 -0
- package/dist/commands/tasks.js.map +1 -0
- package/dist/commands/tests.d.ts +6 -0
- package/dist/commands/tests.d.ts.map +1 -0
- package/dist/commands/tests.js +190 -0
- package/dist/commands/tests.js.map +1 -0
- package/dist/commands/tools.d.ts +6 -0
- package/dist/commands/tools.d.ts.map +1 -0
- package/dist/commands/tools.js +105 -0
- package/dist/commands/tools.js.map +1 -0
- package/dist/commands/voices.d.ts +6 -0
- package/dist/commands/voices.d.ts.map +1 -0
- package/dist/commands/voices.js +114 -0
- package/dist/commands/voices.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/agent-payload.d.ts +28 -0
- package/dist/lib/agent-payload.d.ts.map +1 -0
- package/dist/lib/agent-payload.js +65 -0
- package/dist/lib/agent-payload.js.map +1 -0
- package/dist/lib/call-payload.d.ts +42 -0
- package/dist/lib/call-payload.d.ts.map +1 -0
- package/dist/lib/call-payload.js +63 -0
- package/dist/lib/call-payload.js.map +1 -0
- package/dist/lib/client.d.ts +23 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/client.js +25 -0
- package/dist/lib/client.js.map +1 -0
- package/dist/lib/command-utils.d.ts +10 -0
- package/dist/lib/command-utils.d.ts.map +1 -0
- package/dist/lib/command-utils.js +55 -0
- package/dist/lib/command-utils.js.map +1 -0
- package/dist/lib/config.d.ts +47 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +90 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +25 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +73 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/exit.d.ts +20 -0
- package/dist/lib/exit.d.ts.map +1 -0
- package/dist/lib/exit.js +24 -0
- package/dist/lib/exit.js.map +1 -0
- package/dist/lib/json-file.d.ts +7 -0
- package/dist/lib/json-file.d.ts.map +1 -0
- package/dist/lib/json-file.js +29 -0
- package/dist/lib/json-file.js.map +1 -0
- package/dist/lib/output.d.ts +18 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +60 -0
- package/dist/lib/output.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function parseOptionalInt(value: string | undefined, flag: string): number | undefined;
|
|
2
|
+
export declare function parsePositiveInt(value: string | undefined, flag: string): number | undefined;
|
|
3
|
+
export declare function parseOptionalFloat(value: string | undefined, flag: string): number | undefined;
|
|
4
|
+
export declare function parseCsv(value: string | undefined): string[] | undefined;
|
|
5
|
+
export declare function readJsonFileIfSet(path: string | undefined, flag: string): Record<string, unknown> | undefined;
|
|
6
|
+
export declare function requireJsonFile(path: string | undefined, flag: string): Record<string, unknown>;
|
|
7
|
+
export declare function requireJsonValueFile(path: string | undefined, flag: string): unknown;
|
|
8
|
+
export declare function readSecretFromEnv(envName: string | undefined, flag: string): string;
|
|
9
|
+
export declare function maybeMetadata(path: string | undefined): Record<string, unknown> | undefined;
|
|
10
|
+
//# sourceMappingURL=command-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-utils.d.ts","sourceRoot":"","sources":["../../src/lib/command-utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK5F;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI5F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK9F;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAIxE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAE7G;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG/F;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKnF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAE3F"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { UsageError } from './exit.js';
|
|
2
|
+
import { readJsonObjectFile, readJsonValueFile } from './json-file.js';
|
|
3
|
+
export function parseOptionalInt(value, flag) {
|
|
4
|
+
if (value === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
const n = Number.parseInt(value, 10);
|
|
7
|
+
if (!Number.isInteger(n))
|
|
8
|
+
throw new UsageError(`${flag} must be an integer.`, 'INVALID_ARG');
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
export function parsePositiveInt(value, flag) {
|
|
12
|
+
const n = parseOptionalInt(value, flag);
|
|
13
|
+
if (n !== undefined && n <= 0)
|
|
14
|
+
throw new UsageError(`${flag} must be a positive integer.`, 'INVALID_ARG');
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
export function parseOptionalFloat(value, flag) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
const n = Number.parseFloat(value);
|
|
21
|
+
if (!Number.isFinite(n))
|
|
22
|
+
throw new UsageError(`${flag} must be a number.`, 'INVALID_ARG');
|
|
23
|
+
return n;
|
|
24
|
+
}
|
|
25
|
+
export function parseCsv(value) {
|
|
26
|
+
if (!value)
|
|
27
|
+
return undefined;
|
|
28
|
+
const values = value.split(',').map(part => part.trim()).filter(Boolean);
|
|
29
|
+
return values.length ? values : undefined;
|
|
30
|
+
}
|
|
31
|
+
export function readJsonFileIfSet(path, flag) {
|
|
32
|
+
return path ? readJsonObjectFile(path, flag) : undefined;
|
|
33
|
+
}
|
|
34
|
+
export function requireJsonFile(path, flag) {
|
|
35
|
+
if (!path)
|
|
36
|
+
throw new UsageError(`Missing ${flag} <json>.`, 'MISSING_ARG');
|
|
37
|
+
return readJsonObjectFile(path, flag);
|
|
38
|
+
}
|
|
39
|
+
export function requireJsonValueFile(path, flag) {
|
|
40
|
+
if (!path)
|
|
41
|
+
throw new UsageError(`Missing ${flag} <json>.`, 'MISSING_ARG');
|
|
42
|
+
return readJsonValueFile(path, flag);
|
|
43
|
+
}
|
|
44
|
+
export function readSecretFromEnv(envName, flag) {
|
|
45
|
+
if (!envName?.trim())
|
|
46
|
+
throw new UsageError(`Missing ${flag} <env-var>.`, 'MISSING_ARG');
|
|
47
|
+
const value = process.env[envName]?.trim();
|
|
48
|
+
if (!value)
|
|
49
|
+
throw new UsageError(`${flag} references ${envName}, but that environment variable is empty.`, 'MISSING_SECRET');
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
export function maybeMetadata(path) {
|
|
53
|
+
return readJsonFileIfSet(path, '--metadata-file');
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=command-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-utils.js","sourceRoot":"","sources":["../../src/lib/command-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEtE,MAAM,UAAU,gBAAgB,CAAC,KAAyB,EAAE,IAAY;IACtE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACzC,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACpC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,sBAAsB,EAAE,aAAa,CAAC,CAAA;IAC5F,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAyB,EAAE,IAAY;IACtE,MAAM,CAAC,GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IACvC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,8BAA8B,EAAE,aAAa,CAAC,CAAA;IACzG,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAyB,EAAE,IAAY;IACxE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACzC,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IAClC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,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AK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAA;IAC1C,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,eAAe,OAAO,2CAA2C,EAAE,gBAAgB,CAAC,CAAA;IAC5H,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAwB;IACpD,OAAO,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential + base-URL resolution.
|
|
3
|
+
*
|
|
4
|
+
* The CLI is driven by autonomous agents, so secrets are NEVER accepted on the
|
|
5
|
+
* command line (argv leaks into process listings, shell history, and logs).
|
|
6
|
+
* The API key resolves from, in order:
|
|
7
|
+
* 1. PHONY_API_KEY environment variable
|
|
8
|
+
* 2. the active profile's `apiKey` in ~/.phony/config.json
|
|
9
|
+
*
|
|
10
|
+
* The base URL resolves from, in order:
|
|
11
|
+
* 1. PHONY_BASE_URL environment variable
|
|
12
|
+
* 2. the active profile's `baseUrl`
|
|
13
|
+
* 3. https://api.ph0ny.com
|
|
14
|
+
*
|
|
15
|
+
* The active profile is PHONY_PROFILE if set, else the config's `activeProfile`,
|
|
16
|
+
* else "default".
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_BASE_URL = "https://api.ph0ny.com";
|
|
19
|
+
export declare const DEFAULT_PROFILE = "default";
|
|
20
|
+
export declare const API_KEY_PREFIX = "plabs_";
|
|
21
|
+
export interface ProfileConfig {
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PhonyConfig {
|
|
26
|
+
activeProfile?: string;
|
|
27
|
+
profiles?: Record<string, ProfileConfig>;
|
|
28
|
+
}
|
|
29
|
+
export type CredentialSource = 'env' | 'profile' | 'none';
|
|
30
|
+
export interface ResolvedContext {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
/** Platform root, e.g. https://api.ph0ny.com (no /v1 suffix). */
|
|
33
|
+
baseUrl: string;
|
|
34
|
+
profile: string;
|
|
35
|
+
apiKeySource: CredentialSource;
|
|
36
|
+
}
|
|
37
|
+
export declare function getActiveProfile(config?: PhonyConfig): string;
|
|
38
|
+
export declare function resolveBaseUrl(config?: PhonyConfig, profile?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve full auth context. Throws a UsageError (exit 2) when no key is found
|
|
41
|
+
* so callers get a clean, actionable message instead of a stack trace.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveContext(): ResolvedContext;
|
|
44
|
+
/** The /v1 base the SDK and raw fetch calls use. */
|
|
45
|
+
export declare function v1BaseUrl(baseUrl: string): string;
|
|
46
|
+
export declare function getConfigPath(): string;
|
|
47
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,eAAO,MAAM,gBAAgB,0BAA0B,CAAA;AACvD,eAAO,MAAM,eAAe,YAAY,CAAA;AACxC,eAAO,MAAM,cAAc,WAAW,CAAA;AAKtC,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CACzC;AAED,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;AAEzD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,gBAAgB,CAAA;CAC/B;AAcD,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,WAA8B,GAAG,MAAM,CAI/E;AAUD,wBAAgB,cAAc,CAAC,MAAM,GAAE,WAA8B,EAAE,OAAO,SAA2B,GAAG,MAAM,CAMjH;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,eAAe,CAiBhD;AAED,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGjD;AAMD,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential + base-URL resolution.
|
|
3
|
+
*
|
|
4
|
+
* The CLI is driven by autonomous agents, so secrets are NEVER accepted on the
|
|
5
|
+
* command line (argv leaks into process listings, shell history, and logs).
|
|
6
|
+
* The API key resolves from, in order:
|
|
7
|
+
* 1. PHONY_API_KEY environment variable
|
|
8
|
+
* 2. the active profile's `apiKey` in ~/.phony/config.json
|
|
9
|
+
*
|
|
10
|
+
* The base URL resolves from, in order:
|
|
11
|
+
* 1. PHONY_BASE_URL environment variable
|
|
12
|
+
* 2. the active profile's `baseUrl`
|
|
13
|
+
* 3. https://api.ph0ny.com
|
|
14
|
+
*
|
|
15
|
+
* The active profile is PHONY_PROFILE if set, else the config's `activeProfile`,
|
|
16
|
+
* else "default".
|
|
17
|
+
*/
|
|
18
|
+
import * as fs from 'node:fs';
|
|
19
|
+
import * as os from 'node:os';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import { UsageError } from './exit.js';
|
|
22
|
+
export const DEFAULT_BASE_URL = 'https://api.ph0ny.com';
|
|
23
|
+
export const DEFAULT_PROFILE = 'default';
|
|
24
|
+
export const API_KEY_PREFIX = 'plabs_';
|
|
25
|
+
const CONFIG_DIR = path.join(os.homedir(), '.phony');
|
|
26
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
27
|
+
function loadConfigFrom(file = CONFIG_FILE) {
|
|
28
|
+
try {
|
|
29
|
+
if (fs.existsSync(file)) {
|
|
30
|
+
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// A malformed config file must not crash the CLI; treat it as absent. The
|
|
35
|
+
// resulting "no API key" error is the loud, actionable signal.
|
|
36
|
+
}
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
export function getActiveProfile(config = loadConfigFrom()) {
|
|
40
|
+
const envProfile = process.env.PHONY_PROFILE?.trim();
|
|
41
|
+
if (envProfile)
|
|
42
|
+
return envProfile;
|
|
43
|
+
return config.activeProfile?.trim() || DEFAULT_PROFILE;
|
|
44
|
+
}
|
|
45
|
+
function resolveApiKey(config, profile) {
|
|
46
|
+
const envKey = process.env.PHONY_API_KEY?.trim();
|
|
47
|
+
if (envKey)
|
|
48
|
+
return { value: envKey, source: 'env' };
|
|
49
|
+
const profileKey = config.profiles?.[profile]?.apiKey?.trim();
|
|
50
|
+
if (profileKey)
|
|
51
|
+
return { value: profileKey, source: 'profile' };
|
|
52
|
+
return { source: 'none' };
|
|
53
|
+
}
|
|
54
|
+
export function resolveBaseUrl(config = loadConfigFrom(), profile = getActiveProfile(config)) {
|
|
55
|
+
const envUrl = process.env.PHONY_BASE_URL?.trim();
|
|
56
|
+
if (envUrl)
|
|
57
|
+
return stripTrailingSlash(envUrl);
|
|
58
|
+
const profileUrl = config.profiles?.[profile]?.baseUrl?.trim();
|
|
59
|
+
if (profileUrl)
|
|
60
|
+
return stripTrailingSlash(profileUrl);
|
|
61
|
+
return DEFAULT_BASE_URL;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve full auth context. Throws a UsageError (exit 2) when no key is found
|
|
65
|
+
* so callers get a clean, actionable message instead of a stack trace.
|
|
66
|
+
*/
|
|
67
|
+
export function resolveContext() {
|
|
68
|
+
const config = loadConfigFrom();
|
|
69
|
+
const profile = getActiveProfile(config);
|
|
70
|
+
const { value: apiKey, source } = resolveApiKey(config, profile);
|
|
71
|
+
if (!apiKey) {
|
|
72
|
+
throw new UsageError(`No API key found. Set PHONY_API_KEY, or add an "apiKey" to profile "${profile}" in ${CONFIG_FILE}.`, 'NO_API_KEY');
|
|
73
|
+
}
|
|
74
|
+
if (!apiKey.startsWith(API_KEY_PREFIX)) {
|
|
75
|
+
throw new UsageError(`API key must start with "${API_KEY_PREFIX}". The resolved key (source: ${source}) does not.`, 'INVALID_API_KEY');
|
|
76
|
+
}
|
|
77
|
+
return { apiKey, baseUrl: resolveBaseUrl(config, profile), profile, apiKeySource: source };
|
|
78
|
+
}
|
|
79
|
+
/** The /v1 base the SDK and raw fetch calls use. */
|
|
80
|
+
export function v1BaseUrl(baseUrl) {
|
|
81
|
+
const root = stripTrailingSlash(baseUrl);
|
|
82
|
+
return root.endsWith('/v1') ? root : `${root}/v1`;
|
|
83
|
+
}
|
|
84
|
+
function stripTrailingSlash(value) {
|
|
85
|
+
return value.replace(/\/+$/, '');
|
|
86
|
+
}
|
|
87
|
+
export function getConfigPath() {
|
|
88
|
+
return CONFIG_FILE;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAA;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,QAA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IACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,CAAA;AACnD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAClC,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central error formatting + exit-code mapping.
|
|
3
|
+
*
|
|
4
|
+
* Every command action runs inside `run()`. It converts SDK exceptions,
|
|
5
|
+
* usage errors, and bare errors into a single message line (human mode) or a
|
|
6
|
+
* `{ error: { code, message, status? } }` object (--json), then exits with the
|
|
7
|
+
* code the error class dictates. No stack traces ever reach stdout/stderr.
|
|
8
|
+
*/
|
|
9
|
+
interface FormattedError {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
details?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function formatError(err: unknown): FormattedError;
|
|
16
|
+
export declare function exitCodeFor(err: unknown): number;
|
|
17
|
+
/** Print an error (human or JSON) and exit with the mapped code. */
|
|
18
|
+
export declare function handleError(err: unknown, json?: boolean): never;
|
|
19
|
+
/**
|
|
20
|
+
* Wrap a command action so any thrown error is formatted, printed, and mapped
|
|
21
|
+
* to an exit code. `--json` is read off the action's resolved options.
|
|
22
|
+
*/
|
|
23
|
+
export declare function run<A extends unknown[]>(action: (...args: A) => Promise<void> | void): (...args: A) => Promise<void>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAgBxD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAGhD;AAED,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,UAAQ,GAAG,KAAK,CAS7D;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,OAAO,EAAE,EACrC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAC3C,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAW/B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central error formatting + exit-code mapping.
|
|
3
|
+
*
|
|
4
|
+
* Every command action runs inside `run()`. It converts SDK exceptions,
|
|
5
|
+
* usage errors, and bare errors into a single message line (human mode) or a
|
|
6
|
+
* `{ error: { code, message, status? } }` object (--json), then exits with the
|
|
7
|
+
* code the error class dictates. No stack traces ever reach stdout/stderr.
|
|
8
|
+
*/
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import { VoiceApiException } from '@ph0ny/sdk';
|
|
11
|
+
import { printJson } from './output.js';
|
|
12
|
+
import { EXIT_FAILURE, EXIT_USAGE, UsageError } from './exit.js';
|
|
13
|
+
export function formatError(err) {
|
|
14
|
+
if (err instanceof UsageError) {
|
|
15
|
+
return { code: err.code, message: err.message };
|
|
16
|
+
}
|
|
17
|
+
if (err instanceof VoiceApiException) {
|
|
18
|
+
return {
|
|
19
|
+
code: err.code,
|
|
20
|
+
message: err.message,
|
|
21
|
+
status: err.statusCode,
|
|
22
|
+
...(err.details === undefined ? {} : { details: err.details }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (err instanceof Error) {
|
|
26
|
+
return { code: 'ERROR', message: err.message };
|
|
27
|
+
}
|
|
28
|
+
return { code: 'ERROR', message: String(err) };
|
|
29
|
+
}
|
|
30
|
+
export function exitCodeFor(err) {
|
|
31
|
+
if (err instanceof UsageError)
|
|
32
|
+
return EXIT_USAGE;
|
|
33
|
+
return EXIT_FAILURE;
|
|
34
|
+
}
|
|
35
|
+
/** Print an error (human or JSON) and exit with the mapped code. */
|
|
36
|
+
export function handleError(err, json = false) {
|
|
37
|
+
const formatted = formatError(err);
|
|
38
|
+
if (json) {
|
|
39
|
+
printJson({ error: formatted });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const status = formatted.status ? chalk.dim(` (HTTP ${formatted.status})`) : '';
|
|
43
|
+
process.stderr.write(`${chalk.red('Error')} ${chalk.dim(formatted.code)}${status}: ${formatted.message}\n`);
|
|
44
|
+
}
|
|
45
|
+
process.exit(exitCodeFor(err));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wrap a command action so any thrown error is formatted, printed, and mapped
|
|
49
|
+
* to an exit code. `--json` is read off the action's resolved options.
|
|
50
|
+
*/
|
|
51
|
+
export function run(action) {
|
|
52
|
+
return async (...args) => {
|
|
53
|
+
// commander passes (…positionals, options, command); options is the last
|
|
54
|
+
// object arg that carries the resolved flags.
|
|
55
|
+
const json = extractJsonFlag(args);
|
|
56
|
+
try {
|
|
57
|
+
await action(...args);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
handleError(err, json);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function extractJsonFlag(args) {
|
|
65
|
+
for (let i = args.length - 1; i >= 0; i--) {
|
|
66
|
+
const arg = args[i];
|
|
67
|
+
if (arg && typeof arg === 'object' && 'json' in arg) {
|
|
68
|
+
return Boolean(arg.json);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAShE,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAA;IACjD,CAAC;IACD,IAAI,GAAG,YAAY,iBAAiB,EAAE,CAAC;QACrC,OAAO;YACL,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,GAAG,CAAC,UAAU;YACtB,GAAG,CAAC,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;SAC/D,CAAA;IACH,CAAC;IACD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAA;IAChD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAA;AAChD,CAAC;AAED,MAAM,UAAU,WAAW,C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AG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAK,GAA+B,EAAE,CAAC;YACjF,OAAO,OAAO,CAAE,GAA+B,CAAC,IAAI,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process exit codes for the Phony CLI.
|
|
3
|
+
*
|
|
4
|
+
* These are a fixed contract that LLM agents and shell scripts driving the CLI
|
|
5
|
+
* can branch on without parsing output:
|
|
6
|
+
* 0 — success
|
|
7
|
+
* 1 — runtime failure (API error, network error, not found, server error)
|
|
8
|
+
* 2 — usage error (bad arguments, missing required flag, compliance gate,
|
|
9
|
+
* unbuilt feature) — the invocation is malformed and retrying as-is will
|
|
10
|
+
* not succeed.
|
|
11
|
+
*/
|
|
12
|
+
export declare const EXIT_OK = 0;
|
|
13
|
+
export declare const EXIT_FAILURE = 1;
|
|
14
|
+
export declare const EXIT_USAGE = 2;
|
|
15
|
+
/** Thrown for usage/validation problems that must exit with code 2. */
|
|
16
|
+
export declare class UsageError extends Error {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
constructor(message: string, code?: string);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=exit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.d.ts","sourceRoot":"","sources":["../../src/lib/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,IAAI,CAAA;AACxB,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,UAAU,IAAI,CAAA;AAE3B,uEAAuE;AACvE,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBACT,OAAO,EAAE,MAAM,EAAE,IAAI,SAAgB;CAKlD"}
|
package/dist/lib/exit.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process exit codes for the Phony CLI.
|
|
3
|
+
*
|
|
4
|
+
* These are a fixed contract that LLM agents and shell scripts driving the CLI
|
|
5
|
+
* can branch on without parsing output:
|
|
6
|
+
* 0 — success
|
|
7
|
+
* 1 — runtime failure (API error, network error, not found, server error)
|
|
8
|
+
* 2 — usage error (bad arguments, missing required flag, compliance gate,
|
|
9
|
+
* unbuilt feature) — the invocation is malformed and retrying as-is will
|
|
10
|
+
* not succeed.
|
|
11
|
+
*/
|
|
12
|
+
export const EXIT_OK = 0;
|
|
13
|
+
export const EXIT_FAILURE = 1;
|
|
14
|
+
export const EXIT_USAGE = 2;
|
|
15
|
+
/** Thrown for usage/validation problems that must exit with code 2. */
|
|
16
|
+
export class UsageError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(message, code = 'USAGE_ERROR') {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'UsageError';
|
|
21
|
+
this.code = code;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=exit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.js","sourceRoot":"","sources":["../../src/lib/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAA;AACxB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAA;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAA;AAE3B,uEAAuE;AACvE,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAQ;IACrB,YAAY,OAAe,EAAE,IAAI,GAAG,aAAa;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read + parse a JSON file argument into an object, raising a clean UsageError
|
|
3
|
+
* (exit 2) on a missing file or invalid JSON rather than leaking a stack trace.
|
|
4
|
+
*/
|
|
5
|
+
export declare function readJsonValueFile(filePath: string, flag: string): unknown;
|
|
6
|
+
export declare function readJsonObjectFile(filePath: string, flag: string): Record<string, unknown>;
|
|
7
|
+
//# sourceMappingURL=json-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-file.d.ts","sourceRoot":"","sources":["../../src/lib/json-file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAezE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM1F"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read + parse a JSON file argument into an object, raising a clean UsageError
|
|
3
|
+
* (exit 2) on a missing file or invalid JSON rather than leaking a stack trace.
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import { UsageError } from './exit.js';
|
|
7
|
+
export function readJsonValueFile(filePath, flag) {
|
|
8
|
+
let raw;
|
|
9
|
+
try {
|
|
10
|
+
raw = fs.readFileSync(filePath, 'utf-8');
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new UsageError(`Cannot read ${flag} file: ${filePath}`, 'FILE_NOT_FOUND');
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
throw new UsageError(`Invalid JSON in ${flag} file ${filePath}: ${err instanceof Error ? err.message : String(err)}`, 'INVALID_JSON');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function readJsonObjectFile(filePath, flag) {
|
|
23
|
+
const parsed = readJsonValueFile(filePath, flag);
|
|
24
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
25
|
+
throw new UsageError(`${flag} file ${filePath} must contain a JSON object.`, 'INVALID_JSON');
|
|
26
|
+
}
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=json-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-file.js","sourceRoot":"","sources":["../../src/lib/json-file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,IAAY;IAC9D,IAAI,GAAW,CAAA;IACf,IAAI,CAAC;QACH,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,UAAU,CAAC,eAAe,IAAI,UAAU,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAA;IACjF,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAClB,mBAAmB,IAAI,SAAS,QAAQ,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAC/F,cAAc,CACf,CAAA;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,IAAY;IAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAChD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,SAAS,QAAQ,8BAA8B,EAAE,cAAc,CAAC,CAAA;IAC9F,CAAC;IACD,OAAO,MAAiC,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output helpers.
|
|
3
|
+
*
|
|
4
|
+
* `--json` paths use `printJson` only: 2-space indentation, no ANSI colors, the
|
|
5
|
+
* raw API shape so downstream agents can `JSON.parse` stdout directly. Human
|
|
6
|
+
* paths use colored printers + spinners.
|
|
7
|
+
*/
|
|
8
|
+
import { type Ora } from 'ora';
|
|
9
|
+
/** Machine-readable JSON to stdout: 2-space indent, never colorized. */
|
|
10
|
+
export declare function printJson(data: unknown): void;
|
|
11
|
+
export declare function success(message: string): void;
|
|
12
|
+
export declare function info(message: string): void;
|
|
13
|
+
export declare function warn(message: string): void;
|
|
14
|
+
/** A spinner that is suppressed entirely in JSON mode (keeps stdout clean). */
|
|
15
|
+
export declare function spinner(text: string, json: boolean): Ora;
|
|
16
|
+
export declare function printKeyValue(pairs: Record<string, unknown>): void;
|
|
17
|
+
export declare function printTable(headers: string[], rows: unknown[][]): void;
|
|
18
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAY,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAEnC,wEAAwE;AACxE,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,GAAG,CASxD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAKlE;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,CAarE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output helpers.
|
|
3
|
+
*
|
|
4
|
+
* `--json` paths use `printJson` only: 2-space indentation, no ANSI colors, the
|
|
5
|
+
* raw API shape so downstream agents can `JSON.parse` stdout directly. Human
|
|
6
|
+
* paths use colored printers + spinners.
|
|
7
|
+
*/
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import ora from 'ora';
|
|
10
|
+
/** Machine-readable JSON to stdout: 2-space indent, never colorized. */
|
|
11
|
+
export function printJson(data) {
|
|
12
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}\n`);
|
|
13
|
+
}
|
|
14
|
+
export function success(message) {
|
|
15
|
+
console.log(chalk.green('✓'), message);
|
|
16
|
+
}
|
|
17
|
+
export function info(message) {
|
|
18
|
+
console.log(chalk.cyan('→'), message);
|
|
19
|
+
}
|
|
20
|
+
export function warn(message) {
|
|
21
|
+
console.log(chalk.yellow('!'), message);
|
|
22
|
+
}
|
|
23
|
+
/** A spinner that is suppressed entirely in JSON mode (keeps stdout clean). */
|
|
24
|
+
export function spinner(text, json) {
|
|
25
|
+
if (json) {
|
|
26
|
+
return {
|
|
27
|
+
text,
|
|
28
|
+
start() { return this; },
|
|
29
|
+
stop() { return this; },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return ora({ text, color: 'cyan' });
|
|
33
|
+
}
|
|
34
|
+
export function printKeyValue(pairs) {
|
|
35
|
+
for (const [key, value] of Object.entries(pairs)) {
|
|
36
|
+
if (value === undefined || value === null)
|
|
37
|
+
continue;
|
|
38
|
+
console.log(`${chalk.dim(`${key}:`)} ${formatCell(value)}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function printTable(headers, rows) {
|
|
42
|
+
if (rows.length === 0) {
|
|
43
|
+
console.log(chalk.dim('No items.'));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const cells = rows.map((row) => row.map(formatCell));
|
|
47
|
+
const widths = headers.map((header, i) => Math.max(header.length, ...cells.map((row) => row[i]?.length ?? 0)) + 2);
|
|
48
|
+
console.log(headers.map((header, i) => chalk.bold(header.padEnd(widths[i]))).join(''));
|
|
49
|
+
for (const row of cells) {
|
|
50
|
+
console.log(row.map((cell, i) => (cell ?? '').padEnd(widths[i])).join(''));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function formatCell(value) {
|
|
54
|
+
if (value === null || value === undefined)
|
|
55
|
+
return '—';
|
|
56
|
+
if (typeof value === 'boolean')
|
|
57
|
+
return value ? 'yes' : 'no';
|
|
58
|
+
return String(value);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,GAAiB,MAAM,KAAK,CAAA;AAEnC,wEAAwE;AACxE,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,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AE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;IAC3D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACtB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ph0ny/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line interface for the Phony Voice API — agents, knowledge, tests, voices, and outbound calls",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"phony": "./bin/phony.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"bin",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"chalk": "^5.4.1",
|
|
21
|
+
"commander": "^12.1.0",
|
|
22
|
+
"dotenv": "^16.4.7",
|
|
23
|
+
"ora": "^8.1.1",
|
|
24
|
+
"@ph0ny/sdk": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.10.0",
|
|
28
|
+
"typescript": "^5.4.0",
|
|
29
|
+
"vitest": "^4.0.18"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/drewstone/ph0ny.git",
|
|
38
|
+
"directory": "packages/cli"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"voice",
|
|
42
|
+
"ai",
|
|
43
|
+
"agents",
|
|
44
|
+
"cli",
|
|
45
|
+
"outbound",
|
|
46
|
+
"conversational-ai"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.json",
|
|
50
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
51
|
+
"clean": "rm -rf dist",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest"
|
|
54
|
+
}
|
|
55
|
+
}
|