praisonai 1.2.2 → 1.2.3

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 (160) hide show
  1. package/dist/agent/simple.js +1 -1
  2. package/dist/cli/commands/auto.d.ts +12 -0
  3. package/dist/cli/commands/auto.js +109 -0
  4. package/dist/cli/commands/autonomy.d.ts +5 -0
  5. package/dist/cli/commands/autonomy.js +152 -0
  6. package/dist/cli/commands/cache.d.ts +9 -0
  7. package/dist/cli/commands/cache.js +143 -0
  8. package/dist/cli/commands/chat.d.ts +14 -0
  9. package/dist/cli/commands/chat.js +127 -0
  10. package/dist/cli/commands/checkpoints.d.ts +5 -0
  11. package/dist/cli/commands/checkpoints.js +236 -0
  12. package/dist/cli/commands/context.d.ts +11 -0
  13. package/dist/cli/commands/context.js +182 -0
  14. package/dist/cli/commands/cost.d.ts +5 -0
  15. package/dist/cli/commands/cost.js +146 -0
  16. package/dist/cli/commands/db.d.ts +9 -0
  17. package/dist/cli/commands/db.js +149 -0
  18. package/dist/cli/commands/eval.d.ts +17 -0
  19. package/dist/cli/commands/eval.js +247 -0
  20. package/dist/cli/commands/external-agents.d.ts +5 -0
  21. package/dist/cli/commands/external-agents.js +169 -0
  22. package/dist/cli/commands/fast-context.d.ts +5 -0
  23. package/dist/cli/commands/fast-context.js +126 -0
  24. package/dist/cli/commands/flow.d.ts +5 -0
  25. package/dist/cli/commands/flow.js +141 -0
  26. package/dist/cli/commands/git.d.ts +5 -0
  27. package/dist/cli/commands/git.js +178 -0
  28. package/dist/cli/commands/graph-rag.d.ts +9 -0
  29. package/dist/cli/commands/graph-rag.js +131 -0
  30. package/dist/cli/commands/guardrail.d.ts +11 -0
  31. package/dist/cli/commands/guardrail.js +156 -0
  32. package/dist/cli/commands/handoff.d.ts +9 -0
  33. package/dist/cli/commands/handoff.js +133 -0
  34. package/dist/cli/commands/help.d.ts +8 -0
  35. package/dist/cli/commands/help.js +167 -0
  36. package/dist/cli/commands/image.d.ts +13 -0
  37. package/dist/cli/commands/image.js +192 -0
  38. package/dist/cli/commands/interactive.d.ts +6 -0
  39. package/dist/cli/commands/interactive.js +79 -0
  40. package/dist/cli/commands/jobs.d.ts +5 -0
  41. package/dist/cli/commands/jobs.js +282 -0
  42. package/dist/cli/commands/knowledge.d.ts +9 -0
  43. package/dist/cli/commands/knowledge.js +226 -0
  44. package/dist/cli/commands/mcp.d.ts +9 -0
  45. package/dist/cli/commands/mcp.js +243 -0
  46. package/dist/cli/commands/memory.d.ts +10 -0
  47. package/dist/cli/commands/memory.js +198 -0
  48. package/dist/cli/commands/n8n.d.ts +5 -0
  49. package/dist/cli/commands/n8n.js +137 -0
  50. package/dist/cli/commands/observability.d.ts +9 -0
  51. package/dist/cli/commands/observability.js +145 -0
  52. package/dist/cli/commands/planning.d.ts +9 -0
  53. package/dist/cli/commands/planning.js +167 -0
  54. package/dist/cli/commands/prompt-expand.d.ts +11 -0
  55. package/dist/cli/commands/prompt-expand.js +100 -0
  56. package/dist/cli/commands/providers.d.ts +9 -0
  57. package/dist/cli/commands/providers.js +98 -0
  58. package/dist/cli/commands/query-rewrite.d.ts +12 -0
  59. package/dist/cli/commands/query-rewrite.js +102 -0
  60. package/dist/cli/commands/repo-map.d.ts +5 -0
  61. package/dist/cli/commands/repo-map.js +151 -0
  62. package/dist/cli/commands/reranker.d.ts +10 -0
  63. package/dist/cli/commands/reranker.js +144 -0
  64. package/dist/cli/commands/research.d.ts +12 -0
  65. package/dist/cli/commands/research.js +108 -0
  66. package/dist/cli/commands/router.d.ts +11 -0
  67. package/dist/cli/commands/router.js +142 -0
  68. package/dist/cli/commands/run.d.ts +14 -0
  69. package/dist/cli/commands/run.js +111 -0
  70. package/dist/cli/commands/sandbox.d.ts +5 -0
  71. package/dist/cli/commands/sandbox.js +135 -0
  72. package/dist/cli/commands/scheduler.d.ts +5 -0
  73. package/dist/cli/commands/scheduler.js +260 -0
  74. package/dist/cli/commands/session.d.ts +9 -0
  75. package/dist/cli/commands/session.js +238 -0
  76. package/dist/cli/commands/skills.d.ts +9 -0
  77. package/dist/cli/commands/skills.js +256 -0
  78. package/dist/cli/commands/telemetry.d.ts +9 -0
  79. package/dist/cli/commands/telemetry.js +146 -0
  80. package/dist/cli/commands/tools.d.ts +9 -0
  81. package/dist/cli/commands/tools.js +172 -0
  82. package/dist/cli/commands/vector.d.ts +10 -0
  83. package/dist/cli/commands/vector.js +171 -0
  84. package/dist/cli/commands/version.d.ts +8 -0
  85. package/dist/cli/commands/version.js +68 -0
  86. package/dist/cli/commands/voice.d.ts +10 -0
  87. package/dist/cli/commands/voice.js +162 -0
  88. package/dist/cli/commands/workflow.d.ts +13 -0
  89. package/dist/cli/commands/workflow.js +184 -0
  90. package/dist/cli/config/index.d.ts +6 -0
  91. package/dist/cli/config/index.js +22 -0
  92. package/dist/cli/config/load.d.ts +20 -0
  93. package/dist/cli/config/load.js +229 -0
  94. package/dist/cli/config/resolve.d.ts +28 -0
  95. package/dist/cli/config/resolve.js +70 -0
  96. package/dist/cli/config/schema.d.ts +15 -0
  97. package/dist/cli/config/schema.js +65 -0
  98. package/dist/cli/features/autonomy-mode.d.ts +98 -0
  99. package/dist/cli/features/autonomy-mode.js +266 -0
  100. package/dist/cli/features/background-jobs.d.ts +155 -0
  101. package/dist/cli/features/background-jobs.js +416 -0
  102. package/dist/cli/features/checkpoints.d.ts +126 -0
  103. package/dist/cli/features/checkpoints.js +288 -0
  104. package/dist/cli/features/cost-tracker.d.ts +101 -0
  105. package/dist/cli/features/cost-tracker.js +212 -0
  106. package/dist/cli/features/external-agents.d.ts +115 -0
  107. package/dist/cli/features/external-agents.js +294 -0
  108. package/dist/cli/features/fast-context.d.ts +126 -0
  109. package/dist/cli/features/fast-context.js +310 -0
  110. package/dist/cli/features/flow-display.d.ts +100 -0
  111. package/dist/cli/features/flow-display.js +254 -0
  112. package/dist/cli/features/git-integration.d.ts +138 -0
  113. package/dist/cli/features/git-integration.js +374 -0
  114. package/dist/cli/features/index.d.ts +17 -0
  115. package/dist/cli/features/index.js +102 -0
  116. package/dist/cli/features/interactive-tui.d.ts +114 -0
  117. package/dist/cli/features/interactive-tui.js +326 -0
  118. package/dist/cli/features/n8n-integration.d.ts +108 -0
  119. package/dist/cli/features/n8n-integration.js +296 -0
  120. package/dist/cli/features/repo-map.d.ts +101 -0
  121. package/dist/cli/features/repo-map.js +350 -0
  122. package/dist/cli/features/sandbox-executor.d.ts +89 -0
  123. package/dist/cli/features/sandbox-executor.js +314 -0
  124. package/dist/cli/features/scheduler.d.ts +111 -0
  125. package/dist/cli/features/scheduler.js +298 -0
  126. package/dist/cli/features/slash-commands.d.ts +77 -0
  127. package/dist/cli/features/slash-commands.js +316 -0
  128. package/dist/cli/index.d.ts +19 -15
  129. package/dist/cli/index.js +163 -123
  130. package/dist/cli/output/errors.d.ts +32 -0
  131. package/dist/cli/output/errors.js +72 -0
  132. package/dist/cli/output/index.d.ts +6 -0
  133. package/dist/cli/output/index.js +22 -0
  134. package/dist/cli/output/json.d.ts +17 -0
  135. package/dist/cli/output/json.js +54 -0
  136. package/dist/cli/output/pretty.d.ts +21 -0
  137. package/dist/cli/output/pretty.js +106 -0
  138. package/dist/cli/runtime/env.d.ts +12 -0
  139. package/dist/cli/runtime/env.js +49 -0
  140. package/dist/cli/runtime/exit.d.ts +11 -0
  141. package/dist/cli/runtime/exit.js +49 -0
  142. package/dist/cli/runtime/index.d.ts +6 -0
  143. package/dist/cli/runtime/index.js +22 -0
  144. package/dist/cli/runtime/lazy.d.ts +18 -0
  145. package/dist/cli/runtime/lazy.js +85 -0
  146. package/dist/cli/spec/cli-spec.d.ts +87 -0
  147. package/dist/cli/spec/cli-spec.js +478 -0
  148. package/dist/cli/spec/index.d.ts +4 -0
  149. package/dist/cli/spec/index.js +20 -0
  150. package/dist/index.d.ts +4 -1
  151. package/dist/index.js +100 -7
  152. package/dist/memory/auto-memory.d.ts +136 -0
  153. package/dist/memory/auto-memory.js +301 -0
  154. package/dist/memory/file-memory.d.ts +88 -0
  155. package/dist/memory/file-memory.js +287 -0
  156. package/dist/memory/index.d.ts +2 -0
  157. package/dist/memory/index.js +11 -1
  158. package/dist/workflows/loop.d.ts +0 -0
  159. package/dist/workflows/loop.js +1 -0
  160. package/package.json +1 -1
