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,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Run command - Run an agent with a task
|
|
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 agent_1 = require("../../agent");
|
|
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 task = args[0];
|
|
48
|
+
if (!task) {
|
|
49
|
+
if (options.json || options.output === 'json') {
|
|
50
|
+
(0, json_1.printError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide a task');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await pretty.error('Please provide a task');
|
|
54
|
+
}
|
|
55
|
+
process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
|
|
56
|
+
}
|
|
57
|
+
// Resolve config with precedence
|
|
58
|
+
const config = (0, resolve_1.resolveConfig)({
|
|
59
|
+
configPath: options.config,
|
|
60
|
+
profile: options.profile,
|
|
61
|
+
model: options.model,
|
|
62
|
+
verbose: options.verbose
|
|
63
|
+
});
|
|
64
|
+
const startTime = Date.now();
|
|
65
|
+
const outputFormat = options.json ? 'json' : (options.output || 'pretty');
|
|
66
|
+
try {
|
|
67
|
+
// Parse tools if provided
|
|
68
|
+
const tools = options.tools ? options.tools.split(',').map(t => t.trim()) : [];
|
|
69
|
+
// Create agent
|
|
70
|
+
const agent = new agent_1.Agent({
|
|
71
|
+
name: 'CLI Agent',
|
|
72
|
+
instructions: 'You are a helpful AI assistant.',
|
|
73
|
+
llm: config.model,
|
|
74
|
+
verbose: config.verbose
|
|
75
|
+
});
|
|
76
|
+
// Execute task
|
|
77
|
+
const result = await agent.start(task);
|
|
78
|
+
const duration = Date.now() - startTime;
|
|
79
|
+
if (outputFormat === 'json') {
|
|
80
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)({
|
|
81
|
+
result: result,
|
|
82
|
+
agent: 'CLI Agent',
|
|
83
|
+
task: task
|
|
84
|
+
}, {
|
|
85
|
+
duration_ms: duration,
|
|
86
|
+
model: config.model
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
if (typeof result === 'string') {
|
|
91
|
+
console.log(result);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.log(JSON.stringify(result, null, 2));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const cliError = (0, errors_1.normalizeError)(error);
|
|
100
|
+
if (outputFormat === 'json') {
|
|
101
|
+
(0, json_1.outputJson)((0, json_1.formatError)(cliError.code, cliError.message, cliError.details));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await pretty.error(cliError.message);
|
|
105
|
+
if (config.verbose && error instanceof Error && error.stack) {
|
|
106
|
+
await pretty.dim(error.stack);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
process.exit(cliError.exitCode);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI command: sandbox
|
|
4
|
+
* Safe command execution with restrictions
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.execute = execute;
|
|
8
|
+
const sandbox_executor_1 = require("../features/sandbox-executor");
|
|
9
|
+
async function execute(args, options) {
|
|
10
|
+
const subcommand = args[0] || 'help';
|
|
11
|
+
const isJson = Boolean(options.output === 'json' || options.json);
|
|
12
|
+
switch (subcommand) {
|
|
13
|
+
case 'exec':
|
|
14
|
+
await handleExec(args.slice(1), options, isJson);
|
|
15
|
+
break;
|
|
16
|
+
case 'check':
|
|
17
|
+
await handleCheck(args.slice(1), isJson);
|
|
18
|
+
break;
|
|
19
|
+
case 'mode':
|
|
20
|
+
await handleMode(args.slice(1), isJson);
|
|
21
|
+
break;
|
|
22
|
+
case 'help':
|
|
23
|
+
default:
|
|
24
|
+
showHelp(isJson);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function handleExec(args, options, isJson) {
|
|
28
|
+
const command = args.join(' ');
|
|
29
|
+
if (!command) {
|
|
30
|
+
console.error('Error: Command is required');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const mode = options.mode || 'basic';
|
|
34
|
+
const timeout = options.timeout || 30000;
|
|
35
|
+
const executor = (0, sandbox_executor_1.createSandboxExecutor)({ mode, timeout });
|
|
36
|
+
const result = await executor.execute(command);
|
|
37
|
+
if (isJson) {
|
|
38
|
+
console.log(JSON.stringify(result, null, 2));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (result.success) {
|
|
42
|
+
console.log('✓ Command executed successfully');
|
|
43
|
+
console.log(`Duration: ${result.duration}ms`);
|
|
44
|
+
if (result.stdout) {
|
|
45
|
+
console.log('\nOutput:');
|
|
46
|
+
console.log(result.stdout);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.error('✗ Command failed');
|
|
51
|
+
if (result.stderr)
|
|
52
|
+
console.error(result.stderr);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!result.success)
|
|
56
|
+
process.exit(result.exitCode || 1);
|
|
57
|
+
}
|
|
58
|
+
async function handleCheck(args, isJson) {
|
|
59
|
+
const command = args.join(' ');
|
|
60
|
+
if (!command) {
|
|
61
|
+
console.error('Error: Command is required');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const validator = new sandbox_executor_1.CommandValidator();
|
|
65
|
+
const result = validator.validate(command);
|
|
66
|
+
if (isJson) {
|
|
67
|
+
console.log(JSON.stringify({ command, ...result }, null, 2));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (result.valid) {
|
|
71
|
+
console.log(`✓ Command is allowed: ${command}`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(`✗ Command blocked: ${command}`);
|
|
75
|
+
console.log(` Reason: ${result.reason}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function handleMode(args, isJson) {
|
|
80
|
+
const modes = {
|
|
81
|
+
disabled: 'No execution allowed',
|
|
82
|
+
basic: 'Basic validation, blocks dangerous patterns',
|
|
83
|
+
strict: 'Minimal environment, restricted PATH',
|
|
84
|
+
'network-isolated': 'No network access (proxy blocked)'
|
|
85
|
+
};
|
|
86
|
+
if (isJson) {
|
|
87
|
+
console.log(JSON.stringify({ success: true, modes }, null, 2));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log('Sandbox Modes:\n');
|
|
91
|
+
for (const [mode, desc] of Object.entries(modes)) {
|
|
92
|
+
console.log(` ${mode.padEnd(18)} ${desc}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function showHelp(isJson) {
|
|
97
|
+
const help = {
|
|
98
|
+
command: 'sandbox',
|
|
99
|
+
description: 'Safe command execution with restrictions',
|
|
100
|
+
subcommands: {
|
|
101
|
+
exec: 'Execute a command in sandbox',
|
|
102
|
+
check: 'Check if a command would be allowed',
|
|
103
|
+
mode: 'List available sandbox modes'
|
|
104
|
+
},
|
|
105
|
+
flags: {
|
|
106
|
+
'--mode': 'Sandbox mode (disabled, basic, strict, network-isolated)',
|
|
107
|
+
'--timeout': 'Execution timeout in ms (default: 30000)',
|
|
108
|
+
'--json': 'Output in JSON format'
|
|
109
|
+
},
|
|
110
|
+
examples: [
|
|
111
|
+
'praisonai-ts sandbox exec "ls -la"',
|
|
112
|
+
'praisonai-ts sandbox exec "npm install" --mode strict',
|
|
113
|
+
'praisonai-ts sandbox check "rm -rf /"',
|
|
114
|
+
'praisonai-ts sandbox mode'
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
if (isJson) {
|
|
118
|
+
console.log(JSON.stringify(help, null, 2));
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log('Sandbox - Safe command execution\n');
|
|
122
|
+
console.log('Subcommands:');
|
|
123
|
+
for (const [cmd, desc] of Object.entries(help.subcommands)) {
|
|
124
|
+
console.log(` ${cmd.padEnd(12)} ${desc}`);
|
|
125
|
+
}
|
|
126
|
+
console.log('\nFlags:');
|
|
127
|
+
for (const [flag, desc] of Object.entries(help.flags)) {
|
|
128
|
+
console.log(` ${flag.padEnd(12)} ${desc}`);
|
|
129
|
+
}
|
|
130
|
+
console.log('\nExamples:');
|
|
131
|
+
for (const ex of help.examples) {
|
|
132
|
+
console.log(` ${ex}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI command: scheduler
|
|
4
|
+
* Agent task scheduling with cron-like patterns
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.execute = execute;
|
|
8
|
+
const scheduler_1 = require("../features/scheduler");
|
|
9
|
+
async function execute(args, options) {
|
|
10
|
+
const subcommand = args[0] || 'help';
|
|
11
|
+
const isJson = Boolean(options.output === 'json' || options.json);
|
|
12
|
+
switch (subcommand) {
|
|
13
|
+
case 'create':
|
|
14
|
+
await handleCreate(args.slice(1), options, isJson);
|
|
15
|
+
break;
|
|
16
|
+
case 'list':
|
|
17
|
+
await handleList(options, isJson);
|
|
18
|
+
break;
|
|
19
|
+
case 'run':
|
|
20
|
+
await handleRun(args.slice(1), options, isJson);
|
|
21
|
+
break;
|
|
22
|
+
case 'remove':
|
|
23
|
+
await handleRemove(args.slice(1), options, isJson);
|
|
24
|
+
break;
|
|
25
|
+
case 'enable':
|
|
26
|
+
await handleEnable(args.slice(1), options, isJson);
|
|
27
|
+
break;
|
|
28
|
+
case 'disable':
|
|
29
|
+
await handleDisable(args.slice(1), options, isJson);
|
|
30
|
+
break;
|
|
31
|
+
case 'patterns':
|
|
32
|
+
await handlePatterns(isJson);
|
|
33
|
+
break;
|
|
34
|
+
case 'help':
|
|
35
|
+
default:
|
|
36
|
+
showHelp(isJson);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function handleCreate(args, options, isJson) {
|
|
40
|
+
const name = args[0];
|
|
41
|
+
const cron = options.cron;
|
|
42
|
+
const interval = options.interval;
|
|
43
|
+
if (!name) {
|
|
44
|
+
const error = { error: 'Task name is required' };
|
|
45
|
+
if (isJson) {
|
|
46
|
+
console.log(JSON.stringify(error));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.error('Error: Task name is required');
|
|
50
|
+
console.log('Usage: praisonai-ts scheduler create <name> --cron "* * * * *"');
|
|
51
|
+
}
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
if (!cron && !interval) {
|
|
55
|
+
const error = { error: 'Either --cron or --interval is required' };
|
|
56
|
+
if (isJson) {
|
|
57
|
+
console.log(JSON.stringify(error));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.error('Error: Either --cron or --interval is required');
|
|
61
|
+
}
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const scheduler = (0, scheduler_1.createScheduler)();
|
|
65
|
+
const id = scheduler.add({
|
|
66
|
+
name,
|
|
67
|
+
cron,
|
|
68
|
+
interval: interval ? interval * 1000 : undefined,
|
|
69
|
+
task: async () => {
|
|
70
|
+
console.log(`Task ${name} executed at ${new Date().toISOString()}`);
|
|
71
|
+
return { executed: true };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const result = {
|
|
75
|
+
success: true,
|
|
76
|
+
id,
|
|
77
|
+
name,
|
|
78
|
+
cron,
|
|
79
|
+
interval,
|
|
80
|
+
message: `Task '${name}' created with ID: ${id}`
|
|
81
|
+
};
|
|
82
|
+
if (isJson) {
|
|
83
|
+
console.log(JSON.stringify(result, null, 2));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log(`✓ Task '${name}' created`);
|
|
87
|
+
console.log(` ID: ${id}`);
|
|
88
|
+
if (cron)
|
|
89
|
+
console.log(` Cron: ${cron}`);
|
|
90
|
+
if (interval)
|
|
91
|
+
console.log(` Interval: ${interval}s`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function handleList(options, isJson) {
|
|
95
|
+
const scheduler = (0, scheduler_1.createScheduler)();
|
|
96
|
+
const tasks = scheduler.getAllTasks();
|
|
97
|
+
if (isJson) {
|
|
98
|
+
console.log(JSON.stringify({ success: true, tasks }, null, 2));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (tasks.length === 0) {
|
|
102
|
+
console.log('No scheduled tasks');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.log('Scheduled Tasks:');
|
|
106
|
+
for (const task of tasks) {
|
|
107
|
+
console.log(` ${task.name} (${task.id})`);
|
|
108
|
+
console.log(` Status: ${task.status}`);
|
|
109
|
+
console.log(` Enabled: ${task.enabled}`);
|
|
110
|
+
console.log(` Run count: ${task.runCount}`);
|
|
111
|
+
if (task.nextRun)
|
|
112
|
+
console.log(` Next run: ${task.nextRun.toISOString()}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function handleRun(args, options, isJson) {
|
|
118
|
+
const id = args[0];
|
|
119
|
+
if (!id) {
|
|
120
|
+
console.error('Error: Task ID is required');
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const scheduler = (0, scheduler_1.createScheduler)();
|
|
124
|
+
try {
|
|
125
|
+
const result = await scheduler.runNow(id);
|
|
126
|
+
if (isJson) {
|
|
127
|
+
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
console.log(`✓ Task ${id} executed successfully`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (isJson) {
|
|
135
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.error(`Error: ${error.message}`);
|
|
139
|
+
}
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function handleRemove(args, options, isJson) {
|
|
144
|
+
const id = args[0];
|
|
145
|
+
if (!id) {
|
|
146
|
+
console.error('Error: Task ID is required');
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
const scheduler = (0, scheduler_1.createScheduler)();
|
|
150
|
+
const removed = scheduler.remove(id);
|
|
151
|
+
if (isJson) {
|
|
152
|
+
console.log(JSON.stringify({ success: removed, id }));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (removed) {
|
|
156
|
+
console.log(`✓ Task ${id} removed`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.error(`Task ${id} not found`);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function handleEnable(args, options, isJson) {
|
|
165
|
+
const id = args[0];
|
|
166
|
+
if (!id) {
|
|
167
|
+
console.error('Error: Task ID is required');
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
const scheduler = (0, scheduler_1.createScheduler)();
|
|
171
|
+
const enabled = scheduler.enable(id);
|
|
172
|
+
if (isJson) {
|
|
173
|
+
console.log(JSON.stringify({ success: enabled, id }));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
console.log(enabled ? `✓ Task ${id} enabled` : `Task ${id} not found`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function handleDisable(args, options, isJson) {
|
|
180
|
+
const id = args[0];
|
|
181
|
+
if (!id) {
|
|
182
|
+
console.error('Error: Task ID is required');
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
const scheduler = (0, scheduler_1.createScheduler)();
|
|
186
|
+
const disabled = scheduler.disable(id);
|
|
187
|
+
if (isJson) {
|
|
188
|
+
console.log(JSON.stringify({ success: disabled, id }));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
console.log(disabled ? `✓ Task ${id} disabled` : `Task ${id} not found`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async function handlePatterns(isJson) {
|
|
195
|
+
const patterns = {
|
|
196
|
+
everyMinute: scheduler_1.cronExpressions.everyMinute,
|
|
197
|
+
every5Minutes: scheduler_1.cronExpressions.every5Minutes,
|
|
198
|
+
every15Minutes: scheduler_1.cronExpressions.every15Minutes,
|
|
199
|
+
everyHour: scheduler_1.cronExpressions.everyHour,
|
|
200
|
+
everyDay: scheduler_1.cronExpressions.everyDay,
|
|
201
|
+
everyWeek: scheduler_1.cronExpressions.everyWeek,
|
|
202
|
+
everyMonth: scheduler_1.cronExpressions.everyMonth,
|
|
203
|
+
weekdays: scheduler_1.cronExpressions.weekdays,
|
|
204
|
+
weekends: scheduler_1.cronExpressions.weekends
|
|
205
|
+
};
|
|
206
|
+
if (isJson) {
|
|
207
|
+
console.log(JSON.stringify({ success: true, patterns }, null, 2));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.log('Common Cron Patterns:');
|
|
211
|
+
for (const [name, pattern] of Object.entries(patterns)) {
|
|
212
|
+
console.log(` ${name}: ${pattern}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function showHelp(isJson) {
|
|
217
|
+
const help = {
|
|
218
|
+
command: 'scheduler',
|
|
219
|
+
description: 'Agent task scheduling with cron-like patterns',
|
|
220
|
+
subcommands: {
|
|
221
|
+
create: 'Create a scheduled task',
|
|
222
|
+
list: 'List all scheduled tasks',
|
|
223
|
+
run: 'Run a task immediately',
|
|
224
|
+
remove: 'Remove a scheduled task',
|
|
225
|
+
enable: 'Enable a task',
|
|
226
|
+
disable: 'Disable a task',
|
|
227
|
+
patterns: 'Show common cron patterns'
|
|
228
|
+
},
|
|
229
|
+
flags: {
|
|
230
|
+
'--cron': 'Cron expression (e.g., "*/5 * * * *")',
|
|
231
|
+
'--interval': 'Interval in seconds',
|
|
232
|
+
'--json': 'Output in JSON format'
|
|
233
|
+
},
|
|
234
|
+
examples: [
|
|
235
|
+
'praisonai-ts scheduler create my-task --cron "*/5 * * * *"',
|
|
236
|
+
'praisonai-ts scheduler create backup --interval 3600',
|
|
237
|
+
'praisonai-ts scheduler list',
|
|
238
|
+
'praisonai-ts scheduler run <task-id>',
|
|
239
|
+
'praisonai-ts scheduler patterns'
|
|
240
|
+
]
|
|
241
|
+
};
|
|
242
|
+
if (isJson) {
|
|
243
|
+
console.log(JSON.stringify(help, null, 2));
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
console.log('Scheduler - Agent task scheduling\n');
|
|
247
|
+
console.log('Subcommands:');
|
|
248
|
+
for (const [cmd, desc] of Object.entries(help.subcommands)) {
|
|
249
|
+
console.log(` ${cmd.padEnd(12)} ${desc}`);
|
|
250
|
+
}
|
|
251
|
+
console.log('\nFlags:');
|
|
252
|
+
for (const [flag, desc] of Object.entries(help.flags)) {
|
|
253
|
+
console.log(` ${flag.padEnd(12)} ${desc}`);
|
|
254
|
+
}
|
|
255
|
+
console.log('\nExamples:');
|
|
256
|
+
for (const ex of help.examples) {
|
|
257
|
+
console.log(` ${ex}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|