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
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ /**
3
+ * CLI command: checkpoints
4
+ * Session state checkpointing and recovery
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.execute = execute;
8
+ const checkpoints_1 = require("../features/checkpoints");
9
+ let manager = null;
10
+ function getManager(storagePath) {
11
+ if (!manager) {
12
+ const storage = storagePath ? (0, checkpoints_1.createFileCheckpointStorage)(storagePath) : undefined;
13
+ manager = (0, checkpoints_1.createCheckpointManager)({ storage });
14
+ }
15
+ return manager;
16
+ }
17
+ async function execute(args, options) {
18
+ const subcommand = args[0] || 'help';
19
+ const isJson = Boolean(options.output === 'json' || options.json);
20
+ const storagePath = options.storage;
21
+ switch (subcommand) {
22
+ case 'create':
23
+ await handleCreate(args.slice(1), options, isJson, storagePath);
24
+ break;
25
+ case 'list':
26
+ await handleList(isJson, storagePath);
27
+ break;
28
+ case 'get':
29
+ await handleGet(args.slice(1), isJson, storagePath);
30
+ break;
31
+ case 'restore':
32
+ await handleRestore(args.slice(1), isJson, storagePath);
33
+ break;
34
+ case 'delete':
35
+ await handleDelete(args.slice(1), isJson, storagePath);
36
+ break;
37
+ case 'export':
38
+ await handleExport(args.slice(1), isJson, storagePath);
39
+ break;
40
+ case 'import':
41
+ await handleImport(args.slice(1), isJson, storagePath);
42
+ break;
43
+ case 'help':
44
+ default:
45
+ showHelp(isJson);
46
+ }
47
+ }
48
+ async function handleCreate(args, options, isJson, storagePath) {
49
+ const name = args[0] || `checkpoint-${Date.now()}`;
50
+ const mgr = getManager(storagePath);
51
+ // Set state from options if provided
52
+ const state = options.state ? JSON.parse(options.state) : {};
53
+ mgr.setState(state);
54
+ const checkpoint = await mgr.create(name, {
55
+ sessionId: options.session,
56
+ metadata: options.metadata ? JSON.parse(options.metadata) : undefined
57
+ });
58
+ if (isJson) {
59
+ console.log(JSON.stringify({ success: true, checkpoint }, null, 2));
60
+ }
61
+ else {
62
+ console.log(`✓ Checkpoint created: ${checkpoint.id}`);
63
+ console.log(` Name: ${checkpoint.name}`);
64
+ console.log(` Time: ${checkpoint.timestamp.toISOString()}`);
65
+ }
66
+ }
67
+ async function handleList(isJson, storagePath) {
68
+ const mgr = getManager(storagePath);
69
+ const checkpoints = await mgr.list();
70
+ if (isJson) {
71
+ console.log(JSON.stringify({ success: true, checkpoints }, null, 2));
72
+ }
73
+ else {
74
+ if (checkpoints.length === 0) {
75
+ console.log('No checkpoints found');
76
+ }
77
+ else {
78
+ console.log('Checkpoints:');
79
+ for (const cp of checkpoints) {
80
+ console.log(` ${cp.name} (${cp.id})`);
81
+ console.log(` Created: ${cp.timestamp.toISOString()}`);
82
+ if (cp.sessionId)
83
+ console.log(` Session: ${cp.sessionId}`);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ async function handleGet(args, isJson, storagePath) {
89
+ const id = args[0];
90
+ if (!id) {
91
+ console.error('Error: Checkpoint ID is required');
92
+ process.exit(1);
93
+ }
94
+ const mgr = getManager(storagePath);
95
+ const checkpoint = await mgr.get(id);
96
+ if (!checkpoint) {
97
+ if (isJson) {
98
+ console.log(JSON.stringify({ success: false, error: 'Checkpoint not found' }));
99
+ }
100
+ else {
101
+ console.error(`Checkpoint ${id} not found`);
102
+ }
103
+ process.exit(1);
104
+ }
105
+ if (isJson) {
106
+ console.log(JSON.stringify({ success: true, checkpoint }, null, 2));
107
+ }
108
+ else {
109
+ console.log(`Checkpoint: ${checkpoint.id}`);
110
+ console.log(` Name: ${checkpoint.name}`);
111
+ console.log(` Created: ${checkpoint.timestamp.toISOString()}`);
112
+ console.log(` State: ${JSON.stringify(checkpoint.state, null, 2)}`);
113
+ }
114
+ }
115
+ async function handleRestore(args, isJson, storagePath) {
116
+ const id = args[0];
117
+ const mgr = getManager(storagePath);
118
+ let checkpoint;
119
+ if (id) {
120
+ checkpoint = await mgr.restore(id);
121
+ }
122
+ else {
123
+ checkpoint = await mgr.restoreLatest();
124
+ }
125
+ if (!checkpoint) {
126
+ if (isJson) {
127
+ console.log(JSON.stringify({ success: false, error: 'No checkpoint to restore' }));
128
+ }
129
+ else {
130
+ console.error('No checkpoint to restore');
131
+ }
132
+ process.exit(1);
133
+ }
134
+ if (isJson) {
135
+ console.log(JSON.stringify({ success: true, restored: checkpoint }, null, 2));
136
+ }
137
+ else {
138
+ console.log(`✓ Restored checkpoint: ${checkpoint.id}`);
139
+ console.log(` Name: ${checkpoint.name}`);
140
+ console.log(` State keys: ${Object.keys(checkpoint.state).join(', ') || 'none'}`);
141
+ }
142
+ }
143
+ async function handleDelete(args, isJson, storagePath) {
144
+ const id = args[0];
145
+ if (!id) {
146
+ console.error('Error: Checkpoint ID is required');
147
+ process.exit(1);
148
+ }
149
+ const mgr = getManager(storagePath);
150
+ await mgr.delete(id);
151
+ if (isJson) {
152
+ console.log(JSON.stringify({ success: true, deleted: id }));
153
+ }
154
+ else {
155
+ console.log(`✓ Checkpoint ${id} deleted`);
156
+ }
157
+ }
158
+ async function handleExport(args, isJson, storagePath) {
159
+ const id = args[0];
160
+ if (!id) {
161
+ console.error('Error: Checkpoint ID is required');
162
+ process.exit(1);
163
+ }
164
+ const mgr = getManager(storagePath);
165
+ const exported = await mgr.export(id);
166
+ if (!exported) {
167
+ console.error(`Checkpoint ${id} not found`);
168
+ process.exit(1);
169
+ }
170
+ console.log(exported);
171
+ }
172
+ async function handleImport(args, isJson, storagePath) {
173
+ const jsonData = args[0];
174
+ if (!jsonData) {
175
+ console.error('Error: JSON data is required');
176
+ process.exit(1);
177
+ }
178
+ const mgr = getManager(storagePath);
179
+ const checkpoint = await mgr.import(jsonData);
180
+ if (isJson) {
181
+ console.log(JSON.stringify({ success: true, imported: checkpoint }, null, 2));
182
+ }
183
+ else {
184
+ console.log(`✓ Checkpoint imported: ${checkpoint.id}`);
185
+ }
186
+ }
187
+ function showHelp(isJson) {
188
+ const help = {
189
+ command: 'checkpoints',
190
+ description: 'Session state checkpointing and recovery',
191
+ subcommands: {
192
+ create: 'Create a new checkpoint',
193
+ list: 'List all checkpoints',
194
+ get: 'Get checkpoint details',
195
+ restore: 'Restore from a checkpoint',
196
+ delete: 'Delete a checkpoint',
197
+ export: 'Export checkpoint as JSON',
198
+ import: 'Import checkpoint from JSON'
199
+ },
200
+ flags: {
201
+ '--storage': 'Path to checkpoint storage directory',
202
+ '--state': 'JSON state to save with checkpoint',
203
+ '--session': 'Session ID to associate',
204
+ '--metadata': 'JSON metadata',
205
+ '--json': 'Output in JSON format'
206
+ },
207
+ examples: [
208
+ 'praisonai-ts checkpoints create my-checkpoint',
209
+ 'praisonai-ts checkpoints create --state \'{"key": "value"}\'',
210
+ 'praisonai-ts checkpoints list',
211
+ 'praisonai-ts checkpoints restore <id>',
212
+ 'praisonai-ts checkpoints restore # restores latest',
213
+ 'praisonai-ts checkpoints export <id> > checkpoint.json',
214
+ 'praisonai-ts checkpoints import \'{"name": "imported"}\'',
215
+ 'praisonai-ts checkpoints delete <id>'
216
+ ]
217
+ };
218
+ if (isJson) {
219
+ console.log(JSON.stringify(help, null, 2));
220
+ }
221
+ else {
222
+ console.log('Checkpoints - Session state checkpointing\n');
223
+ console.log('Subcommands:');
224
+ for (const [cmd, desc] of Object.entries(help.subcommands)) {
225
+ console.log(` ${cmd.padEnd(12)} ${desc}`);
226
+ }
227
+ console.log('\nFlags:');
228
+ for (const [flag, desc] of Object.entries(help.flags)) {
229
+ console.log(` ${flag.padEnd(12)} ${desc}`);
230
+ }
231
+ console.log('\nExamples:');
232
+ for (const ex of help.examples) {
233
+ console.log(` ${ex}`);
234
+ }
235
+ }
236
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Context command - Manage conversation context
3
+ */
4
+ export interface ContextOptions {
5
+ model?: string;
6
+ verbose?: boolean;
7
+ output?: 'json' | 'text' | 'pretty';
8
+ json?: boolean;
9
+ maxMessages?: number;
10
+ }
11
+ export declare function execute(args: string[], options: ContextOptions): Promise<void>;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ /**
3
+ * Context command - Manage conversation context
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.execute = execute;
40
+ const context_1 = require("../../agent/context");
41
+ const resolve_1 = require("../config/resolve");
42
+ const json_1 = require("../output/json");
43
+ const pretty = __importStar(require("../output/pretty"));
44
+ const cli_spec_1 = require("../spec/cli-spec");
45
+ const errors_1 = require("../output/errors");
46
+ async function execute(args, options) {
47
+ const action = args[0] || 'help';
48
+ const actionArgs = args.slice(1);
49
+ const outputFormat = options.json ? 'json' : (options.output || 'pretty');
50
+ const config = (0, resolve_1.resolveConfig)(options);
51
+ try {
52
+ switch (action) {
53
+ case 'chat':
54
+ await chatWithContext(actionArgs, options, config, outputFormat);
55
+ break;
56
+ case 'summarize':
57
+ await summarizeContext(actionArgs, options, config, outputFormat);
58
+ break;
59
+ case 'help':
60
+ default:
61
+ await showHelp(outputFormat);
62
+ break;
63
+ }
64
+ }
65
+ catch (error) {
66
+ if (outputFormat === 'json') {
67
+ (0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.UNKNOWN, error instanceof Error ? error.message : String(error)));
68
+ }
69
+ else {
70
+ await pretty.error(error instanceof Error ? error.message : String(error));
71
+ }
72
+ process.exit(cli_spec_1.EXIT_CODES.RUNTIME_ERROR);
73
+ }
74
+ }
75
+ async function chatWithContext(args, options, config, outputFormat) {
76
+ const message = args.join(' ');
77
+ if (!message) {
78
+ if (outputFormat === 'json') {
79
+ (0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide a message'));
80
+ }
81
+ else {
82
+ await pretty.error('Please provide a message');
83
+ }
84
+ process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
85
+ }
86
+ const startTime = Date.now();
87
+ if (outputFormat !== 'json') {
88
+ await pretty.info('Processing with context...');
89
+ }
90
+ const agent = (0, context_1.createContextAgent)({
91
+ llm: config.model,
92
+ instructions: 'You are a helpful assistant with context awareness.',
93
+ contextWindow: options.maxMessages || 10,
94
+ verbose: options.verbose
95
+ });
96
+ const result = await agent.chat(message);
97
+ const duration = Date.now() - startTime;
98
+ if (outputFormat === 'json') {
99
+ (0, json_1.outputJson)((0, json_1.formatSuccess)({
100
+ message,
101
+ response: result.text
102
+ }, {
103
+ duration_ms: duration,
104
+ model: config.model
105
+ }));
106
+ }
107
+ else {
108
+ await pretty.heading('Response');
109
+ await pretty.plain(result.text);
110
+ await pretty.newline();
111
+ await pretty.success(`Completed in ${duration}ms`);
112
+ }
113
+ }
114
+ async function summarizeContext(args, options, config, outputFormat) {
115
+ const context = args.join(' ');
116
+ if (!context) {
117
+ if (outputFormat === 'json') {
118
+ (0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide context to summarize'));
119
+ }
120
+ else {
121
+ await pretty.error('Please provide context to summarize');
122
+ }
123
+ process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
124
+ }
125
+ const startTime = Date.now();
126
+ if (outputFormat !== 'json') {
127
+ await pretty.info('Summarizing context...');
128
+ }
129
+ const agent = (0, context_1.createContextAgent)({
130
+ llm: config.model,
131
+ instructions: 'You are a summarization assistant. Provide concise summaries.',
132
+ verbose: options.verbose
133
+ });
134
+ // Use chat to summarize
135
+ const result = await agent.chat(`Please summarize the following text concisely:\n\n${context}`);
136
+ const duration = Date.now() - startTime;
137
+ if (outputFormat === 'json') {
138
+ (0, json_1.outputJson)((0, json_1.formatSuccess)({
139
+ originalLength: context.length,
140
+ summary: result.text
141
+ }, {
142
+ duration_ms: duration,
143
+ model: config.model
144
+ }));
145
+ }
146
+ else {
147
+ await pretty.heading('Summary');
148
+ await pretty.plain(result.text);
149
+ await pretty.newline();
150
+ await pretty.dim(`Original: ${context.length} chars`);
151
+ await pretty.success(`Summarized in ${duration}ms`);
152
+ }
153
+ }
154
+ async function showHelp(outputFormat) {
155
+ const help = {
156
+ command: 'context',
157
+ subcommands: [
158
+ { name: 'chat <message>', description: 'Chat with context management' },
159
+ { name: 'summarize <text>', description: 'Summarize context' },
160
+ { name: 'help', description: 'Show this help' }
161
+ ],
162
+ flags: [
163
+ { name: '--max-messages', description: 'Maximum messages to keep in context' }
164
+ ]
165
+ };
166
+ if (outputFormat === 'json') {
167
+ (0, json_1.outputJson)((0, json_1.formatSuccess)(help));
168
+ }
169
+ else {
170
+ await pretty.heading('Context Command');
171
+ await pretty.plain('Manage conversation context\n');
172
+ await pretty.plain('Subcommands:');
173
+ for (const cmd of help.subcommands) {
174
+ await pretty.plain(` ${cmd.name.padEnd(25)} ${cmd.description}`);
175
+ }
176
+ await pretty.newline();
177
+ await pretty.plain('Flags:');
178
+ for (const flag of help.flags) {
179
+ await pretty.plain(` ${flag.name.padEnd(20)} ${flag.description}`);
180
+ }
181
+ }
182
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * CLI command: cost
3
+ * Token usage and cost tracking
4
+ */
5
+ export declare function execute(args: string[], options: Record<string, unknown>): Promise<void>;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * CLI command: cost
4
+ * Token usage and cost tracking
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.execute = execute;
8
+ const cost_tracker_1 = require("../features/cost-tracker");
9
+ let tracker = null;
10
+ function getTracker() {
11
+ if (!tracker) {
12
+ tracker = (0, cost_tracker_1.createCostTracker)();
13
+ }
14
+ return tracker;
15
+ }
16
+ async function execute(args, options) {
17
+ const subcommand = args[0] || 'help';
18
+ const isJson = Boolean(options.output === 'json' || options.json);
19
+ switch (subcommand) {
20
+ case 'summary':
21
+ await handleSummary(isJson);
22
+ break;
23
+ case 'add':
24
+ await handleAdd(args.slice(1), options, isJson);
25
+ break;
26
+ case 'reset':
27
+ await handleReset(isJson);
28
+ break;
29
+ case 'pricing':
30
+ await handlePricing(args.slice(1), isJson);
31
+ break;
32
+ case 'help':
33
+ default:
34
+ showHelp(isJson);
35
+ }
36
+ }
37
+ async function handleSummary(isJson) {
38
+ const t = getTracker();
39
+ const stats = t.getStats();
40
+ const breakdown = t.getBreakdownByModel();
41
+ if (isJson) {
42
+ console.log(JSON.stringify({ success: true, stats, breakdown }, null, 2));
43
+ }
44
+ else {
45
+ console.log(t.getSummary());
46
+ if (Object.keys(breakdown).length > 0) {
47
+ console.log('\nBreakdown by model:');
48
+ for (const [model, data] of Object.entries(breakdown)) {
49
+ console.log(` ${model}: ${data.tokens} tokens, ${(0, cost_tracker_1.formatCost)(data.cost)}, ${data.requests} requests`);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ async function handleAdd(args, options, isJson) {
55
+ const model = args[0] || 'gpt-4o-mini';
56
+ const inputTokens = parseInt(args[1] || '0');
57
+ const outputTokens = parseInt(args[2] || '0');
58
+ if (isNaN(inputTokens) || isNaN(outputTokens)) {
59
+ console.error('Error: Invalid token counts');
60
+ process.exit(1);
61
+ }
62
+ const t = getTracker();
63
+ const request = t.addUsage(model, inputTokens, outputTokens);
64
+ if (isJson) {
65
+ console.log(JSON.stringify({ success: true, request }, null, 2));
66
+ }
67
+ else {
68
+ console.log(`✓ Added usage: ${model}`);
69
+ console.log(` Input: ${inputTokens} tokens`);
70
+ console.log(` Output: ${outputTokens} tokens`);
71
+ console.log(` Cost: ${(0, cost_tracker_1.formatCost)(request.cost)}`);
72
+ }
73
+ }
74
+ async function handleReset(isJson) {
75
+ const t = getTracker();
76
+ t.reset();
77
+ if (isJson) {
78
+ console.log(JSON.stringify({ success: true, message: 'Cost tracker reset' }));
79
+ }
80
+ else {
81
+ console.log('✓ Cost tracker reset');
82
+ }
83
+ }
84
+ async function handlePricing(args, isJson) {
85
+ const model = args[0];
86
+ if (model) {
87
+ const pricing = cost_tracker_1.MODEL_PRICING[model] || cost_tracker_1.MODEL_PRICING['default'];
88
+ if (isJson) {
89
+ console.log(JSON.stringify({ success: true, model, pricing }, null, 2));
90
+ }
91
+ else {
92
+ console.log(`Pricing for ${model}:`);
93
+ console.log(` Input: $${pricing.inputCostPer1k}/1K tokens`);
94
+ console.log(` Output: $${pricing.outputCostPer1k}/1K tokens`);
95
+ }
96
+ }
97
+ else {
98
+ if (isJson) {
99
+ console.log(JSON.stringify({ success: true, pricing: cost_tracker_1.MODEL_PRICING }, null, 2));
100
+ }
101
+ else {
102
+ console.log('Model Pricing (per 1K tokens):\n');
103
+ for (const [name, pricing] of Object.entries(cost_tracker_1.MODEL_PRICING)) {
104
+ if (name === 'default')
105
+ continue;
106
+ console.log(` ${name.padEnd(30)} in: $${pricing.inputCostPer1k.toFixed(5)} out: $${pricing.outputCostPer1k.toFixed(5)}`);
107
+ }
108
+ }
109
+ }
110
+ }
111
+ function showHelp(isJson) {
112
+ const help = {
113
+ command: 'cost',
114
+ description: 'Token usage and cost tracking',
115
+ subcommands: {
116
+ summary: 'Show cost summary',
117
+ add: 'Add token usage',
118
+ reset: 'Reset cost tracker',
119
+ pricing: 'Show model pricing'
120
+ },
121
+ flags: {
122
+ '--json': 'Output in JSON format'
123
+ },
124
+ examples: [
125
+ 'praisonai-ts cost summary',
126
+ 'praisonai-ts cost add gpt-4o 1000 500',
127
+ 'praisonai-ts cost pricing',
128
+ 'praisonai-ts cost pricing gpt-4o',
129
+ 'praisonai-ts cost reset'
130
+ ]
131
+ };
132
+ if (isJson) {
133
+ console.log(JSON.stringify(help, null, 2));
134
+ }
135
+ else {
136
+ console.log('Cost - Token usage and cost tracking\n');
137
+ console.log('Subcommands:');
138
+ for (const [cmd, desc] of Object.entries(help.subcommands)) {
139
+ console.log(` ${cmd.padEnd(12)} ${desc}`);
140
+ }
141
+ console.log('\nExamples:');
142
+ for (const ex of help.examples) {
143
+ console.log(` ${ex}`);
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * DB command - Database adapter management
3
+ */
4
+ export interface DbOptions {
5
+ verbose?: boolean;
6
+ output?: 'json' | 'text' | 'pretty';
7
+ json?: boolean;
8
+ }
9
+ export declare function execute(args: string[], options: DbOptions): Promise<void>;