@@ -1,20 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * PraisonAI TypeScript CLI
4
+ * Implements CLI Spec v1.0.0
5
+ *
6
+ * Binary: praisonai-ts
7
+ * Package: praisonai (npm)
4
8
  */
5
- interface CLIOptions {
6
- model?: string;
7
- stream?: boolean;
8
- verbose?: boolean;
9
- sessionId?: string;
10
- }
11
- declare function chat(prompt: string, options?: CLIOptions): Promise<string>;
12
- declare function listProviders(): Promise<void>;
13
- declare function version(): Promise<void>;
14
- declare function help(): Promise<void>;
15
- declare function parseArgs(args: string[]): {
9
+ import { CLI_SPEC_VERSION } from './spec/cli-spec';
10
+ export interface ParsedArgs {
16
11
  command: string;
17
- prompt: string;
18
- options: CLIOptions;
19
- };
20
- export { chat, listProviders, version, help, parseArgs };
12
+ subcommand?: string;
13
+ args: string[];
14
+ options: Record<string, unknown>;
15
+ }
16
+ /**
17
+ * Parse command line arguments according to CLI spec
18
+ */
19
+ declare function parseArgs(argv: string[]): ParsedArgs;
20
+ /**
21
+ * Load and execute a command (lazy loading)
22
+ */
23
+ declare function executeCommand(parsed: ParsedArgs): Promise<void>;
24
+ export { parseArgs, executeCommand, CLI_SPEC_VERSION };
package/dist/cli/index.js CHANGED
@@ -2,149 +2,189 @@
2
2
  "use strict";
