praisonai 1.0.19 → 1.1.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/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/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/index.d.ts +16 -1
- package/dist/index.js +72 -1
- 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/observability/index.d.ts +86 -0
- package/dist/observability/index.js +166 -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/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 +6 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflows - Pipeline and orchestration patterns
|
|
3
|
+
*/
|
|
4
|
+
export type StepStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
|
|
5
|
+
export interface StepResult<T = any> {
|
|
6
|
+
stepId: string;
|
|
7
|
+
stepName: string;
|
|
8
|
+
status: StepStatus;
|
|
9
|
+
output?: T;
|
|
10
|
+
error?: Error;
|
|
11
|
+
duration: number;
|
|
12
|
+
startedAt: number;
|
|
13
|
+
completedAt?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkflowContext {
|
|
16
|
+
workflowId: string;
|
|
17
|
+
stepResults: Map<string, StepResult>;
|
|
18
|
+
metadata: Record<string, any>;
|
|
19
|
+
get<T = any>(stepName: string): T | undefined;
|
|
20
|
+
set(key: string, value: any): void;
|
|
21
|
+
}
|
|
22
|
+
export type StepFunction<TInput = any, TOutput = any> = (input: TInput, context: WorkflowContext) => Promise<TOutput> | TOutput;
|
|
23
|
+
export interface WorkflowStepConfig<TInput = any, TOutput = any> {
|
|
24
|
+
name: string;
|
|
25
|
+
execute: StepFunction<TInput, TOutput>;
|
|
26
|
+
condition?: (context: WorkflowContext) => boolean;
|
|
27
|
+
onError?: 'fail' | 'skip' | 'retry';
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Workflow Step
|
|
33
|
+
*/
|
|
34
|
+
export declare class WorkflowStep<TInput = any, TOutput = any> {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly execute: StepFunction<TInput, TOutput>;
|
|
38
|
+
readonly condition?: (context: WorkflowContext) => boolean;
|
|
39
|
+
readonly onError: 'fail' | 'skip' | 'retry';
|
|
40
|
+
readonly maxRetries: number;
|
|
41
|
+
readonly timeout?: number;
|
|
42
|
+
constructor(config: WorkflowStepConfig<TInput, TOutput>);
|
|
43
|
+
run(input: TInput, context: WorkflowContext): Promise<StepResult<TOutput>>;
|
|
44
|
+
private executeWithTimeout;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Workflow - Sequential pipeline execution
|
|
48
|
+
*/
|
|
49
|
+
export declare class Workflow<TInput = any, TOutput = any> {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly name: string;
|
|
52
|
+
private steps;
|
|
53
|
+
constructor(name: string);
|
|
54
|
+
/**
|
|
55
|
+
* Add a step to the workflow
|
|
56
|
+
*/
|
|
57
|
+
addStep<TStepInput = any, TStepOutput = any>(config: WorkflowStepConfig<TStepInput, TStepOutput>): this;
|
|
58
|
+
/**
|
|
59
|
+
* Add a step using a simpler syntax
|
|
60
|
+
*/
|
|
61
|
+
step<TStepInput = any, TStepOutput = any>(name: string, execute: StepFunction<TStepInput, TStepOutput>): this;
|
|
62
|
+
/**
|
|
63
|
+
* Run the workflow
|
|
64
|
+
*/
|
|
65
|
+
run(input: TInput): Promise<{
|
|
66
|
+
output: TOutput | undefined;
|
|
67
|
+
results: StepResult[];
|
|
68
|
+
context: WorkflowContext;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Get step count
|
|
72
|
+
*/
|
|
73
|
+
get stepCount(): number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Pipeline - Alias for Workflow
|
|
77
|
+
*/
|
|
78
|
+
export declare const Pipeline: typeof Workflow;
|
|
79
|
+
/**
|
|
80
|
+
* Parallel execution helper
|
|
81
|
+
*/
|
|
82
|
+
export declare function parallel<T>(tasks: Array<() => Promise<T>>): Promise<T[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Route helper - Execute based on condition
|
|
85
|
+
*/
|
|
86
|
+
export declare function route<T>(conditions: Array<{
|
|
87
|
+
condition: () => boolean;
|
|
88
|
+
execute: () => Promise<T>;
|
|
89
|
+
}>, defaultExecute?: () => Promise<T>): Promise<T | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Loop helper - Repeat until condition
|
|
92
|
+
*/
|
|
93
|
+
export declare function loop<T>(execute: (iteration: number) => Promise<T>, shouldContinue: (result: T, iteration: number) => boolean, maxIterations?: number): Promise<T[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Repeat helper - Execute N times
|
|
96
|
+
*/
|
|
97
|
+
export declare function repeat<T>(execute: (iteration: number) => Promise<T>, times: number): Promise<T[]>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Workflows - Pipeline and orchestration patterns
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Pipeline = exports.Workflow = exports.WorkflowStep = void 0;
|
|
7
|
+
exports.parallel = parallel;
|
|
8
|
+
exports.route = route;
|
|
9
|
+
exports.loop = loop;
|
|
10
|
+
exports.repeat = repeat;
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
/**
|
|
13
|
+
* Workflow Step
|
|
14
|
+
*/
|
|
15
|
+
class WorkflowStep {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.id = (0, crypto_1.randomUUID)();
|
|
18
|
+
this.name = config.name;
|
|
19
|
+
this.execute = config.execute;
|
|
20
|
+
this.condition = config.condition;
|
|
21
|
+
this.onError = config.onError || 'fail';
|
|
22
|
+
this.maxRetries = config.maxRetries || 0;
|
|
23
|
+
this.timeout = config.timeout;
|
|
24
|
+
}
|
|
25
|
+
async run(input, context) {
|
|
26
|
+
const startedAt = Date.now();
|
|
27
|
+
// Check condition
|
|
28
|
+
if (this.condition && !this.condition(context)) {
|
|
29
|
+
return {
|
|
30
|
+
stepId: this.id,
|
|
31
|
+
stepName: this.name,
|
|
32
|
+
status: 'skipped',
|
|
33
|
+
duration: 0,
|
|
34
|
+
startedAt,
|
|
35
|
+
completedAt: Date.now(),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
let lastError;
|
|
39
|
+
let attempts = 0;
|
|
40
|
+
while (attempts <= this.maxRetries) {
|
|
41
|
+
attempts++;
|
|
42
|
+
try {
|
|
43
|
+
const output = await this.executeWithTimeout(input, context);
|
|
44
|
+
const completedAt = Date.now();
|
|
45
|
+
return {
|
|
46
|
+
stepId: this.id,
|
|
47
|
+
stepName: this.name,
|
|
48
|
+
status: 'completed',
|
|
49
|
+
output,
|
|
50
|
+
duration: completedAt - startedAt,
|
|
51
|
+
startedAt,
|
|
52
|
+
completedAt,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
lastError = error;
|
|
57
|
+
if (this.onError === 'skip') {
|
|
58
|
+
return {
|
|
59
|
+
stepId: this.id,
|
|
60
|
+
stepName: this.name,
|
|
61
|
+
status: 'skipped',
|
|
62
|
+
error: lastError,
|
|
63
|
+
duration: Date.now() - startedAt,
|
|
64
|
+
startedAt,
|
|
65
|
+
completedAt: Date.now(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (this.onError !== 'retry' || attempts > this.maxRetries) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
stepId: this.id,
|
|
75
|
+
stepName: this.name,
|
|
76
|
+
status: 'failed',
|
|
77
|
+
error: lastError,
|
|
78
|
+
duration: Date.now() - startedAt,
|
|
79
|
+
startedAt,
|
|
80
|
+
completedAt: Date.now(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async executeWithTimeout(input, context) {
|
|
84
|
+
if (!this.timeout) {
|
|
85
|
+
return this.execute(input, context);
|
|
86
|
+
}
|
|
87
|
+
return Promise.race([
|
|
88
|
+
this.execute(input, context),
|
|
89
|
+
new Promise((_, reject) => {
|
|
90
|
+
setTimeout(() => reject(new Error(`Step ${this.name} timed out after ${this.timeout}ms`)), this.timeout);
|
|
91
|
+
}),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.WorkflowStep = WorkflowStep;
|
|
96
|
+
/**
|
|
97
|
+
* Create a workflow context
|
|
98
|
+
*/
|
|
99
|
+
function createContext(workflowId) {
|
|
100
|
+
const stepResults = new Map();
|
|
101
|
+
const metadata = {};
|
|
102
|
+
return {
|
|
103
|
+
workflowId,
|
|
104
|
+
stepResults,
|
|
105
|
+
metadata,
|
|
106
|
+
get(stepName) {
|
|
107
|
+
const result = stepResults.get(stepName);
|
|
108
|
+
return result?.output;
|
|
109
|
+
},
|
|
110
|
+
set(key, value) {
|
|
111
|
+
metadata[key] = value;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Workflow - Sequential pipeline execution
|
|
117
|
+
*/
|
|
118
|
+
class Workflow {
|
|
119
|
+
constructor(name) {
|
|
120
|
+
this.steps = [];
|
|
121
|
+
this.id = (0, crypto_1.randomUUID)();
|
|
122
|
+
this.name = name;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Add a step to the workflow
|
|
126
|
+
*/
|
|
127
|
+
addStep(config) {
|
|
128
|
+
this.steps.push(new WorkflowStep(config));
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Add a step using a simpler syntax
|
|
133
|
+
*/
|
|
134
|
+
step(name, execute) {
|
|
135
|
+
return this.addStep({ name, execute });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Run the workflow
|
|
139
|
+
*/
|
|
140
|
+
async run(input) {
|
|
141
|
+
const context = createContext(this.id);
|
|
142
|
+
const results = [];
|
|
143
|
+
let currentInput = input;
|
|
144
|
+
for (const step of this.steps) {
|
|
145
|
+
const result = await step.run(currentInput, context);
|
|
146
|
+
results.push(result);
|
|
147
|
+
context.stepResults.set(step.name, result);
|
|
148
|
+
if (result.status === 'failed') {
|
|
149
|
+
return { output: undefined, results, context };
|
|
150
|
+
}
|
|
151
|
+
if (result.status === 'completed') {
|
|
152
|
+
currentInput = result.output;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const lastResult = results[results.length - 1];
|
|
156
|
+
return {
|
|
157
|
+
output: lastResult?.output,
|
|
158
|
+
results,
|
|
159
|
+
context,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get step count
|
|
164
|
+
*/
|
|
165
|
+
get stepCount() {
|
|
166
|
+
return this.steps.length;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.Workflow = Workflow;
|
|
170
|
+
/**
|
|
171
|
+
* Pipeline - Alias for Workflow
|
|
172
|
+
*/
|
|
173
|
+
exports.Pipeline = Workflow;
|
|
174
|
+
/**
|
|
175
|
+
* Parallel execution helper
|
|
176
|
+
*/
|
|
177
|
+
async function parallel(tasks) {
|
|
178
|
+
return Promise.all(tasks.map(task => task()));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Route helper - Execute based on condition
|
|
182
|
+
*/
|
|
183
|
+
async function route(conditions, defaultExecute) {
|
|
184
|
+
for (const { condition, execute } of conditions) {
|
|
185
|
+
if (condition()) {
|
|
186
|
+
return execute();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return defaultExecute?.();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Loop helper - Repeat until condition
|
|
193
|
+
*/
|
|
194
|
+
async function loop(execute, shouldContinue, maxIterations = 100) {
|
|
195
|
+
const results = [];
|
|
196
|
+
let iteration = 0;
|
|
197
|
+
while (iteration < maxIterations) {
|
|
198
|
+
const result = await execute(iteration);
|
|
199
|
+
results.push(result);
|
|
200
|
+
if (!shouldContinue(result, iteration)) {
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
iteration++;
|
|
204
|
+
}
|
|
205
|
+
return results;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Repeat helper - Execute N times
|
|
209
|
+
*/
|
|
210
|
+
async function repeat(execute, times) {
|
|
211
|
+
const results = [];
|
|
212
|
+
for (let i = 0; i < times; i++) {
|
|
213
|
+
results.push(await execute(i));
|
|
214
|
+
}
|
|
215
|
+
return results;
|
|
216
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "praisonai",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "PraisonAI TypeScript AI Agents Framework - Node.js, npm, and Javascript AI Agents Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"praisonai-ts": "./dist/cli/index.js"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc",
|
|
9
12
|
"test": "jest",
|
|
@@ -62,7 +65,8 @@
|
|
|
62
65
|
"fast-xml-parser": "^4.5.1",
|
|
63
66
|
"node-fetch": "^2.6.9",
|
|
64
67
|
"openai": "^4.81.0",
|
|
65
|
-
"praisonai": "
|
|
68
|
+
"praisonai": "latest",
|
|
69
|
+
"@modelcontextprotocol/sdk": "^1.12.1"
|
|
66
70
|
},
|
|
67
71
|
"optionalDependencies": {
|
|
68
72
|
"boxen": "^7.1.1",
|