praisonai 1.0.19 → 1.2.0
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/context.d.ts +68 -0
- package/dist/agent/context.js +119 -0
- package/dist/agent/enhanced.d.ts +92 -0
- package/dist/agent/enhanced.js +267 -0
- package/dist/agent/handoff.d.ts +82 -0
- package/dist/agent/handoff.js +124 -0
- package/dist/agent/image.d.ts +51 -0
- package/dist/agent/image.js +93 -0
- package/dist/agent/prompt-expander.d.ts +40 -0
- package/dist/agent/prompt-expander.js +84 -0
- package/dist/agent/query-rewriter.d.ts +38 -0
- package/dist/agent/query-rewriter.js +79 -0
- package/dist/agent/research.d.ts +52 -0
- package/dist/agent/research.js +118 -0
- package/dist/agent/router.d.ts +77 -0
- package/dist/agent/router.js +113 -0
- package/dist/agent/simple.js +1 -1
- package/dist/agent/types.js +2 -2
- package/dist/auto/index.d.ts +56 -0
- package/dist/auto/index.js +142 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +150 -0
- package/dist/db/index.d.ts +23 -0
- package/dist/db/index.js +72 -0
- package/dist/db/memory-adapter.d.ts +42 -0
- package/dist/db/memory-adapter.js +146 -0
- package/dist/db/types.d.ts +113 -0
- package/dist/db/types.js +5 -0
- package/dist/eval/index.d.ts +61 -0
- package/dist/eval/index.js +157 -0
- package/dist/guardrails/index.d.ts +82 -0
- package/dist/guardrails/index.js +202 -0
- package/dist/guardrails/llm-guardrail.d.ts +40 -0
- package/dist/guardrails/llm-guardrail.js +91 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +122 -1
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +157 -0
- package/dist/knowledge/rag.d.ts +80 -0
- package/dist/knowledge/rag.js +147 -0
- package/dist/llm/openai.js +1 -1
- package/dist/llm/providers/anthropic.d.ts +33 -0
- package/dist/llm/providers/anthropic.js +291 -0
- package/dist/llm/providers/base.d.ts +25 -0
- package/dist/llm/providers/base.js +43 -0
- package/dist/llm/providers/google.d.ts +27 -0
- package/dist/llm/providers/google.js +275 -0
- package/dist/llm/providers/index.d.ts +43 -0
- package/dist/llm/providers/index.js +116 -0
- package/dist/llm/providers/openai.d.ts +18 -0
- package/dist/llm/providers/openai.js +203 -0
- package/dist/llm/providers/types.d.ts +94 -0
- package/dist/llm/providers/types.js +5 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +169 -0
- package/dist/observability/index.d.ts +86 -0
- package/dist/observability/index.js +166 -0
- package/dist/planning/index.d.ts +133 -0
- package/dist/planning/index.js +228 -0
- package/dist/session/index.d.ts +111 -0
- package/dist/session/index.js +250 -0
- package/dist/skills/index.d.ts +70 -0
- package/dist/skills/index.js +233 -0
- package/dist/telemetry/index.d.ts +102 -0
- package/dist/telemetry/index.js +187 -0
- package/dist/tools/decorator.d.ts +91 -0
- package/dist/tools/decorator.js +165 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/mcpSse.d.ts +41 -0
- package/dist/tools/mcpSse.js +108 -0
- package/dist/workflows/index.d.ts +97 -0
- package/dist/workflows/index.js +216 -0
- package/package.json +5 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Router Agent - Route requests to specialized agents
|
|
3
|
+
*/
|
|
4
|
+
import type { EnhancedAgent } from './enhanced';
|
|
5
|
+
export interface RouteConfig {
|
|
6
|
+
agent: EnhancedAgent;
|
|
7
|
+
condition: (input: string, context?: RouteContext) => boolean | Promise<boolean>;
|
|
8
|
+
priority?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RouteContext {
|
|
11
|
+
history?: string[];
|
|
12
|
+
metadata?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
export interface RouterConfig {
|
|
15
|
+
name?: string;
|
|
16
|
+
routes: RouteConfig[];
|
|
17
|
+
defaultAgent?: EnhancedAgent;
|
|
18
|
+
verbose?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Router Agent - Routes requests to the most appropriate agent
|
|
22
|
+
*/
|
|
23
|
+
export declare class RouterAgent {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
private routes;
|
|
26
|
+
private defaultAgent?;
|
|
27
|
+
private verbose;
|
|
28
|
+
constructor(config: RouterConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Route a request to the appropriate agent
|
|
31
|
+
*/
|
|
32
|
+
route(input: string, context?: RouteContext): Promise<{
|
|
33
|
+
agent: EnhancedAgent;
|
|
34
|
+
response: string;
|
|
35
|
+
} | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Add a route
|
|
38
|
+
*/
|
|
39
|
+
addRoute(config: RouteConfig): this;
|
|
40
|
+
/**
|
|
41
|
+
* Get all routes
|
|
42
|
+
*/
|
|
43
|
+
getRoutes(): RouteConfig[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Route condition helpers
|
|
47
|
+
*/
|
|
48
|
+
export declare const routeConditions: {
|
|
49
|
+
/**
|
|
50
|
+
* Match by keywords
|
|
51
|
+
*/
|
|
52
|
+
keywords: (keywords: string | string[]) => (input: string) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Match by regex
|
|
55
|
+
*/
|
|
56
|
+
pattern: (regex: RegExp) => (input: string) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Match by metadata
|
|
59
|
+
*/
|
|
60
|
+
metadata: (key: string, value: any) => (_input: string, context?: RouteContext) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Always match (for default routes)
|
|
63
|
+
*/
|
|
64
|
+
always: () => () => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Combine conditions with AND
|
|
67
|
+
*/
|
|
68
|
+
and: (...conditions: Array<(input: string, context?: RouteContext) => boolean>) => (input: string, context?: RouteContext) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Combine conditions with OR
|
|
71
|
+
*/
|
|
72
|
+
or: (...conditions: Array<(input: string, context?: RouteContext) => boolean>) => (input: string, context?: RouteContext) => boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Create a router agent
|
|
76
|
+
*/
|
|
77
|
+
export declare function createRouter(config: RouterConfig): RouterAgent;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Router Agent - Route requests to specialized agents
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.routeConditions = exports.RouterAgent = void 0;
|
|
7
|
+
exports.createRouter = createRouter;
|
|
8
|
+
/**
|
|
9
|
+
* Router Agent - Routes requests to the most appropriate agent
|
|
10
|
+
*/
|
|
11
|
+
class RouterAgent {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.name = config.name || 'Router';
|
|
14
|
+
this.routes = config.routes.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
15
|
+
this.defaultAgent = config.defaultAgent;
|
|
16
|
+
this.verbose = config.verbose ?? false;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Route a request to the appropriate agent
|
|
20
|
+
*/
|
|
21
|
+
async route(input, context) {
|
|
22
|
+
for (const route of this.routes) {
|
|
23
|
+
const matches = await route.condition(input, context);
|
|
24
|
+
if (matches) {
|
|
25
|
+
if (this.verbose) {
|
|
26
|
+
console.log(`[Router] Routing to: ${route.agent.name}`);
|
|
27
|
+
}
|
|
28
|
+
const response = await route.agent.chat(input);
|
|
29
|
+
return { agent: route.agent, response: response.text };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (this.defaultAgent) {
|
|
33
|
+
if (this.verbose) {
|
|
34
|
+
console.log(`[Router] Using default agent: ${this.defaultAgent.name}`);
|
|
35
|
+
}
|
|
36
|
+
const response = await this.defaultAgent.chat(input);
|
|
37
|
+
return { agent: this.defaultAgent, response: response.text };
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Add a route
|
|
43
|
+
*/
|
|
44
|
+
addRoute(config) {
|
|
45
|
+
this.routes.push(config);
|
|
46
|
+
this.routes.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get all routes
|
|
51
|
+
*/
|
|
52
|
+
getRoutes() {
|
|
53
|
+
return [...this.routes];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.RouterAgent = RouterAgent;
|
|
57
|
+
/**
|
|
58
|
+
* Route condition helpers
|
|
59
|
+
*/
|
|
60
|
+
exports.routeConditions = {
|
|
61
|
+
/**
|
|
62
|
+
* Match by keywords
|
|
63
|
+
*/
|
|
64
|
+
keywords: (keywords) => {
|
|
65
|
+
const keywordList = Array.isArray(keywords) ? keywords : [keywords];
|
|
66
|
+
return (input) => {
|
|
67
|
+
const lower = input.toLowerCase();
|
|
68
|
+
return keywordList.some(kw => lower.includes(kw.toLowerCase()));
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Match by regex
|
|
73
|
+
*/
|
|
74
|
+
pattern: (regex) => {
|
|
75
|
+
return (input) => regex.test(input);
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Match by metadata
|
|
79
|
+
*/
|
|
80
|
+
metadata: (key, value) => {
|
|
81
|
+
return (_input, context) => {
|
|
82
|
+
return context?.metadata?.[key] === value;
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Always match (for default routes)
|
|
87
|
+
*/
|
|
88
|
+
always: () => {
|
|
89
|
+
return () => true;
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Combine conditions with AND
|
|
93
|
+
*/
|
|
94
|
+
and: (...conditions) => {
|
|
95
|
+
return (input, context) => {
|
|
96
|
+
return conditions.every(c => c(input, context));
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Combine conditions with OR
|
|
101
|
+
*/
|
|
102
|
+
or: (...conditions) => {
|
|
103
|
+
return (input, context) => {
|
|
104
|
+
return conditions.some(c => c(input, context));
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Create a router agent
|
|
110
|
+
*/
|
|
111
|
+
function createRouter(config) {
|
|
112
|
+
return new RouterAgent(config);
|
|
113
|
+
}
|
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-5-nano';
|
|
14
14
|
this.markdown = config.markdown ?? true;
|
|
15
15
|
this.stream = config.stream ?? true;
|
|
16
16
|
this.tools = config.tools;
|
package/dist/agent/types.js
CHANGED
|
@@ -22,7 +22,7 @@ class Agent {
|
|
|
22
22
|
this.goal = config.goal;
|
|
23
23
|
this.backstory = config.backstory;
|
|
24
24
|
this.verbose = config.verbose || false;
|
|
25
|
-
this.llm = new openai_1.OpenAIService(config.llm || 'gpt-
|
|
25
|
+
this.llm = new openai_1.OpenAIService(config.llm || 'gpt-5-nano');
|
|
26
26
|
this.markdown = config.markdown || true;
|
|
27
27
|
this.result = '';
|
|
28
28
|
logger_1.Logger.debug(`Agent created: ${this.name}`, { config });
|
|
@@ -87,7 +87,7 @@ class PraisonAIAgents {
|
|
|
87
87
|
this.tasks = config.tasks;
|
|
88
88
|
this.verbose = config.verbose || false;
|
|
89
89
|
this.process = config.process || 'sequential';
|
|
90
|
-
this.manager_llm = config.manager_llm || 'gpt-
|
|
90
|
+
this.manager_llm = config.manager_llm || 'gpt-5-nano';
|
|
91
91
|
logger_1.Logger.debug('PraisonAIAgents initialized', { config });
|
|
92
92
|
}
|
|
93
93
|
async start() {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AutoAgents - Automatic agent generation from task descriptions
|
|
3
|
+
*/
|
|
4
|
+
export interface AgentConfig {
|
|
5
|
+
name: string;
|
|
6
|
+
role: string;
|
|
7
|
+
goal: string;
|
|
8
|
+
backstory?: string;
|
|
9
|
+
instructions?: string;
|
|
10
|
+
tools?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface TaskConfig {
|
|
13
|
+
description: string;
|
|
14
|
+
expectedOutput?: string;
|
|
15
|
+
agent?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TeamStructure {
|
|
18
|
+
agents: AgentConfig[];
|
|
19
|
+
tasks: TaskConfig[];
|
|
20
|
+
pattern: 'sequential' | 'parallel' | 'hierarchical';
|
|
21
|
+
}
|
|
22
|
+
export interface AutoAgentsConfig {
|
|
23
|
+
llm?: string;
|
|
24
|
+
pattern?: 'sequential' | 'parallel' | 'routing' | 'orchestrator-workers' | 'evaluator-optimizer';
|
|
25
|
+
singleAgent?: boolean;
|
|
26
|
+
verbose?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* AutoAgents - Generate agent configurations from task descriptions
|
|
30
|
+
*/
|
|
31
|
+
export declare class AutoAgents {
|
|
32
|
+
private provider;
|
|
33
|
+
private pattern;
|
|
34
|
+
private singleAgent;
|
|
35
|
+
private verbose;
|
|
36
|
+
constructor(config?: AutoAgentsConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Generate agent configuration from task description
|
|
39
|
+
*/
|
|
40
|
+
generate(taskDescription: string): Promise<TeamStructure>;
|
|
41
|
+
/**
|
|
42
|
+
* Recommend a pattern for the task
|
|
43
|
+
*/
|
|
44
|
+
recommendPattern(taskDescription: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Analyze task complexity
|
|
47
|
+
*/
|
|
48
|
+
analyzeComplexity(taskDescription: string): 'simple' | 'moderate' | 'complex';
|
|
49
|
+
private getSystemPrompt;
|
|
50
|
+
private buildPrompt;
|
|
51
|
+
private parseResponse;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create an AutoAgents instance
|
|
55
|
+
*/
|
|
56
|
+
export declare function createAutoAgents(config?: AutoAgentsConfig): AutoAgents;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AutoAgents - Automatic agent generation from task descriptions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AutoAgents = void 0;
|
|
7
|
+
exports.createAutoAgents = createAutoAgents;
|
|
8
|
+
const providers_1 = require("../llm/providers");
|
|
9
|
+
/**
|
|
10
|
+
* AutoAgents - Generate agent configurations from task descriptions
|
|
11
|
+
*/
|
|
12
|
+
class AutoAgents {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
this.provider = (0, providers_1.createProvider)(config.llm || 'openai/gpt-4o-mini');
|
|
15
|
+
this.pattern = config.pattern || 'sequential';
|
|
16
|
+
this.singleAgent = config.singleAgent ?? false;
|
|
17
|
+
this.verbose = config.verbose ?? false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate agent configuration from task description
|
|
21
|
+
*/
|
|
22
|
+
async generate(taskDescription) {
|
|
23
|
+
const prompt = this.buildPrompt(taskDescription);
|
|
24
|
+
const result = await this.provider.generateText({
|
|
25
|
+
messages: [
|
|
26
|
+
{ role: 'system', content: this.getSystemPrompt() },
|
|
27
|
+
{ role: 'user', content: prompt }
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
return this.parseResponse(result.text);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Recommend a pattern for the task
|
|
34
|
+
*/
|
|
35
|
+
recommendPattern(taskDescription) {
|
|
36
|
+
const lower = taskDescription.toLowerCase();
|
|
37
|
+
if (lower.includes('parallel') || lower.includes('concurrent') || lower.includes('simultaneously')) {
|
|
38
|
+
return 'parallel';
|
|
39
|
+
}
|
|
40
|
+
if (lower.includes('route') || lower.includes('classify') || lower.includes('categorize')) {
|
|
41
|
+
return 'routing';
|
|
42
|
+
}
|
|
43
|
+
if (lower.includes('orchestrat') || lower.includes('coordinat') || lower.includes('manage')) {
|
|
44
|
+
return 'orchestrator-workers';
|
|
45
|
+
}
|
|
46
|
+
if (lower.includes('evaluat') || lower.includes('optimi') || lower.includes('improv')) {
|
|
47
|
+
return 'evaluator-optimizer';
|
|
48
|
+
}
|
|
49
|
+
return 'sequential';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Analyze task complexity
|
|
53
|
+
*/
|
|
54
|
+
analyzeComplexity(taskDescription) {
|
|
55
|
+
const words = taskDescription.split(/\s+/).length;
|
|
56
|
+
const hasMultipleSteps = /step|then|after|before|first|second|third|finally/i.test(taskDescription);
|
|
57
|
+
const hasMultipleAgents = /team|multiple|several|different|various/i.test(taskDescription);
|
|
58
|
+
if (words < 20 && !hasMultipleSteps && !hasMultipleAgents) {
|
|
59
|
+
return 'simple';
|
|
60
|
+
}
|
|
61
|
+
if (words > 100 || (hasMultipleSteps && hasMultipleAgents)) {
|
|
62
|
+
return 'complex';
|
|
63
|
+
}
|
|
64
|
+
return 'moderate';
|
|
65
|
+
}
|
|
66
|
+
getSystemPrompt() {
|
|
67
|
+
return `You are an AI agent architect. Your job is to analyze task descriptions and generate optimal agent configurations.
|
|
68
|
+
|
|
69
|
+
Output a JSON object with the following structure:
|
|
70
|
+
{
|
|
71
|
+
"agents": [
|
|
72
|
+
{
|
|
73
|
+
"name": "AgentName",
|
|
74
|
+
"role": "Role description",
|
|
75
|
+
"goal": "Agent's goal",
|
|
76
|
+
"backstory": "Optional backstory",
|
|
77
|
+
"instructions": "Specific instructions",
|
|
78
|
+
"tools": ["tool1", "tool2"]
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"tasks": [
|
|
82
|
+
{
|
|
83
|
+
"description": "Task description",
|
|
84
|
+
"expectedOutput": "What the task should produce",
|
|
85
|
+
"agent": "AgentName"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"pattern": "sequential|parallel|hierarchical"
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Guidelines:
|
|
92
|
+
- For simple tasks, use 1 agent
|
|
93
|
+
- For moderate tasks, use 2-3 agents
|
|
94
|
+
- For complex tasks, use 3-5 agents
|
|
95
|
+
- Match the pattern to the task requirements
|
|
96
|
+
- Be specific about roles and goals`;
|
|
97
|
+
}
|
|
98
|
+
buildPrompt(taskDescription) {
|
|
99
|
+
const complexity = this.analyzeComplexity(taskDescription);
|
|
100
|
+
const recommendedPattern = this.recommendPattern(taskDescription);
|
|
101
|
+
return `Task Description: ${taskDescription}
|
|
102
|
+
|
|
103
|
+
Complexity: ${complexity}
|
|
104
|
+
Recommended Pattern: ${this.pattern || recommendedPattern}
|
|
105
|
+
Single Agent Mode: ${this.singleAgent}
|
|
106
|
+
|
|
107
|
+
Generate an optimal agent configuration for this task.`;
|
|
108
|
+
}
|
|
109
|
+
parseResponse(response) {
|
|
110
|
+
try {
|
|
111
|
+
// Extract JSON from response
|
|
112
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
113
|
+
if (jsonMatch) {
|
|
114
|
+
return JSON.parse(jsonMatch[0]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// Fallback to default structure
|
|
119
|
+
}
|
|
120
|
+
// Default fallback
|
|
121
|
+
return {
|
|
122
|
+
agents: [{
|
|
123
|
+
name: 'GeneralAgent',
|
|
124
|
+
role: 'General purpose agent',
|
|
125
|
+
goal: 'Complete the assigned task',
|
|
126
|
+
instructions: 'Follow the task description carefully'
|
|
127
|
+
}],
|
|
128
|
+
tasks: [{
|
|
129
|
+
description: 'Complete the task',
|
|
130
|
+
agent: 'GeneralAgent'
|
|
131
|
+
}],
|
|
132
|
+
pattern: 'sequential'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.AutoAgents = AutoAgents;
|
|
137
|
+
/**
|
|
138
|
+
* Create an AutoAgents instance
|
|
139
|
+
*/
|
|
140
|
+
function createAutoAgents(config) {
|
|
141
|
+
return new AutoAgents(config);
|
|
142
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* PraisonAI TypeScript CLI
|
|
4
|
+
*/
|
|
5
|
+
interface CLIOptions {
|
|
6
|
+
model?: string;
|
|
7
|
+
stream?: boolean;
|
|
8
|
+
verbose?: boolean;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
}
|
|
11
|
+
declare function chat(prompt: string, options?: CLIOptions): Promise<string>;
|
|
12
|
+
declare function listProviders(): Promise<void>;
|
|
13
|
+
declare function version(): Promise<void>;
|
|
14
|
+
declare function help(): Promise<void>;
|
|
15
|
+
declare function parseArgs(args: string[]): {
|
|
16
|
+
command: string;
|
|
17
|
+
prompt: string;
|
|
18
|
+
options: CLIOptions;
|
|
19
|
+
};
|
|
20
|
+
export { chat, listProviders, version, help, parseArgs };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* PraisonAI TypeScript CLI
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.chat = chat;
|
|
8
|
+
exports.listProviders = listProviders;
|
|
9
|
+
exports.version = version;
|
|
10
|
+
exports.help = help;
|
|
11
|
+
exports.parseArgs = parseArgs;
|
|
12
|
+
const providers_1 = require("../llm/providers");
|
|
13
|
+
const session_1 = require("../session");
|
|
14
|
+
async function chat(prompt, options = {}) {
|
|
15
|
+
const model = options.model || process.env.PRAISONAI_MODEL || 'openai/gpt-4o-mini';
|
|
16
|
+
const provider = (0, providers_1.createProvider)(model);
|
|
17
|
+
const session = new session_1.Session({ id: options.sessionId });
|
|
18
|
+
session.addMessage({ role: 'user', content: prompt });
|
|
19
|
+
if (options.stream) {
|
|
20
|
+
let fullText = '';
|
|
21
|
+
const stream = await provider.streamText({
|
|
22
|
+
messages: [{ role: 'user', content: prompt }],
|
|
23
|
+
onToken: (token) => {
|
|
24
|
+
process.stdout.write(token);
|
|
25
|
+
fullText += token;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
for await (const chunk of stream) {
|
|
29
|
+
// Stream is consumed by onToken
|
|
30
|
+
}
|
|
31
|
+
console.log(); // New line after streaming
|
|
32
|
+
return fullText;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const result = await provider.generateText({
|
|
36
|
+
messages: [{ role: 'user', content: prompt }]
|
|
37
|
+
});
|
|
38
|
+
console.log(result.text);
|
|
39
|
+
return result.text;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function listProviders() {
|
|
43
|
+
console.log('Available Providers:');
|
|
44
|
+
const available = (0, providers_1.getAvailableProviders)();
|
|
45
|
+
const providers = ['openai', 'anthropic', 'google'];
|
|
46
|
+
for (const p of providers) {
|
|
47
|
+
const status = available.includes(p) ? '✅' : '❌';
|
|
48
|
+
console.log(` ${status} ${p}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function version() {
|
|
52
|
+
const pkg = require('../../package.json');
|
|
53
|
+
console.log(`praisonai v${pkg.version}`);
|
|
54
|
+
}
|
|
55
|
+
async function help() {
|
|
56
|
+
console.log(`
|
|
57
|
+
PraisonAI TypeScript CLI
|
|
58
|
+
|
|
59
|
+
Usage:
|
|
60
|
+
praisonai-ts chat <prompt> Chat with an AI agent
|
|
61
|
+
praisonai-ts providers List available providers
|
|
62
|
+
praisonai-ts version Show version
|
|
63
|
+
praisonai-ts help Show this help
|
|
64
|
+
|
|
65
|
+
Options:
|
|
66
|
+
--model, -m <model> Model to use (e.g., openai/gpt-4o-mini)
|
|
67
|
+
--stream, -s Enable streaming output
|
|
68
|
+
--verbose, -v Verbose output
|
|
69
|
+
--session <id> Session ID for conversation continuity
|
|
70
|
+
|
|
71
|
+
Environment Variables:
|
|
72
|
+
OPENAI_API_KEY OpenAI API key
|
|
73
|
+
ANTHROPIC_API_KEY Anthropic API key
|
|
74
|
+
GOOGLE_API_KEY Google API key
|
|
75
|
+
PRAISONAI_MODEL Default model
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
praisonai-ts chat "Hello, how are you?"
|
|
79
|
+
praisonai-ts chat "Write a poem" --stream
|
|
80
|
+
praisonai-ts chat "Explain AI" -m anthropic/claude-sonnet-4-20250514
|
|
81
|
+
praisonai-ts providers
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
84
|
+
function parseArgs(args) {
|
|
85
|
+
const options = {};
|
|
86
|
+
let command = 'help';
|
|
87
|
+
let prompt = '';
|
|
88
|
+
let i = 0;
|
|
89
|
+
while (i < args.length) {
|
|
90
|
+
const arg = args[i];
|
|
91
|
+
if (arg === '--model' || arg === '-m') {
|
|
92
|
+
options.model = args[++i];
|
|
93
|
+
}
|
|
94
|
+
else if (arg === '--stream' || arg === '-s') {
|
|
95
|
+
options.stream = true;
|
|
96
|
+
}
|
|
97
|
+
else if (arg === '--verbose' || arg === '-v') {
|
|
98
|
+
options.verbose = true;
|
|
99
|
+
}
|
|
100
|
+
else if (arg === '--session') {
|
|
101
|
+
options.sessionId = args[++i];
|
|
102
|
+
}
|
|
103
|
+
else if (!arg.startsWith('-')) {
|
|
104
|
+
if (!command || command === 'help') {
|
|
105
|
+
command = arg;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
prompt = arg;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
return { command, prompt, options };
|
|
114
|
+
}
|
|
115
|
+
async function main() {
|
|
116
|
+
const args = process.argv.slice(2);
|
|
117
|
+
const { command, prompt, options } = parseArgs(args);
|
|
118
|
+
try {
|
|
119
|
+
switch (command) {
|
|
120
|
+
case 'chat':
|
|
121
|
+
if (!prompt) {
|
|
122
|
+
console.error('Error: Please provide a prompt');
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
await chat(prompt, options);
|
|
126
|
+
break;
|
|
127
|
+
case 'providers':
|
|
128
|
+
await listProviders();
|
|
129
|
+
break;
|
|
130
|
+
case 'version':
|
|
131
|
+
await version();
|
|
132
|
+
break;
|
|
133
|
+
case 'help':
|
|
134
|
+
default:
|
|
135
|
+
await help();
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error('Error:', error.message);
|
|
141
|
+
if (options.verbose) {
|
|
142
|
+
console.error(error.stack);
|
|
143
|
+
}
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Run CLI if executed directly
|
|
148
|
+
if (require.main === module) {
|
|
149
|
+
main();
|
|
150
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Module - Exports for persistence layer
|
|
3
|
+
*/
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { MemoryDbAdapter } from './memory-adapter';
|
|
6
|
+
import type { DbAdapter, DbConfig } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Create a database adapter based on configuration
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDbAdapter(config: DbConfig): DbAdapter;
|
|
11
|
+
/**
|
|
12
|
+
* Get or create the default database adapter
|
|
13
|
+
*/
|
|
14
|
+
export declare function getDefaultDbAdapter(): DbAdapter;
|
|
15
|
+
/**
|
|
16
|
+
* Set the default database adapter
|
|
17
|
+
*/
|
|
18
|
+
export declare function setDefaultDbAdapter(adapter: DbAdapter): void;
|
|
19
|
+
/**
|
|
20
|
+
* Shortcut function for creating a database adapter
|
|
21
|
+
* Usage: db({ type: 'memory' }) or db({ type: 'sqlite', path: './data.db' })
|
|
22
|
+
*/
|
|
23
|
+
export declare function db(config?: DbConfig): DbAdapter;
|
package/dist/db/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Database Module - Exports for persistence layer
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.MemoryDbAdapter = void 0;
|
|
21
|
+
exports.createDbAdapter = createDbAdapter;
|
|
22
|
+
exports.getDefaultDbAdapter = getDefaultDbAdapter;
|
|
23
|
+
exports.setDefaultDbAdapter = setDefaultDbAdapter;
|
|
24
|
+
exports.db = db;
|
|
25
|
+
__exportStar(require("./types"), exports);
|
|
26
|
+
var memory_adapter_1 = require("./memory-adapter");
|
|
27
|
+
Object.defineProperty(exports, "MemoryDbAdapter", { enumerable: true, get: function () { return memory_adapter_1.MemoryDbAdapter; } });
|
|
28
|
+
const memory_adapter_2 = require("./memory-adapter");
|
|
29
|
+
// Default adapter instance
|
|
30
|
+
let defaultAdapter = null;
|
|
31
|
+
/**
|
|
32
|
+
* Create a database adapter based on configuration
|
|
33
|
+
*/
|
|
34
|
+
function createDbAdapter(config) {
|
|
35
|
+
switch (config.type) {
|
|
36
|
+
case 'memory':
|
|
37
|
+
return new memory_adapter_2.MemoryDbAdapter();
|
|
38
|
+
case 'sqlite':
|
|
39
|
+
// SQLite adapter would be implemented here
|
|
40
|
+
throw new Error('SQLite adapter not yet implemented. Use memory adapter for now.');
|
|
41
|
+
case 'postgres':
|
|
42
|
+
// PostgreSQL adapter would be implemented here
|
|
43
|
+
throw new Error('PostgreSQL adapter not yet implemented. Use memory adapter for now.');
|
|
44
|
+
case 'redis':
|
|
45
|
+
// Redis adapter would be implemented here
|
|
46
|
+
throw new Error('Redis adapter not yet implemented. Use memory adapter for now.');
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Unknown database type: ${config.type}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get or create the default database adapter
|
|
53
|
+
*/
|
|
54
|
+
function getDefaultDbAdapter() {
|
|
55
|
+
if (!defaultAdapter) {
|
|
56
|
+
defaultAdapter = new memory_adapter_2.MemoryDbAdapter();
|
|
57
|
+
}
|
|
58
|
+
return defaultAdapter;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Set the default database adapter
|
|
62
|
+
*/
|
|
63
|
+
function setDefaultDbAdapter(adapter) {
|
|
64
|
+
defaultAdapter = adapter;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Shortcut function for creating a database adapter
|
|
68
|
+
* Usage: db({ type: 'memory' }) or db({ type: 'sqlite', path: './data.db' })
|
|
69
|
+
*/
|
|
70
|
+
function db(config = { type: 'memory' }) {
|
|
71
|
+
return createDbAdapter(config);
|
|
72
|
+
}
|