praisonai 1.2.1 → 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/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -0
- 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/db/postgres.d.ts +84 -0
- package/dist/db/postgres.js +266 -0
- package/dist/db/redis.d.ts +109 -0
- package/dist/db/redis.js +307 -0
- package/dist/db/sqlite.d.ts +66 -0
- package/dist/db/sqlite.js +339 -0
- package/dist/events/index.d.ts +84 -0
- package/dist/events/index.js +153 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +182 -6
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.js +26 -0
- package/dist/integrations/observability/base.d.ts +123 -0
- package/dist/integrations/observability/base.js +183 -0
- package/dist/integrations/observability/index.d.ts +8 -0
- package/dist/integrations/observability/index.js +29 -0
- package/dist/integrations/observability/langfuse.d.ts +32 -0
- package/dist/integrations/observability/langfuse.js +174 -0
- package/dist/integrations/vector/base.d.ts +110 -0
- package/dist/integrations/vector/base.js +158 -0
- package/dist/integrations/vector/chroma.d.ts +25 -0
- package/dist/integrations/vector/chroma.js +143 -0
- package/dist/integrations/vector/index.d.ts +14 -0
- package/dist/integrations/vector/index.js +37 -0
- package/dist/integrations/vector/pinecone.d.ts +28 -0
- package/dist/integrations/vector/pinecone.js +172 -0
- package/dist/integrations/vector/qdrant.d.ts +25 -0
- package/dist/integrations/vector/qdrant.js +146 -0
- package/dist/integrations/vector/weaviate.d.ts +30 -0
- package/dist/integrations/vector/weaviate.js +206 -0
- package/dist/integrations/voice/base.d.ts +76 -0
- package/dist/integrations/voice/base.js +168 -0
- package/dist/integrations/voice/index.d.ts +6 -0
- package/dist/integrations/voice/index.js +26 -0
- package/dist/knowledge/graph-rag.d.ts +125 -0
- package/dist/knowledge/graph-rag.js +289 -0
- package/dist/knowledge/index.d.ts +2 -0
- package/dist/knowledge/index.js +18 -0
- package/dist/knowledge/reranker.d.ts +86 -0
- package/dist/knowledge/reranker.js +196 -0
- 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/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +1 -1
package/dist/agent/simple.js
CHANGED
|
@@ -10,7 +10,7 @@ class Agent {
|
|
|
10
10
|
this.name = config.name || `Agent_${Math.random().toString(36).substr(2, 9)}`;
|
|
11
11
|
this.verbose = config.verbose ?? process.env.PRAISON_VERBOSE !== 'false';
|
|
12
12
|
this.pretty = config.pretty ?? process.env.PRAISON_PRETTY === 'true';
|
|
13
|
-
this.llm = config.llm || 'gpt-
|
|
13
|
+
this.llm = config.llm || 'gpt-4o-mini';
|
|
14
14
|
this.markdown = config.markdown ?? true;
|
|
15
15
|
this.stream = config.stream ?? true;
|
|
16
16
|
this.tools = config.tools;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache System - In-memory and persistent caching for agents
|
|
3
|
+
* Inspired by mastra's cache module
|
|
4
|
+
*/
|
|
5
|
+
export interface CacheConfig {
|
|
6
|
+
name?: string;
|
|
7
|
+
ttl?: number;
|
|
8
|
+
maxSize?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface CacheEntry<T = any> {
|
|
11
|
+
value: T;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
expiresAt?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Abstract base class for cache implementations
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class BaseCache {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
constructor(config?: CacheConfig);
|
|
21
|
+
abstract get<T = any>(key: string): Promise<T | undefined>;
|
|
22
|
+
abstract set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
23
|
+
abstract delete(key: string): Promise<boolean>;
|
|
24
|
+
abstract clear(): Promise<void>;
|
|
25
|
+
abstract has(key: string): Promise<boolean>;
|
|
26
|
+
abstract keys(): Promise<string[]>;
|
|
27
|
+
abstract size(): Promise<number>;
|
|
28
|
+
abstract listPush<T = any>(key: string, value: T): Promise<void>;
|
|
29
|
+
abstract listLength(key: string): Promise<number>;
|
|
30
|
+
abstract listRange<T = any>(key: string, start: number, end?: number): Promise<T[]>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* In-memory cache implementation
|
|
34
|
+
*/
|
|
35
|
+
export declare class MemoryCache extends BaseCache {
|
|
36
|
+
private cache;
|
|
37
|
+
private lists;
|
|
38
|
+
private ttl?;
|
|
39
|
+
private maxSize?;
|
|
40
|
+
constructor(config?: CacheConfig);
|
|
41
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
42
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
43
|
+
delete(key: string): Promise<boolean>;
|
|
44
|
+
clear(): Promise<void>;
|
|
45
|
+
has(key: string): Promise<boolean>;
|
|
46
|
+
keys(): Promise<string[]>;
|
|
47
|
+
size(): Promise<number>;
|
|
48
|
+
listPush<T = any>(key: string, value: T): Promise<void>;
|
|
49
|
+
listLength(key: string): Promise<number>;
|
|
50
|
+
listRange<T = any>(key: string, start: number, end?: number): Promise<T[]>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* File-based cache implementation
|
|
54
|
+
*/
|
|
55
|
+
export declare class FileCache extends BaseCache {
|
|
56
|
+
private cacheDir;
|
|
57
|
+
private fs;
|
|
58
|
+
private path;
|
|
59
|
+
constructor(config?: CacheConfig & {
|
|
60
|
+
cacheDir?: string;
|
|
61
|
+
});
|
|
62
|
+
private ensureDir;
|
|
63
|
+
private getFilePath;
|
|
64
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
65
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
66
|
+
delete(key: string): Promise<boolean>;
|
|
67
|
+
clear(): Promise<void>;
|
|
68
|
+
has(key: string): Promise<boolean>;
|
|
69
|
+
keys(): Promise<string[]>;
|
|
70
|
+
size(): Promise<number>;
|
|
71
|
+
listPush<T = any>(key: string, value: T): Promise<void>;
|
|
72
|
+
listLength(key: string): Promise<number>;
|
|
73
|
+
listRange<T = any>(key: string, start: number, end?: number): Promise<T[]>;
|
|
74
|
+
}
|
|
75
|
+
export declare function createMemoryCache(config?: CacheConfig): MemoryCache;
|
|
76
|
+
export declare function createFileCache(config?: CacheConfig & {
|
|
77
|
+
cacheDir?: string;
|
|
78
|
+
}): FileCache;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cache System - In-memory and persistent caching for agents
|
|
4
|
+
* Inspired by mastra's cache module
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.FileCache = exports.MemoryCache = exports.BaseCache = void 0;
|
|
41
|
+
exports.createMemoryCache = createMemoryCache;
|
|
42
|
+
exports.createFileCache = createFileCache;
|
|
43
|
+
/**
|
|
44
|
+
* Abstract base class for cache implementations
|
|
45
|
+
*/
|
|
46
|
+
class BaseCache {
|
|
47
|
+
constructor(config = {}) {
|
|
48
|
+
this.name = config.name || 'cache';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.BaseCache = BaseCache;
|
|
52
|
+
/**
|
|
53
|
+
* In-memory cache implementation
|
|
54
|
+
*/
|
|
55
|
+
class MemoryCache extends BaseCache {
|
|
56
|
+
constructor(config = {}) {
|
|
57
|
+
super(config);
|
|
58
|
+
this.cache = new Map();
|
|
59
|
+
this.lists = new Map();
|
|
60
|
+
this.ttl = config.ttl;
|
|
61
|
+
this.maxSize = config.maxSize;
|
|
62
|
+
}
|
|
63
|
+
async get(key) {
|
|
64
|
+
const entry = this.cache.get(key);
|
|
65
|
+
if (!entry)
|
|
66
|
+
return undefined;
|
|
67
|
+
// Check expiration
|
|
68
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
69
|
+
this.cache.delete(key);
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
return entry.value;
|
|
73
|
+
}
|
|
74
|
+
async set(key, value, ttl) {
|
|
75
|
+
// Enforce max size
|
|
76
|
+
if (this.maxSize && this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
77
|
+
// Remove oldest entry
|
|
78
|
+
const firstKey = this.cache.keys().next().value;
|
|
79
|
+
if (firstKey)
|
|
80
|
+
this.cache.delete(firstKey);
|
|
81
|
+
}
|
|
82
|
+
const effectiveTtl = ttl ?? this.ttl;
|
|
83
|
+
const entry = {
|
|
84
|
+
value,
|
|
85
|
+
createdAt: Date.now(),
|
|
86
|
+
expiresAt: effectiveTtl ? Date.now() + effectiveTtl : undefined
|
|
87
|
+
};
|
|
88
|
+
this.cache.set(key, entry);
|
|
89
|
+
}
|
|
90
|
+
async delete(key) {
|
|
91
|
+
const existed = this.cache.has(key);
|
|
92
|
+
this.cache.delete(key);
|
|
93
|
+
this.lists.delete(key);
|
|
94
|
+
return existed;
|
|
95
|
+
}
|
|
96
|
+
async clear() {
|
|
97
|
+
this.cache.clear();
|
|
98
|
+
this.lists.clear();
|
|
99
|
+
}
|
|
100
|
+
async has(key) {
|
|
101
|
+
const entry = this.cache.get(key);
|
|
102
|
+
if (!entry)
|
|
103
|
+
return false;
|
|
104
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
105
|
+
this.cache.delete(key);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
async keys() {
|
|
111
|
+
return Array.from(this.cache.keys());
|
|
112
|
+
}
|
|
113
|
+
async size() {
|
|
114
|
+
return this.cache.size;
|
|
115
|
+
}
|
|
116
|
+
async listPush(key, value) {
|
|
117
|
+
if (!this.lists.has(key)) {
|
|
118
|
+
this.lists.set(key, []);
|
|
119
|
+
}
|
|
120
|
+
this.lists.get(key).push(value);
|
|
121
|
+
}
|
|
122
|
+
async listLength(key) {
|
|
123
|
+
return this.lists.get(key)?.length ?? 0;
|
|
124
|
+
}
|
|
125
|
+
async listRange(key, start, end) {
|
|
126
|
+
const list = this.lists.get(key) ?? [];
|
|
127
|
+
return list.slice(start, end);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.MemoryCache = MemoryCache;
|
|
131
|
+
/**
|
|
132
|
+
* File-based cache implementation
|
|
133
|
+
*/
|
|
134
|
+
class FileCache extends BaseCache {
|
|
135
|
+
constructor(config = {}) {
|
|
136
|
+
super(config);
|
|
137
|
+
this.cacheDir = config.cacheDir || '.cache';
|
|
138
|
+
}
|
|
139
|
+
async ensureDir() {
|
|
140
|
+
if (!this.fs) {
|
|
141
|
+
this.fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
142
|
+
this.path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
await this.fs.mkdir(this.cacheDir, { recursive: true });
|
|
146
|
+
}
|
|
147
|
+
catch { }
|
|
148
|
+
}
|
|
149
|
+
getFilePath(key) {
|
|
150
|
+
const safeKey = key.replace(/[^a-zA-Z0-9-_]/g, '_');
|
|
151
|
+
return this.path.join(this.cacheDir, `${safeKey}.json`);
|
|
152
|
+
}
|
|
153
|
+
async get(key) {
|
|
154
|
+
await this.ensureDir();
|
|
155
|
+
try {
|
|
156
|
+
const data = await this.fs.readFile(this.getFilePath(key), 'utf-8');
|
|
157
|
+
const entry = JSON.parse(data);
|
|
158
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
159
|
+
await this.delete(key);
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
return entry.value;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async set(key, value, ttl) {
|
|
169
|
+
await this.ensureDir();
|
|
170
|
+
const entry = {
|
|
171
|
+
value,
|
|
172
|
+
createdAt: Date.now(),
|
|
173
|
+
expiresAt: ttl ? Date.now() + ttl : undefined
|
|
174
|
+
};
|
|
175
|
+
await this.fs.writeFile(this.getFilePath(key), JSON.stringify(entry));
|
|
176
|
+
}
|
|
177
|
+
async delete(key) {
|
|
178
|
+
await this.ensureDir();
|
|
179
|
+
try {
|
|
180
|
+
await this.fs.unlink(this.getFilePath(key));
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async clear() {
|
|
188
|
+
await this.ensureDir();
|
|
189
|
+
try {
|
|
190
|
+
const files = await this.fs.readdir(this.cacheDir);
|
|
191
|
+
await Promise.all(files.filter((f) => f.endsWith('.json'))
|
|
192
|
+
.map((f) => this.fs.unlink(this.path.join(this.cacheDir, f))));
|
|
193
|
+
}
|
|
194
|
+
catch { }
|
|
195
|
+
}
|
|
196
|
+
async has(key) {
|
|
197
|
+
return (await this.get(key)) !== undefined;
|
|
198
|
+
}
|
|
199
|
+
async keys() {
|
|
200
|
+
await this.ensureDir();
|
|
201
|
+
try {
|
|
202
|
+
const files = await this.fs.readdir(this.cacheDir);
|
|
203
|
+
return files
|
|
204
|
+
.filter((f) => f.endsWith('.json'))
|
|
205
|
+
.map((f) => f.replace('.json', ''));
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async size() {
|
|
212
|
+
return (await this.keys()).length;
|
|
213
|
+
}
|
|
214
|
+
async listPush(key, value) {
|
|
215
|
+
const list = (await this.get(`list_${key}`)) || [];
|
|
216
|
+
list.push(value);
|
|
217
|
+
await this.set(`list_${key}`, list);
|
|
218
|
+
}
|
|
219
|
+
async listLength(key) {
|
|
220
|
+
const list = (await this.get(`list_${key}`)) || [];
|
|
221
|
+
return list.length;
|
|
222
|
+
}
|
|
223
|
+
async listRange(key, start, end) {
|
|
224
|
+
const list = (await this.get(`list_${key}`)) || [];
|
|
225
|
+
return list.slice(start, end);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.FileCache = FileCache;
|
|
229
|
+
// Factory functions
|
|
230
|
+
function createMemoryCache(config) {
|
|
231
|
+
return new MemoryCache(config);
|
|
232
|
+
}
|
|
233
|
+
function createFileCache(config) {
|
|
234
|
+
return new FileCache(config);
|
|
235
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto command - AutoAgents for automatic agent generation
|
|
3
|
+
*/
|
|
4
|
+
export interface AutoOptions {
|
|
5
|
+
model?: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
output?: 'json' | 'text' | 'pretty';
|
|
8
|
+
json?: boolean;
|
|
9
|
+
pattern?: string;
|
|
10
|
+
agents?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function execute(args: string[], options: AutoOptions): Promise<void>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auto command - AutoAgents for automatic agent generation
|
|
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 auto_1 = require("../../auto");
|
|
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 topic = args.join(' ');
|
|
48
|
+
const outputFormat = options.json ? 'json' : (options.output || 'pretty');
|
|
49
|
+
const config = (0, resolve_1.resolveConfig)(options);
|
|
50
|
+
if (!topic) {
|
|
51
|
+
if (outputFormat === 'json') {
|
|
52
|
+
(0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide a topic for auto-generation'));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await pretty.error('Please provide a topic for auto-generation');
|
|
56
|
+
await pretty.dim('Usage: praisonai-ts auto "Create a research team"');
|
|
57
|
+
}
|
|
58
|
+
process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
|
|
59
|
+
}
|
|
60
|
+
const startTime = Date.now();
|
|
61
|
+
try {
|
|
62
|
+
if (outputFormat !== 'json') {
|
|
63
|
+
await pretty.info(`Generating agents for: "${topic}"`);
|
|
64
|
+
}
|
|
65
|
+
const autoAgents = (0, auto_1.createAutoAgents)({
|
|
66
|
+
llm: config.model,
|
|
67
|
+
pattern: options.pattern,
|
|
68
|
+
verbose: options.verbose
|
|
69
|
+
});
|
|
70
|
+
const result = await autoAgents.generate(topic);
|
|
71
|
+
const duration = Date.now() - startTime;
|
|
72
|
+
if (outputFormat === 'json') {
|
|
73
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)({
|
|
74
|
+
topic,
|
|
75
|
+
agents: result.agents,
|
|
76
|
+
tasks: result.tasks,
|
|
77
|
+
pattern: result.pattern
|
|
78
|
+
}, {
|
|
79
|
+
duration_ms: duration,
|
|
80
|
+
model: config.model
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
await pretty.heading('Generated Team');
|
|
85
|
+
await pretty.plain(`Pattern: ${result.pattern}`);
|
|
86
|
+
await pretty.newline();
|
|
87
|
+
await pretty.plain('Agents:');
|
|
88
|
+
for (const agent of result.agents) {
|
|
89
|
+
await pretty.plain(` • ${agent.name}: ${agent.role}`);
|
|
90
|
+
}
|
|
91
|
+
await pretty.newline();
|
|
92
|
+
await pretty.plain('Tasks:');
|
|
93
|
+
for (const task of result.tasks) {
|
|
94
|
+
await pretty.plain(` • ${task.description?.substring(0, 60)}...`);
|
|
95
|
+
}
|
|
96
|
+
await pretty.newline();
|
|
97
|
+
await pretty.success(`Generated in ${duration}ms`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (outputFormat === 'json') {
|
|
102
|
+
(0, json_1.outputJson)((0, json_1.formatError)(errors_1.ERROR_CODES.UNKNOWN, error instanceof Error ? error.message : String(error)));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await pretty.error(error instanceof Error ? error.message : String(error));
|
|
106
|
+
}
|
|
107
|
+
process.exit(cli_spec_1.EXIT_CODES.RUNTIME_ERROR);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI command: autonomy
|
|
4
|
+
* Autonomy mode management for agent actions
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.execute = execute;
|
|
8
|
+
const autonomy_mode_1 = require("../features/autonomy-mode");
|
|
9
|
+
let manager = null;
|
|
10
|
+
function getManager() {
|
|
11
|
+
if (!manager) {
|
|
12
|
+
manager = (0, autonomy_mode_1.createAutonomyManager)();
|
|
13
|
+
}
|
|
14
|
+
return manager;
|
|
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 'status':
|
|
21
|
+
await handleStatus(isJson);
|
|
22
|
+
break;
|
|
23
|
+
case 'set':
|
|
24
|
+
await handleSet(args.slice(1), isJson);
|
|
25
|
+
break;
|
|
26
|
+
case 'policies':
|
|
27
|
+
await handlePolicies(args.slice(1), isJson);
|
|
28
|
+
break;
|
|
29
|
+
case 'reset':
|
|
30
|
+
await handleReset(isJson);
|
|
31
|
+
break;
|
|
32
|
+
case 'help':
|
|
33
|
+
default:
|
|
34
|
+
showHelp(isJson);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function handleStatus(isJson) {
|
|
38
|
+
const mgr = getManager();
|
|
39
|
+
const summary = mgr.getSummary();
|
|
40
|
+
const mode = mgr.getMode();
|
|
41
|
+
const actionCount = mgr.getActionCount();
|
|
42
|
+
if (isJson) {
|
|
43
|
+
console.log(JSON.stringify({
|
|
44
|
+
success: true,
|
|
45
|
+
mode,
|
|
46
|
+
actionCount,
|
|
47
|
+
policies: autonomy_mode_1.MODE_POLICIES[mode]
|
|
48
|
+
}, null, 2));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log(summary);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function handleSet(args, isJson) {
|
|
55
|
+
const mode = args[0];
|
|
56
|
+
if (!mode || !['suggest', 'auto_edit', 'full_auto'].includes(mode)) {
|
|
57
|
+
console.error('Error: Valid mode required (suggest, auto_edit, full_auto)');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const mgr = getManager();
|
|
61
|
+
mgr.setMode(mode);
|
|
62
|
+
if (isJson) {
|
|
63
|
+
console.log(JSON.stringify({ success: true, mode }));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.log(`✓ Autonomy mode set to: ${mode}`);
|
|
67
|
+
console.log('\nPolicies for this mode:');
|
|
68
|
+
for (const policy of autonomy_mode_1.MODE_POLICIES[mode]) {
|
|
69
|
+
const status = policy.requiresApproval ? '⚠️ requires approval' : '✓ auto-approved';
|
|
70
|
+
console.log(` ${policy.action}: ${status}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function handlePolicies(args, isJson) {
|
|
75
|
+
const mode = args[0] || 'suggest';
|
|
76
|
+
if (!['suggest', 'auto_edit', 'full_auto'].includes(mode)) {
|
|
77
|
+
console.error('Error: Valid mode required (suggest, auto_edit, full_auto)');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
const policies = autonomy_mode_1.MODE_POLICIES[mode];
|
|
81
|
+
if (isJson) {
|
|
82
|
+
console.log(JSON.stringify({ success: true, mode, policies }, null, 2));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.log(`Policies for mode: ${mode}\n`);
|
|
86
|
+
for (const policy of policies) {
|
|
87
|
+
const status = policy.requiresApproval ? '⚠️ requires approval' : '✓ auto-approved';
|
|
88
|
+
console.log(` ${policy.action.padEnd(20)} ${status}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function handleReset(isJson) {
|
|
93
|
+
const mgr = getManager();
|
|
94
|
+
mgr.clearRemembered();
|
|
95
|
+
mgr.resetActionCount();
|
|
96
|
+
mgr.setMode('suggest');
|
|
97
|
+
if (isJson) {
|
|
98
|
+
console.log(JSON.stringify({ success: true, message: 'Autonomy state reset' }));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.log('✓ Autonomy state reset');
|
|
102
|
+
console.log(' Mode: suggest');
|
|
103
|
+
console.log(' Remembered decisions: cleared');
|
|
104
|
+
console.log(' Action count: 0');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function showHelp(isJson) {
|
|
108
|
+
const help = {
|
|
109
|
+
command: 'autonomy',
|
|
110
|
+
description: 'Autonomy mode management for agent actions',
|
|
111
|
+
subcommands: {
|
|
112
|
+
status: 'Show current autonomy status',
|
|
113
|
+
set: 'Set autonomy mode',
|
|
114
|
+
policies: 'Show policies for a mode',
|
|
115
|
+
reset: 'Reset autonomy state'
|
|
116
|
+
},
|
|
117
|
+
modes: {
|
|
118
|
+
suggest: 'Requires approval for most actions (default)',
|
|
119
|
+
auto_edit: 'Auto-approves file edits, requires approval for others',
|
|
120
|
+
full_auto: 'Auto-approves most actions (use with caution)'
|
|
121
|
+
},
|
|
122
|
+
flags: {
|
|
123
|
+
'--json': 'Output in JSON format'
|
|
124
|
+
},
|
|
125
|
+
examples: [
|
|
126
|
+
'praisonai-ts autonomy status',
|
|
127
|
+
'praisonai-ts autonomy set suggest',
|
|
128
|
+
'praisonai-ts autonomy set auto_edit',
|
|
129
|
+
'praisonai-ts autonomy set full_auto',
|
|
130
|
+
'praisonai-ts autonomy policies suggest',
|
|
131
|
+
'praisonai-ts autonomy reset'
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
if (isJson) {
|
|
135
|
+
console.log(JSON.stringify(help, null, 2));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.log('Autonomy - Agent action approval management\n');
|
|
139
|
+
console.log('Subcommands:');
|
|
140
|
+
for (const [cmd, desc] of Object.entries(help.subcommands)) {
|
|
141
|
+
console.log(` ${cmd.padEnd(12)} ${desc}`);
|
|
142
|
+
}
|
|
143
|
+
console.log('\nModes:');
|
|
144
|
+
for (const [mode, desc] of Object.entries(help.modes)) {
|
|
145
|
+
console.log(` ${mode.padEnd(12)} ${desc}`);
|
|
146
|
+
}
|
|
147
|
+
console.log('\nExamples:');
|
|
148
|
+
for (const ex of help.examples) {
|
|
149
|
+
console.log(` ${ex}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|