3
3
  /**
4
4
  * PraisonAI TypeScript CLI
5
+ * Implements CLI Spec v1.0.0
6
+ *
7
+ * Binary: praisonai-ts
8
+ * Package: praisonai (npm)
5
9
  */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
6
43
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.chat = chat;
8
- exports.listProviders = listProviders;
9
- exports.version = version;
10
- exports.help = help;
44
+ exports.CLI_SPEC_VERSION = void 0;
11
45
  exports.parseArgs = parseArgs;
12
- const providers_1 = require("../llm/providers");
13
- const session_1 = require("../session");
14
- async function chat(prompt, options = {}) {
15
- const model = options.model || process.env.PRAISONAI_MODEL || 'openai/gpt-4o-mini';
16
- const provider = (0, providers_1.createProvider)(model);
17
- const session = new session_1.Session({ id: options.sessionId });
18
- session.addMessage({ role: 'user', content: prompt });
19
- if (options.stream) {
20
- let fullText = '';
21
- const stream = await provider.streamText({
22
- messages: [{ role: 'user', content: prompt }],
23
- onToken: (token) => {
24
- process.stdout.write(token);
25
- fullText += token;
26
- }
27
- });
28
- for await (const chunk of stream) {
29
- // Stream is consumed by onToken
30
- }
31
- console.log(); // New line after streaming
32
- return fullText;
33
- }
34
- else {
35
- const result = await provider.generateText({
36
- messages: [{ role: 'user', content: prompt }]
37
- });
38
- console.log(result.text);
39
- return result.text;
40
- }
41
- }
42
- async function listProviders() {
43
- console.log('Available Providers:');
44
- const available = (0, providers_1.getAvailableProviders)();
45
- const providers = ['openai', 'anthropic', 'google'];
46
- for (const p of providers) {
47
- const status = available.includes(p) ? '✅' : '❌';
48
- console.log(` ${status} ${p}`);
49
- }
50
- }
51
- async function version() {
52
- const pkg = require('../../package.json');
53
- console.log(`praisonai v${pkg.version}`);
54
- }
55
- async function help() {
56
- console.log(`
57
- PraisonAI TypeScript CLI
58
-
59
- Usage:
60
- praisonai-ts chat <prompt> Chat with an AI agent
61
- praisonai-ts providers List available providers
62
- praisonai-ts version Show version
63
- praisonai-ts help Show this help
64
-
65
- Options:
66
- --model, -m <model> Model to use (e.g., openai/gpt-4o-mini)
67
- --stream, -s Enable streaming output
68
- --verbose, -v Verbose output
69
- --session <id> Session ID for conversation continuity
70
-
71
- Environment Variables:
72
- OPENAI_API_KEY OpenAI API key
73
- ANTHROPIC_API_KEY Anthropic API key
74
- GOOGLE_API_KEY Google API key
75
- PRAISONAI_MODEL Default model
76
-
77
- Examples:
78
- praisonai-ts chat "Hello, how are you?"
79
- praisonai-ts chat "Write a poem" --stream
80
- praisonai-ts chat "Explain AI" -m anthropic/claude-sonnet-4-20250514
81
- praisonai-ts providers
82
- `);
83
- }
84
- function parseArgs(args) {
85
- const options = {};
86
- let command = 'help';
87
- let prompt = '';
46
+ exports.executeCommand = executeCommand;
47
+ const cli_spec_1 = require("./spec/cli-spec");
48
+ Object.defineProperty(exports, "CLI_SPEC_VERSION", { enumerable: true, get: function () { return cli_spec_1.CLI_SPEC_VERSION; } });
49
+ const json_1 = require("./output/json");
50
+ const errors_1 = require("./output/errors");
51
+ /**
52
+ * Parse command line arguments according to CLI spec
53
+ */
54
+ function parseArgs(argv) {
55
+ const result = {
56
+ command: 'help',
57
+ args: [],
58
+ options: {}
59
+ };
88
60
  let i = 0;
89
- while (i < args.length) {
90
- const arg = args[i];
91
- if (arg === '--model' || arg === '-m') {
92
- options.model = args[++i];
93
- }
94
- else if (arg === '--stream' || arg === '-s') {
95
- options.stream = true;
61
+ let foundCommand = false;
62
+ while (i < argv.length) {
63
+ const arg = argv[i];
64
+ if (arg.startsWith('--')) {
65
+ // Long flag
66
+ const flagName = arg.slice(2);
67
+ const nextArg = argv[i + 1];
68
+ // Check if it's a boolean flag or has a value
69
+ if (!nextArg || nextArg.startsWith('-')) {
70
+ result.options[flagName] = true;
71
+ }
72
+ else {
73
+ result.options[flagName] = nextArg;
74
+ i++;
75
+ }
96
76
  }
97
- else if (arg === '--verbose' || arg === '-v') {
98
- options.verbose = true;
77
+ else if (arg.startsWith('-') && arg.length === 2) {
78
+ // Short flag
79
+ const shortFlag = arg.slice(1);
80
+ const nextArg = argv[i + 1];
81
+ // Find the corresponding long flag name from global flags and command-specific flags
82
+ const globalFlag = cli_spec_1.GLOBAL_FLAGS.find(f => f.short === shortFlag);
83
+ // Also check command-specific flags (e.g., -m for model in chat command)
84
+ const commandShortFlags = {
85
+ 'm': 'model',
86
+ 's': 'stream',
87
+ 'a': 'agent',
88
+ 't': 'tools'
89
+ };
90
+ const flagName = globalFlag?.name || commandShortFlags[shortFlag] || shortFlag;
91
+ if (!nextArg || nextArg.startsWith('-')) {
92
+ result.options[flagName] = true;
93
+ }
94
+ else {
95
+ result.options[flagName] = nextArg;
96
+ i++;
97
+ }
99
98
  }
100
- else if (arg === '--session') {
101
- options.sessionId = args[++i];
99
+ else if (!foundCommand) {
100
+ // First non-flag argument is the command
101
+ result.command = arg;
102
+ foundCommand = true;
102
103
  }
103
- else if (!arg.startsWith('-')) {
104
- if (!command || command === 'help') {
105
- command = arg;
104
+ else if (!result.subcommand && cli_spec_1.COMMANDS[result.command]?.subcommands) {
105
+ // Check if this is a subcommand
106
+ const cmdSpec = cli_spec_1.COMMANDS[result.command];
107
+ if (cmdSpec.subcommands && arg in cmdSpec.subcommands) {
108
+ result.subcommand = arg;
106
109
  }
107
110
  else {
108
- prompt = arg;
111
+ result.args.push(arg);
109
112
  }
110
113
  }
114
+ else {
115
+ // Positional argument
116
+ result.args.push(arg);
117
+ }
111
118
  i++;
112
119
  }
113
- return { command, prompt, options };
120
+ // Handle --json shorthand
121
+ if (result.options.json) {
122
+ result.options.output = 'json';
123
+ }
124
+ return result;
114
125
  }
115
- async function main() {
116
- const args = process.argv.slice(2);
117
- const { command, prompt, options } = parseArgs(args);
118
- try {
119
- switch (command) {
120
- case 'chat':
121
- if (!prompt) {
122
- console.error('Error: Please provide a prompt');
123
- process.exit(1);
124
- }
125
- await chat(prompt, options);
126
- break;
127
- case 'providers':
128
- await listProviders();
129
- break;
130
- case 'version':
131
- await version();
132
- break;
133
- case 'help':
134
- default:
135
- await help();
136
- break;
126
+ /**
127
+ * Load and execute a command (lazy loading)
128
+ */
129
+ async function executeCommand(parsed) {
130
+ const { command, subcommand, args, options } = parsed;
131
+ // Validate command exists
132
+ if (!(0, cli_spec_1.validateCommand)(command)) {
133
+ const isJson = options.output === 'json' || options.json;
134
+ if (isJson) {
135
+ (0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.INVALID_ARGS, `Unknown command: ${command}`));
137
136
  }
137
+ else {
138
+ console.error(`Error: Unknown command '${command}'`);
139
+ console.error('Run "praisonai-ts help" for available commands');
140
+ }
141
+ process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
142
+ }
143
+ // Lazy load the command module
144
+ try {
145
+ const commandModule = await Promise.resolve(`${`./commands/${command}`}`).then(s => __importStar(require(s)));
146
+ // Pass subcommand as first arg if present
147
+ const commandArgs = subcommand ? [subcommand, ...args] : args;
148
+ await commandModule.execute(commandArgs, options);
138
149
  }
139
150
  catch (error) {
140
- console.error('Error:', error.message);
141
- if (options.verbose) {
142
- console.error(error.stack);
151
+ const cliError = (0, errors_1.normalizeError)(error);
152
+ const isJson = options.output === 'json' || options.json;
153
+ if (isJson) {
154
+ (0, json_1.outputJson)((0, json_1.formatError)(cliError.code, cliError.message, cliError.details));
155
+ }
156
+ else {
157
+ console.error(`Error: ${cliError.message}`);
158
+ if (options.verbose && error instanceof Error && error.stack) {
159
+ console.error(error.stack);
160
+ }
143
161
  }
144
- process.exit(1);
162
+ process.exit(cliError.exitCode);
163
+ }
164
+ }
165
+ /**
166
+ * Main CLI entry point
167
+ */
168
+ async function main() {
169
+ const argv = process.argv.slice(2);
170
+ // Fast path for version
171
+ if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
172
+ const helpModule = await Promise.resolve().then(() => __importStar(require('./commands/help')));
173
+ await helpModule.execute([], {});
174
+ return;
175
+ }
176
+ if (argv[0] === '--version') {
177
+ const versionModule = await Promise.resolve().then(() => __importStar(require('./commands/version')));
178
+ await versionModule.execute([], {});
179
+ return;
145
180
  }
181
+ const parsed = parseArgs(argv);
182
+ await executeCommand(parsed);
146
183
  }
147
184
  // Run CLI if executed directly
148
185
  if (require.main === module) {
149
- main();
186
+ main().catch((error) => {
187
+ console.error('Fatal error:', error.message);
188
+ process.exit(cli_spec_1.EXIT_CODES.RUNTIME_ERROR);
189
+ });
150
190
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Error normalization for CLI
3
+ * Ensures consistent error codes and messages across implementations
4
+ */
5
+ export declare const ERROR_CODES: {
6
+ readonly UNKNOWN: "UNKNOWN_ERROR";
7
+ readonly INVALID_ARGS: "INVALID_ARGUMENTS";
8
+ readonly MISSING_ARG: "MISSING_ARGUMENT";
9
+ readonly INVALID_FLAG: "INVALID_FLAG";
10
+ readonly CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND";
11
+ readonly CONFIG_PARSE_ERROR: "CONFIG_PARSE_ERROR";
12
+ readonly INVALID_PROFILE: "INVALID_PROFILE";
13
+ readonly MISSING_API_KEY: "MISSING_API_KEY";
14
+ readonly INVALID_API_KEY: "INVALID_API_KEY";
15
+ readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
16
+ readonly NETWORK_UNREACHABLE: "NETWORK_UNREACHABLE";
17
+ readonly PROVIDER_ERROR: "PROVIDER_ERROR";
18
+ readonly MODEL_NOT_FOUND: "MODEL_NOT_FOUND";
19
+ readonly TOOL_NOT_FOUND: "TOOL_NOT_FOUND";
20
+ readonly WORKFLOW_ERROR: "WORKFLOW_ERROR";
21
+ readonly AGENT_ERROR: "AGENT_ERROR";
22
+ };
23
+ export type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
24
+ export interface CLIError extends Error {
25
+ code: ErrorCode;
26
+ exitCode: number;
27
+ details?: Record<string, unknown>;
28
+ }
29
+ export declare function createError(code: ErrorCode, message: string, exitCode?: number, details?: Record<string, unknown>): CLIError;
30
+ export declare function isCLIError(error: unknown): error is CLIError;
31
+ export declare function normalizeError(error: unknown): CLIError;
32
+ export declare function formatCLIError(error: CLIError): import("../spec/cli-spec").ErrorOutput;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Error normalization for CLI
4
+ * Ensures consistent error codes and messages across implementations
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ERROR_CODES = void 0;
8
+ exports.createError = createError;
9
+ exports.isCLIError = isCLIError;
10
+ exports.normalizeError = normalizeError;
11
+ exports.formatCLIError = formatCLIError;
12
+ const cli_spec_1 = require("../spec/cli-spec");
13
+ const json_1 = require("./json");
14
+ exports.ERROR_CODES = {
15
+ // General errors
16
+ UNKNOWN: 'UNKNOWN_ERROR',
17
+ INVALID_ARGS: 'INVALID_ARGUMENTS',
18
+ MISSING_ARG: 'MISSING_ARGUMENT',
19
+ INVALID_FLAG: 'INVALID_FLAG',
20
+ // Config errors
21
+ CONFIG_NOT_FOUND: 'CONFIG_NOT_FOUND',
22
+ CONFIG_PARSE_ERROR: 'CONFIG_PARSE_ERROR',
23
+ INVALID_PROFILE: 'INVALID_PROFILE',
24
+ // Auth errors
25
+ MISSING_API_KEY: 'MISSING_API_KEY',
26
+ INVALID_API_KEY: 'INVALID_API_KEY',
27
+ // Network errors
28
+ NETWORK_TIMEOUT: 'NETWORK_TIMEOUT',
29
+ NETWORK_UNREACHABLE: 'NETWORK_UNREACHABLE',
30
+ // Runtime errors
31
+ PROVIDER_ERROR: 'PROVIDER_ERROR',
32
+ MODEL_NOT_FOUND: 'MODEL_NOT_FOUND',
33
+ TOOL_NOT_FOUND: 'TOOL_NOT_FOUND',
34
+ WORKFLOW_ERROR: 'WORKFLOW_ERROR',
35
+ AGENT_ERROR: 'AGENT_ERROR'
36
+ };
37
+ function createError(code, message, exitCode = cli_spec_1.EXIT_CODES.RUNTIME_ERROR, details) {
38
+ const error = new Error(message);
39
+ error.code = code;
40
+ error.exitCode = exitCode;
41
+ error.details = details;
42
+ return error;
43
+ }
44
+ function isCLIError(error) {
45
+ return error instanceof Error && 'code' in error && 'exitCode' in error;
46
+ }
47
+ function normalizeError(error) {
48
+ if (isCLIError(error)) {
49
+ return error;
50
+ }
51
+ if (error instanceof Error) {
52
+ // Try to categorize common errors
53
+ const message = error.message.toLowerCase();
54
+ if (message.includes('api key') || message.includes('unauthorized') || message.includes('401')) {
55
+ return createError(exports.ERROR_CODES.MISSING_API_KEY, error.message, cli_spec_1.EXIT_CODES.AUTH_ERROR);
56
+ }
57
+ if (message.includes('timeout') || message.includes('timed out')) {
58
+ return createError(exports.ERROR_CODES.NETWORK_TIMEOUT, error.message, cli_spec_1.EXIT_CODES.NETWORK_ERROR);
59
+ }
60
+ if (message.includes('network') || message.includes('econnrefused') || message.includes('enotfound')) {
61
+ return createError(exports.ERROR_CODES.NETWORK_UNREACHABLE, error.message, cli_spec_1.EXIT_CODES.NETWORK_ERROR);
62
+ }
63
+ if (message.includes('config') || message.includes('configuration')) {
64
+ return createError(exports.ERROR_CODES.CONFIG_PARSE_ERROR, error.message, cli_spec_1.EXIT_CODES.CONFIG_ERROR);
65
+ }
66
+ return createError(exports.ERROR_CODES.UNKNOWN, error.message);
67
+ }
68
+ return createError(exports.ERROR_CODES.UNKNOWN, String(error));
69
+ }
70
+ function formatCLIError(error) {
71
+ return (0, json_1.formatError)(error.code, error.message, error.details);
72
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Output utilities index
3
+ */
4
+ export * from './json';
5
+ export * from './pretty';
6
+ export * from './errors';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Output utilities index
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./json"), exports);
21
+ __exportStar(require("./pretty"), exports);
22
+ __exportStar(require("./errors"), exports);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * JSON output formatting for CLI
3
+ * Ensures byte-compatible output with Python CLI
4
+ */
5
+ import { CLIOutput, SuccessOutput, ErrorOutput } from '../spec/cli-spec';
6
+ export declare function formatSuccess<T>(data: T, meta?: SuccessOutput<T>['meta']): SuccessOutput<T>;
7
+ export declare function formatError(code: string, message: string, details?: Record<string, unknown>): ErrorOutput;
8
+ export declare function outputJson<T>(output: CLIOutput<T>): void;
9
+ export declare function outputJsonCompact<T>(output: CLIOutput<T>): void;
10
+ /**
11
+ * Create a success response and output it
12
+ */
13
+ export declare function printSuccess<T>(data: T, meta?: SuccessOutput<T>['meta']): void;
14
+ /**
15
+ * Create an error response and output it
16
+ */
17
+ export declare function printError(code: string, message: string, details?: Record<string, unknown>): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * JSON output formatting for CLI
4
+ * Ensures byte-compatible output with Python CLI
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.formatSuccess = formatSuccess;
8
+ exports.formatError = formatError;
9
+ exports.outputJson = outputJson;
10
+ exports.outputJsonCompact = outputJsonCompact;
11
+ exports.printSuccess = printSuccess;
12
+ exports.printError = printError;
13
+ function formatSuccess(data, meta) {
14
+ const output = {
15
+ success: true,
16
+ data
17
+ };
18
+ if (meta) {
19
+ output.meta = meta;
20
+ }
21
+ return output;
22
+ }
23
+ function formatError(code, message, details) {
24
+ const output = {
25
+ success: false,
26
+ error: {
27
+ code,
28
+ message
29
+ }
30
+ };
31
+ if (details) {
32
+ output.error.details = details;
33
+ }
34
+ return output;
35
+ }
36
+ function outputJson(output) {
37
+ // Use 2-space indentation for readability (matches Python json.dumps default)
38
+ console.log(JSON.stringify(output, null, 2));
39
+ }
40
+ function outputJsonCompact(output) {
41
+ console.log(JSON.stringify(output));
42
+ }
43
+ /**
44
+ * Create a success response and output it
45
+ */
46
+ function printSuccess(data, meta) {
47
+ outputJson(formatSuccess(data, meta));
48
+ }
49
+ /**
50
+ * Create an error response and output it
51
+ */
52
+ function printError(code, message, details) {
53
+ outputJson(formatError(code, message, details));
54
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Pretty output formatting for CLI
3
+ * Uses optional dependencies (chalk, boxen, ora) with fallbacks
4
+ */
5
+ export declare function success(message: string): Promise<void>;
6
+ export declare function error(message: string): Promise<void>;
7
+ export declare function warn(message: string): Promise<void>;
8
+ export declare function info(message: string): Promise<void>;
9
+ export declare function heading(message: string): Promise<void>;
10
+ export declare function dim(message: string): Promise<void>;
11
+ export declare function highlight(message: string): Promise<void>;
12
+ export declare function plain(message: string): void;
13
+ export declare function newline(): void;
14
+ /**
15
+ * Print a table (simple ASCII fallback)
16
+ */
17
+ export declare function table(headers: string[], rows: string[][]): void;
18
+ /**
19
+ * Print a key-value list
20
+ */
21
+ export declare function keyValue(items: Record<string, string | number | boolean>): Promise<void>;