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.
- package/dist/agent/simple.js +1 -1
- package/dist/cli/commands/auto.d.ts +12 -0
- package/dist/cli/commands/auto.js +109 -0
- package/dist/cli/commands/autonomy.d.ts +5 -0
- package/dist/cli/commands/autonomy.js +152 -0
- package/dist/cli/commands/cache.d.ts +9 -0
- package/dist/cli/commands/cache.js +143 -0
- package/dist/cli/commands/chat.d.ts +14 -0
- package/dist/cli/commands/chat.js +127 -0
- package/dist/cli/commands/checkpoints.d.ts +5 -0
- package/dist/cli/commands/checkpoints.js +236 -0
- package/dist/cli/commands/context.d.ts +11 -0
- package/dist/cli/commands/context.js +182 -0
- package/dist/cli/commands/cost.d.ts +5 -0
- package/dist/cli/commands/cost.js +146 -0
- package/dist/cli/commands/db.d.ts +9 -0
- package/dist/cli/commands/db.js +149 -0
- package/dist/cli/commands/eval.d.ts +17 -0
- package/dist/cli/commands/eval.js +247 -0
- package/dist/cli/commands/external-agents.d.ts +5 -0
- package/dist/cli/commands/external-agents.js +169 -0
- package/dist/cli/commands/fast-context.d.ts +5 -0
- package/dist/cli/commands/fast-context.js +126 -0
- package/dist/cli/commands/flow.d.ts +5 -0
- package/dist/cli/commands/flow.js +141 -0
- package/dist/cli/commands/git.d.ts +5 -0
- package/dist/cli/commands/git.js +178 -0
- package/dist/cli/commands/graph-rag.d.ts +9 -0
- package/dist/cli/commands/graph-rag.js +131 -0
- package/dist/cli/commands/guardrail.d.ts +11 -0
- package/dist/cli/commands/guardrail.js +156 -0
- package/dist/cli/commands/handoff.d.ts +9 -0
- package/dist/cli/commands/handoff.js +133 -0
- package/dist/cli/commands/help.d.ts +8 -0
- package/dist/cli/commands/help.js +167 -0
- package/dist/cli/commands/image.d.ts +13 -0
- package/dist/cli/commands/image.js +192 -0
- package/dist/cli/commands/interactive.d.ts +6 -0
- package/dist/cli/commands/interactive.js +79 -0
- package/dist/cli/commands/jobs.d.ts +5 -0
- package/dist/cli/commands/jobs.js +282 -0
- package/dist/cli/commands/knowledge.d.ts +9 -0
- package/dist/cli/commands/knowledge.js +226 -0
- package/dist/cli/commands/mcp.d.ts +9 -0
- package/dist/cli/commands/mcp.js +243 -0
- package/dist/cli/commands/memory.d.ts +10 -0
- package/dist/cli/commands/memory.js +198 -0
- package/dist/cli/commands/n8n.d.ts +5 -0
- package/dist/cli/commands/n8n.js +137 -0
- package/dist/cli/commands/observability.d.ts +9 -0
- package/dist/cli/commands/observability.js +145 -0
- package/dist/cli/commands/planning.d.ts +9 -0
- package/dist/cli/commands/planning.js +167 -0
- package/dist/cli/commands/prompt-expand.d.ts +11 -0
- package/dist/cli/commands/prompt-expand.js +100 -0
- package/dist/cli/commands/providers.d.ts +9 -0
- package/dist/cli/commands/providers.js +98 -0
- package/dist/cli/commands/query-rewrite.d.ts +12 -0
- package/dist/cli/commands/query-rewrite.js +102 -0
- package/dist/cli/commands/repo-map.d.ts +5 -0
- package/dist/cli/commands/repo-map.js +151 -0
- package/dist/cli/commands/reranker.d.ts +10 -0
- package/dist/cli/commands/reranker.js +144 -0
- package/dist/cli/commands/research.d.ts +12 -0
- package/dist/cli/commands/research.js +108 -0
- package/dist/cli/commands/router.d.ts +11 -0
- package/dist/cli/commands/router.js +142 -0
- package/dist/cli/commands/run.d.ts +14 -0
- package/dist/cli/commands/run.js +111 -0
- package/dist/cli/commands/sandbox.d.ts +5 -0
- package/dist/cli/commands/sandbox.js +135 -0
- package/dist/cli/commands/scheduler.d.ts +5 -0
- package/dist/cli/commands/scheduler.js +260 -0
- package/dist/cli/commands/session.d.ts +9 -0
- package/dist/cli/commands/session.js +238 -0
- package/dist/cli/commands/skills.d.ts +9 -0
- package/dist/cli/commands/skills.js +256 -0
- package/dist/cli/commands/telemetry.d.ts +9 -0
- package/dist/cli/commands/telemetry.js +146 -0
- package/dist/cli/commands/tools.d.ts +9 -0
- package/dist/cli/commands/tools.js +172 -0
- package/dist/cli/commands/vector.d.ts +10 -0
- package/dist/cli/commands/vector.js +171 -0
- package/dist/cli/commands/version.d.ts +8 -0
- package/dist/cli/commands/version.js +68 -0
- package/dist/cli/commands/voice.d.ts +10 -0
- package/dist/cli/commands/voice.js +162 -0
- package/dist/cli/commands/workflow.d.ts +13 -0
- package/dist/cli/commands/workflow.js +184 -0
- package/dist/cli/config/index.d.ts +6 -0
- package/dist/cli/config/index.js +22 -0
- package/dist/cli/config/load.d.ts +20 -0
- package/dist/cli/config/load.js +229 -0
- package/dist/cli/config/resolve.d.ts +28 -0
- package/dist/cli/config/resolve.js +70 -0
- package/dist/cli/config/schema.d.ts +15 -0
- package/dist/cli/config/schema.js +65 -0
- package/dist/cli/features/autonomy-mode.d.ts +98 -0
- package/dist/cli/features/autonomy-mode.js +266 -0
- package/dist/cli/features/background-jobs.d.ts +155 -0
- package/dist/cli/features/background-jobs.js +416 -0
- package/dist/cli/features/checkpoints.d.ts +126 -0
- package/dist/cli/features/checkpoints.js +288 -0
- package/dist/cli/features/cost-tracker.d.ts +101 -0
- package/dist/cli/features/cost-tracker.js +212 -0
- package/dist/cli/features/external-agents.d.ts +115 -0
- package/dist/cli/features/external-agents.js +294 -0
- package/dist/cli/features/fast-context.d.ts +126 -0
- package/dist/cli/features/fast-context.js +310 -0
- package/dist/cli/features/flow-display.d.ts +100 -0
- package/dist/cli/features/flow-display.js +254 -0
- package/dist/cli/features/git-integration.d.ts +138 -0
- package/dist/cli/features/git-integration.js +374 -0
- package/dist/cli/features/index.d.ts +17 -0
- package/dist/cli/features/index.js +102 -0
- package/dist/cli/features/interactive-tui.d.ts +114 -0
- package/dist/cli/features/interactive-tui.js +326 -0
- package/dist/cli/features/n8n-integration.d.ts +108 -0
- package/dist/cli/features/n8n-integration.js +296 -0
- package/dist/cli/features/repo-map.d.ts +101 -0
- package/dist/cli/features/repo-map.js +350 -0
- package/dist/cli/features/sandbox-executor.d.ts +89 -0
- package/dist/cli/features/sandbox-executor.js +314 -0
- package/dist/cli/features/scheduler.d.ts +111 -0
- package/dist/cli/features/scheduler.js +298 -0
- package/dist/cli/features/slash-commands.d.ts +77 -0
- package/dist/cli/features/slash-commands.js +316 -0
- package/dist/cli/index.d.ts +19 -15
- package/dist/cli/index.js +163 -123
- package/dist/cli/output/errors.d.ts +32 -0
- package/dist/cli/output/errors.js +72 -0
- package/dist/cli/output/index.d.ts +6 -0
- package/dist/cli/output/index.js +22 -0
- package/dist/cli/output/json.d.ts +17 -0
- package/dist/cli/output/json.js +54 -0
- package/dist/cli/output/pretty.d.ts +21 -0
- package/dist/cli/output/pretty.js +106 -0
- package/dist/cli/runtime/env.d.ts +12 -0
- package/dist/cli/runtime/env.js +49 -0
- package/dist/cli/runtime/exit.d.ts +11 -0
- package/dist/cli/runtime/exit.js +49 -0
- package/dist/cli/runtime/index.d.ts +6 -0
- package/dist/cli/runtime/index.js +22 -0
- package/dist/cli/runtime/lazy.d.ts +18 -0
- package/dist/cli/runtime/lazy.js +85 -0
- package/dist/cli/spec/cli-spec.d.ts +87 -0
- package/dist/cli/spec/cli-spec.js +478 -0
- package/dist/cli/spec/index.d.ts +4 -0
- package/dist/cli/spec/index.js +20 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +100 -7
- package/dist/memory/auto-memory.d.ts +136 -0
- package/dist/memory/auto-memory.js +301 -0
- package/dist/memory/file-memory.d.ts +88 -0
- package/dist/memory/file-memory.js +287 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +11 -1
- package/dist/workflows/loop.d.ts +0 -0
- package/dist/workflows/loop.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI command: interactive
|
|
4
|
+
* Interactive TUI mode with slash commands
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.execute = execute;
|
|
8
|
+
exports.showHelp = showHelp;
|
|
9
|
+
const interactive_tui_1 = require("../features/interactive-tui");
|
|
10
|
+
async function execute(args, options) {
|
|
11
|
+
const isJson = Boolean(options.output === 'json' || options.json);
|
|
12
|
+
if (isJson) {
|
|
13
|
+
console.log(JSON.stringify({
|
|
14
|
+
success: false,
|
|
15
|
+
error: 'Interactive mode does not support JSON output'
|
|
16
|
+
}));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const historyFile = options.history;
|
|
20
|
+
const model = options.model;
|
|
21
|
+
console.log('Starting interactive mode...');
|
|
22
|
+
console.log('Type /help for available commands, /exit to quit.\n');
|
|
23
|
+
const tui = (0, interactive_tui_1.createInteractiveTUI)({
|
|
24
|
+
prompt: options.prompt || '> ',
|
|
25
|
+
historyFile,
|
|
26
|
+
welcomeMessage: `PraisonAI Interactive Mode
|
|
27
|
+
Model: ${model || 'default'}
|
|
28
|
+
Type /help for commands, /exit to quit.`,
|
|
29
|
+
onMessage: async (message) => {
|
|
30
|
+
// Simple echo for now - in real usage this would call the agent
|
|
31
|
+
return `You said: ${message}`;
|
|
32
|
+
},
|
|
33
|
+
onExit: () => {
|
|
34
|
+
console.log('\nGoodbye!');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
// Update context with model if provided
|
|
38
|
+
if (model) {
|
|
39
|
+
tui.updateContext({ model });
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await tui.start();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(`Error: ${error.message}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function showHelp() {
|
|
50
|
+
console.log(`Interactive - Interactive TUI mode
|
|
51
|
+
|
|
52
|
+
Usage:
|
|
53
|
+
praisonai-ts interactive [options]
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
--model, -m Model to use
|
|
57
|
+
--prompt Custom prompt string (default: "> ")
|
|
58
|
+
--history Path to history file
|
|
59
|
+
|
|
60
|
+
Slash Commands (in interactive mode):
|
|
61
|
+
/help Show available commands
|
|
62
|
+
/cost Show token usage and cost
|
|
63
|
+
/clear Clear conversation history
|
|
64
|
+
/model [name] Show or change model
|
|
65
|
+
/tokens Show token count
|
|
66
|
+
/plan Manage task plan
|
|
67
|
+
/undo Undo last action
|
|
68
|
+
/diff Show pending changes
|
|
69
|
+
/commit Commit pending changes
|
|
70
|
+
/settings Show or modify settings
|
|
71
|
+
/map Show repository map
|
|
72
|
+
/exit Exit interactive mode
|
|
73
|
+
|
|
74
|
+
Examples:
|
|
75
|
+
praisonai-ts interactive
|
|
76
|
+
praisonai-ts interactive --model gpt-4o
|
|
77
|
+
praisonai-ts interactive --history ~/.praisonai_history
|
|
78
|
+
`);
|
|
79
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI command: jobs
|
|
4
|
+
* Background job queue management
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.execute = execute;
|
|
8
|
+
const background_jobs_1 = require("../features/background-jobs");
|
|
9
|
+
let globalQueue = null;
|
|
10
|
+
function getQueue(storagePath) {
|
|
11
|
+
if (!globalQueue) {
|
|
12
|
+
const storage = storagePath ? (0, background_jobs_1.createFileJobStorage)(storagePath) : undefined;
|
|
13
|
+
globalQueue = (0, background_jobs_1.createJobQueue)({ storage });
|
|
14
|
+
}
|
|
15
|
+
return globalQueue;
|
|
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 'add':
|
|
23
|
+
await handleAdd(args.slice(1), options, isJson, storagePath);
|
|
24
|
+
break;
|
|
25
|
+
case 'list':
|
|
26
|
+
await handleList(options, isJson, storagePath);
|
|
27
|
+
break;
|
|
28
|
+
case 'get':
|
|
29
|
+
await handleGet(args.slice(1), isJson, storagePath);
|
|
30
|
+
break;
|
|
31
|
+
case 'cancel':
|
|
32
|
+
await handleCancel(args.slice(1), isJson, storagePath);
|
|
33
|
+
break;
|
|
34
|
+
case 'retry':
|
|
35
|
+
await handleRetry(args.slice(1), isJson, storagePath);
|
|
36
|
+
break;
|
|
37
|
+
case 'process':
|
|
38
|
+
await handleProcess(args.slice(1), isJson, storagePath);
|
|
39
|
+
break;
|
|
40
|
+
case 'stats':
|
|
41
|
+
await handleStats(isJson, storagePath);
|
|
42
|
+
break;
|
|
43
|
+
case 'cleanup':
|
|
44
|
+
await handleCleanup(options, isJson, storagePath);
|
|
45
|
+
break;
|
|
46
|
+
case 'help':
|
|
47
|
+
default:
|
|
48
|
+
showHelp(isJson);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function handleAdd(args, options, isJson, storagePath) {
|
|
52
|
+
const name = args[0];
|
|
53
|
+
const dataStr = args[1] || '{}';
|
|
54
|
+
if (!name) {
|
|
55
|
+
console.error('Error: Job name is required');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
let data;
|
|
59
|
+
try {
|
|
60
|
+
data = JSON.parse(dataStr);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
data = { input: dataStr };
|
|
64
|
+
}
|
|
65
|
+
const priority = options.priority || 'normal';
|
|
66
|
+
const queue = getQueue(storagePath);
|
|
67
|
+
const job = await queue.add(name, data, {
|
|
68
|
+
priority: priority
|
|
69
|
+
});
|
|
70
|
+
if (isJson) {
|
|
71
|
+
console.log(JSON.stringify({ success: true, job }, null, 2));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(`✓ Job created: ${job.id}`);
|
|
75
|
+
console.log(` Name: ${job.name}`);
|
|
76
|
+
console.log(` Priority: ${job.priority}`);
|
|
77
|
+
console.log(` Status: ${job.status}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function handleList(options, isJson, storagePath) {
|
|
81
|
+
const queue = getQueue(storagePath);
|
|
82
|
+
const status = options.status;
|
|
83
|
+
let jobs = await queue.getAll();
|
|
84
|
+
if (status) {
|
|
85
|
+
jobs = jobs.filter(j => j.status === status);
|
|
86
|
+
}
|
|
87
|
+
if (isJson) {
|
|
88
|
+
console.log(JSON.stringify({ success: true, jobs }, null, 2));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (jobs.length === 0) {
|
|
92
|
+
console.log('No jobs found');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.log('Jobs:');
|
|
96
|
+
for (const job of jobs) {
|
|
97
|
+
console.log(` ${job.id}`);
|
|
98
|
+
console.log(` Name: ${job.name}`);
|
|
99
|
+
console.log(` Status: ${job.status}`);
|
|
100
|
+
console.log(` Priority: ${job.priority}`);
|
|
101
|
+
console.log(` Attempts: ${job.attempts}/${job.maxAttempts}`);
|
|
102
|
+
if (job.error)
|
|
103
|
+
console.log(` Error: ${job.error}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function handleGet(args, isJson, storagePath) {
|
|
109
|
+
const id = args[0];
|
|
110
|
+
if (!id) {
|
|
111
|
+
console.error('Error: Job ID is required');
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
const queue = getQueue(storagePath);
|
|
115
|
+
const job = await queue.get(id);
|
|
116
|
+
if (!job) {
|
|
117
|
+
if (isJson) {
|
|
118
|
+
console.log(JSON.stringify({ success: false, error: 'Job not found' }));
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.error(`Job ${id} not found`);
|
|
122
|
+
}
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
if (isJson) {
|
|
126
|
+
console.log(JSON.stringify({ success: true, job }, null, 2));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.log(`Job: ${job.id}`);
|
|
130
|
+
console.log(` Name: ${job.name}`);
|
|
131
|
+
console.log(` Status: ${job.status}`);
|
|
132
|
+
console.log(` Priority: ${job.priority}`);
|
|
133
|
+
console.log(` Attempts: ${job.attempts}/${job.maxAttempts}`);
|
|
134
|
+
console.log(` Created: ${job.createdAt}`);
|
|
135
|
+
if (job.startedAt)
|
|
136
|
+
console.log(` Started: ${job.startedAt}`);
|
|
137
|
+
if (job.completedAt)
|
|
138
|
+
console.log(` Completed: ${job.completedAt}`);
|
|
139
|
+
if (job.error)
|
|
140
|
+
console.log(` Error: ${job.error}`);
|
|
141
|
+
if (job.result)
|
|
142
|
+
console.log(` Result: ${JSON.stringify(job.result)}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function handleCancel(args, isJson, storagePath) {
|
|
146
|
+
const id = args[0];
|
|
147
|
+
if (!id) {
|
|
148
|
+
console.error('Error: Job ID is required');
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
const queue = getQueue(storagePath);
|
|
152
|
+
const cancelled = await queue.cancel(id);
|
|
153
|
+
if (isJson) {
|
|
154
|
+
console.log(JSON.stringify({ success: cancelled, id }));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
console.log(cancelled ? `✓ Job ${id} cancelled` : `Could not cancel job ${id}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function handleRetry(args, isJson, storagePath) {
|
|
161
|
+
const id = args[0];
|
|
162
|
+
if (!id) {
|
|
163
|
+
console.error('Error: Job ID is required');
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
const queue = getQueue(storagePath);
|
|
167
|
+
const retried = await queue.retry(id);
|
|
168
|
+
if (isJson) {
|
|
169
|
+
console.log(JSON.stringify({ success: retried, id }));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
console.log(retried ? `✓ Job ${id} queued for retry` : `Could not retry job ${id}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async function handleProcess(args, isJson, storagePath) {
|
|
176
|
+
const id = args[0];
|
|
177
|
+
if (!id) {
|
|
178
|
+
console.error('Error: Job ID is required');
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
const queue = getQueue(storagePath);
|
|
182
|
+
// Register a simple handler
|
|
183
|
+
queue.register('default', async (job) => {
|
|
184
|
+
return { processed: true, data: job.data };
|
|
185
|
+
});
|
|
186
|
+
try {
|
|
187
|
+
const result = await queue.processNow(id);
|
|
188
|
+
if (isJson) {
|
|
189
|
+
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
console.log(`✓ Job ${id} processed`);
|
|
193
|
+
console.log(` Result: ${JSON.stringify(result)}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (isJson) {
|
|
198
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
console.error(`Error: ${error.message}`);
|
|
202
|
+
}
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async function handleStats(isJson, storagePath) {
|
|
207
|
+
const queue = getQueue(storagePath);
|
|
208
|
+
const stats = await queue.getStats();
|
|
209
|
+
if (isJson) {
|
|
210
|
+
console.log(JSON.stringify({ success: true, stats }, null, 2));
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
console.log('Job Queue Stats:');
|
|
214
|
+
console.log(` Pending: ${stats.pending}`);
|
|
215
|
+
console.log(` Running: ${stats.running}`);
|
|
216
|
+
console.log(` Completed: ${stats.completed}`);
|
|
217
|
+
console.log(` Failed: ${stats.failed}`);
|
|
218
|
+
console.log(` Cancelled: ${stats.cancelled}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async function handleCleanup(options, isJson, storagePath) {
|
|
222
|
+
const queue = getQueue(storagePath);
|
|
223
|
+
const days = options.days || 7;
|
|
224
|
+
const olderThan = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
|
|
225
|
+
const count = await queue.cleanup(olderThan);
|
|
226
|
+
if (isJson) {
|
|
227
|
+
console.log(JSON.stringify({ success: true, cleaned: count }));
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
console.log(`✓ Cleaned up ${count} jobs older than ${days} days`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function showHelp(isJson) {
|
|
234
|
+
const help = {
|
|
235
|
+
command: 'jobs',
|
|
236
|
+
description: 'Background job queue management',
|
|
237
|
+
subcommands: {
|
|
238
|
+
add: 'Add a new job to the queue',
|
|
239
|
+
list: 'List all jobs',
|
|
240
|
+
get: 'Get job details',
|
|
241
|
+
cancel: 'Cancel a pending job',
|
|
242
|
+
retry: 'Retry a failed job',
|
|
243
|
+
process: 'Process a job immediately',
|
|
244
|
+
stats: 'Show queue statistics',
|
|
245
|
+
cleanup: 'Clean up old completed/failed jobs'
|
|
246
|
+
},
|
|
247
|
+
flags: {
|
|
248
|
+
'--storage': 'Path to job storage file',
|
|
249
|
+
'--priority': 'Job priority (low, normal, high, critical)',
|
|
250
|
+
'--status': 'Filter by status',
|
|
251
|
+
'--days': 'Days for cleanup threshold',
|
|
252
|
+
'--json': 'Output in JSON format'
|
|
253
|
+
},
|
|
254
|
+
examples: [
|
|
255
|
+
'praisonai-ts jobs add my-job \'{"input": "data"}\'',
|
|
256
|
+
'praisonai-ts jobs add task --priority high',
|
|
257
|
+
'praisonai-ts jobs list --status pending',
|
|
258
|
+
'praisonai-ts jobs get <job-id>',
|
|
259
|
+
'praisonai-ts jobs cancel <job-id>',
|
|
260
|
+
'praisonai-ts jobs stats',
|
|
261
|
+
'praisonai-ts jobs cleanup --days 30'
|
|
262
|
+
]
|
|
263
|
+
};
|
|
264
|
+
if (isJson) {
|
|
265
|
+
console.log(JSON.stringify(help, null, 2));
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
console.log('Jobs - Background job queue management\n');
|
|
269
|
+
console.log('Subcommands:');
|
|
270
|
+
for (const [cmd, desc] of Object.entries(help.subcommands)) {
|
|
271
|
+
console.log(` ${cmd.padEnd(12)} ${desc}`);
|
|
272
|
+
}
|
|
273
|
+
console.log('\nFlags:');
|
|
274
|
+
for (const [flag, desc] of Object.entries(help.flags)) {
|
|
275
|
+
console.log(` ${flag.padEnd(12)} ${desc}`);
|
|
276
|
+
}
|
|
277
|
+
console.log('\nExamples:');
|
|
278
|
+
for (const ex of help.examples) {
|
|
279
|
+
console.log(` ${ex}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge command - Manage knowledge base
|
|
3
|
+
*/
|
|
4
|
+
export interface KnowledgeOptions {
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
output?: 'json' | 'text' | 'pretty';
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function execute(args: string[], options: KnowledgeOptions): Promise<void>;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Knowledge command - Manage knowledge base
|
|
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 knowledge_1 = require("../../knowledge");
|
|
41
|
+
const json_1 = require("../output/json");
|
|
42
|
+
const pretty = __importStar(require("../output/pretty"));
|
|
43
|
+
const cli_spec_1 = require("../spec/cli-spec");
|
|
44
|
+
const errors_1 = require("../output/errors");
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const crypto_1 = require("crypto");
|
|
48
|
+
// Singleton knowledge base instance
|
|
49
|
+
let kbInstance = null;
|
|
50
|
+
function getKnowledgeBase() {
|
|
51
|
+
if (!kbInstance) {
|
|
52
|
+
kbInstance = new knowledge_1.BaseKnowledgeBase();
|
|
53
|
+
}
|
|
54
|
+
return kbInstance;
|
|
55
|
+
}
|
|
56
|
+
async function execute(args, options) {
|
|
57
|
+
const action = args[0] || 'help';
|
|
58
|
+
const actionArgs = args.slice(1);
|
|
59
|
+
const outputFormat = options.json ? 'json' : (options.output || 'pretty');
|
|
60
|
+
try {
|
|
61
|
+
const kb = getKnowledgeBase();
|
|
62
|
+
switch (action) {
|
|
63
|
+
case 'add':
|
|
64
|
+
await addKnowledge(kb, actionArgs, outputFormat);
|
|
65
|
+
break;
|
|
66
|
+
case 'search':
|
|
67
|
+
await searchKnowledge(kb, actionArgs, outputFormat);
|
|
68
|
+
break;
|
|
69
|
+
case 'list':
|
|
70
|
+
await listKnowledge(kb, outputFormat);
|
|
71
|
+
break;
|
|
72
|
+
case 'help':
|
|
73
|
+
default:
|
|
74
|
+
await showHelp(outputFormat);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (outputFormat === 'json') {
|
|
80
|
+
(0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.UNKNOWN, error instanceof Error ? error.message : String(error)));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
await pretty.error(error instanceof Error ? error.message : String(error));
|
|
84
|
+
}
|
|
85
|
+
process.exit(cli_spec_1.EXIT_CODES.RUNTIME_ERROR);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function addKnowledge(kb, args, outputFormat) {
|
|
89
|
+
const source = args[0];
|
|
90
|
+
if (!source) {
|
|
91
|
+
if (outputFormat === 'json') {
|
|
92
|
+
(0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide a file path or text content'));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
await pretty.error('Please provide a file path or text content');
|
|
96
|
+
}
|
|
97
|
+
process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
|
|
98
|
+
}
|
|
99
|
+
let content;
|
|
100
|
+
let sourceName;
|
|
101
|
+
// Check if it's a file path
|
|
102
|
+
if (fs.existsSync(source)) {
|
|
103
|
+
content = fs.readFileSync(source, 'utf-8');
|
|
104
|
+
sourceName = path.basename(source);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Treat as direct text content
|
|
108
|
+
content = args.join(' ');
|
|
109
|
+
sourceName = 'text-input';
|
|
110
|
+
}
|
|
111
|
+
const knowledge = {
|
|
112
|
+
id: (0, crypto_1.randomUUID)(),
|
|
113
|
+
type: 'text',
|
|
114
|
+
content,
|
|
115
|
+
metadata: { source: sourceName, addedAt: new Date().toISOString() }
|
|
116
|
+
};
|
|
117
|
+
kb.addKnowledge(knowledge);
|
|
118
|
+
if (outputFormat === 'json') {
|
|
119
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)({
|
|
120
|
+
added: true,
|
|
121
|
+
id: knowledge.id,
|
|
122
|
+
source: sourceName,
|
|
123
|
+
contentLength: content.length
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
await pretty.success(`Knowledge added from: ${sourceName}`);
|
|
128
|
+
await pretty.dim(`Content length: ${content.length} characters`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function searchKnowledge(kb, args, outputFormat) {
|
|
132
|
+
const query = args.join(' ');
|
|
133
|
+
if (!query) {
|
|
134
|
+
if (outputFormat === 'json') {
|
|
135
|
+
(0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide a search query'));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
await pretty.error('Please provide a search query');
|
|
139
|
+
}
|
|
140
|
+
process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
|
|
141
|
+
}
|
|
142
|
+
const results = kb.searchKnowledge(query);
|
|
143
|
+
if (outputFormat === 'json') {
|
|
144
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)({
|
|
145
|
+
query,
|
|
146
|
+
results: results.map(r => ({
|
|
147
|
+
id: r.id,
|
|
148
|
+
content: r.content,
|
|
149
|
+
metadata: r.metadata
|
|
150
|
+
})),
|
|
151
|
+
count: results.length
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
await pretty.heading(`Search Results for: "${query}"`);
|
|
156
|
+
if (results.length === 0) {
|
|
157
|
+
await pretty.info('No matching knowledge found');
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
for (const result of results) {
|
|
161
|
+
const contentStr = typeof result.content === 'string' ? result.content : JSON.stringify(result.content);
|
|
162
|
+
await pretty.plain(` • ${contentStr.substring(0, 100)}${contentStr.length > 100 ? '...' : ''}`);
|
|
163
|
+
if (result.metadata?.source) {
|
|
164
|
+
await pretty.dim(` Source: ${result.metadata.source}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
await pretty.newline();
|
|
169
|
+
await pretty.info(`Found: ${results.length} results`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async function listKnowledge(kb, outputFormat) {
|
|
173
|
+
// Search with empty string to get all
|
|
174
|
+
const entries = kb.searchKnowledge('');
|
|
175
|
+
if (outputFormat === 'json') {
|
|
176
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)({
|
|
177
|
+
entries: entries.map((e) => ({
|
|
178
|
+
id: e.id,
|
|
179
|
+
type: e.type,
|
|
180
|
+
contentPreview: typeof e.content === 'string' ? e.content.substring(0, 100) : JSON.stringify(e.content).substring(0, 100),
|
|
181
|
+
source: e.metadata?.source
|
|
182
|
+
})),
|
|
183
|
+
count: entries.length
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
await pretty.heading('Knowledge Base Entries');
|
|
188
|
+
if (entries.length === 0) {
|
|
189
|
+
await pretty.info('No knowledge entries found');
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
for (const entry of entries) {
|
|
193
|
+
const contentStr = typeof entry.content === 'string' ? entry.content : JSON.stringify(entry.content);
|
|
194
|
+
await pretty.plain(` • ${contentStr.substring(0, 80)}${contentStr.length > 80 ? '...' : ''}`);
|
|
195
|
+
if (entry.metadata?.source) {
|
|
196
|
+
await pretty.dim(` Source: ${entry.metadata.source}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
await pretty.newline();
|
|
201
|
+
await pretty.info(`Total: ${entries.length} entries`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async function showHelp(outputFormat) {
|
|
205
|
+
const help = {
|
|
206
|
+
command: 'knowledge',
|
|
207
|
+
subcommands: [
|
|
208
|
+
{ name: 'add <file|text>', description: 'Add knowledge from file or text' },
|
|
209
|
+
{ name: 'search <query>', description: 'Search knowledge base' },
|
|
210
|
+
{ name: 'list', description: 'List all knowledge entries' },
|
|
211
|
+
{ name: 'clear', description: 'Clear all knowledge' },
|
|
212
|
+
{ name: 'help', description: 'Show this help' }
|
|
213
|
+
]
|
|
214
|
+
};
|
|
215
|
+
if (outputFormat === 'json') {
|
|
216
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)(help));
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
await pretty.heading('Knowledge Command');
|
|
220
|
+
await pretty.plain('Manage knowledge base for RAG\n');
|
|
221
|
+
await pretty.plain('Subcommands:');
|
|
222
|
+
for (const cmd of help.subcommands) {
|
|
223
|
+
await pretty.plain(` ${cmd.name.padEnd(25)} ${cmd.description}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|