praisonai 1.2.0 → 1.2.2
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/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -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 +12 -1
- package/dist/index.js +88 -2
- 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/tools/arxivTools.d.ts +19 -6
- package/dist/tools/arxivTools.js +13 -7
- package/dist/tools/base.d.ts +97 -0
- package/dist/tools/base.js +147 -0
- package/dist/tools/index.d.ts +1 -11
- package/dist/tools/index.js +7 -11
- package/dist/tools/mcpSse.d.ts +5 -3
- package/dist/tools/mcpSse.js +6 -4
- package/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +1 -1
package/dist/tools/mcpSse.js
CHANGED
|
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MCP = exports.MCPTool = void 0;
|
|
4
4
|
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
5
5
|
const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
6
|
-
const
|
|
7
|
-
class MCPTool extends
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
class MCPTool extends base_1.BaseTool {
|
|
8
8
|
constructor(info, client) {
|
|
9
|
-
super(
|
|
9
|
+
super();
|
|
10
|
+
this.name = info.name;
|
|
11
|
+
this.description = info.description || `Call the ${info.name} tool`;
|
|
10
12
|
this.client = client;
|
|
11
13
|
this.inputSchema = info.inputSchema || { type: 'object', properties: {}, required: [] };
|
|
12
14
|
}
|
|
13
15
|
get schemaProperties() {
|
|
14
16
|
return this.inputSchema?.properties;
|
|
15
17
|
}
|
|
16
|
-
async
|
|
18
|
+
async run(args = {}) {
|
|
17
19
|
try {
|
|
18
20
|
const result = await this.client.callTool({ name: this.name, arguments: args });
|
|
19
21
|
if (result.structuredContent) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML Workflow Parser
|
|
3
|
+
* Parse YAML workflow definitions into executable workflows
|
|
4
|
+
*/
|
|
5
|
+
import { Workflow } from './index';
|
|
6
|
+
export interface YAMLWorkflowDefinition {
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
steps: YAMLStepDefinition[];
|
|
11
|
+
metadata?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export interface YAMLStepDefinition {
|
|
14
|
+
name: string;
|
|
15
|
+
type: 'agent' | 'tool' | 'condition' | 'parallel' | 'loop';
|
|
16
|
+
agent?: string;
|
|
17
|
+
tool?: string;
|
|
18
|
+
input?: string | Record<string, any>;
|
|
19
|
+
output?: string;
|
|
20
|
+
condition?: string;
|
|
21
|
+
onError?: 'fail' | 'skip' | 'retry';
|
|
22
|
+
maxRetries?: number;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
steps?: YAMLStepDefinition[];
|
|
25
|
+
loopCondition?: string;
|
|
26
|
+
maxIterations?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ParsedWorkflow {
|
|
29
|
+
workflow: Workflow;
|
|
30
|
+
definition: YAMLWorkflowDefinition;
|
|
31
|
+
errors: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse YAML string into workflow definition
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseYAMLWorkflow(yamlContent: string): YAMLWorkflowDefinition;
|
|
37
|
+
/**
|
|
38
|
+
* Create executable workflow from YAML definition
|
|
39
|
+
*/
|
|
40
|
+
export declare function createWorkflowFromYAML(definition: YAMLWorkflowDefinition, agents?: Record<string, any>, tools?: Record<string, any>): ParsedWorkflow;
|
|
41
|
+
/**
|
|
42
|
+
* Load workflow from YAML file
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadWorkflowFromFile(filePath: string, agents?: Record<string, any>, tools?: Record<string, any>): Promise<ParsedWorkflow>;
|
|
45
|
+
/**
|
|
46
|
+
* Validate YAML workflow definition
|
|
47
|
+
*/
|
|
48
|
+
export declare function validateWorkflowDefinition(definition: YAMLWorkflowDefinition): string[];
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* YAML Workflow Parser
|
|
4
|
+
* Parse YAML workflow definitions into executable workflows
|
|
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.parseYAMLWorkflow = parseYAMLWorkflow;
|
|
41
|
+
exports.createWorkflowFromYAML = createWorkflowFromYAML;
|
|
42
|
+
exports.loadWorkflowFromFile = loadWorkflowFromFile;
|
|
43
|
+
exports.validateWorkflowDefinition = validateWorkflowDefinition;
|
|
44
|
+
const index_1 = require("./index");
|
|
45
|
+
/**
|
|
46
|
+
* Parse YAML string into workflow definition
|
|
47
|
+
*/
|
|
48
|
+
function parseYAMLWorkflow(yamlContent) {
|
|
49
|
+
// Simple YAML parser for workflow definitions
|
|
50
|
+
// For production, use js-yaml package
|
|
51
|
+
const lines = yamlContent.split('\n');
|
|
52
|
+
const result = {
|
|
53
|
+
name: '',
|
|
54
|
+
steps: []
|
|
55
|
+
};
|
|
56
|
+
let currentStep = null;
|
|
57
|
+
let indent = 0;
|
|
58
|
+
for (const line of lines) {
|
|
59
|
+
const trimmed = line.trim();
|
|
60
|
+
if (!trimmed || trimmed.startsWith('#'))
|
|
61
|
+
continue;
|
|
62
|
+
const currentIndent = line.search(/\S/);
|
|
63
|
+
// Parse key-value pairs
|
|
64
|
+
const colonIndex = trimmed.indexOf(':');
|
|
65
|
+
if (colonIndex === -1)
|
|
66
|
+
continue;
|
|
67
|
+
const key = trimmed.substring(0, colonIndex).trim();
|
|
68
|
+
const value = trimmed.substring(colonIndex + 1).trim();
|
|
69
|
+
if (currentIndent === 0) {
|
|
70
|
+
// Top-level keys
|
|
71
|
+
if (key === 'name')
|
|
72
|
+
result.name = value;
|
|
73
|
+
else if (key === 'description')
|
|
74
|
+
result.description = value;
|
|
75
|
+
else if (key === 'version')
|
|
76
|
+
result.version = value;
|
|
77
|
+
else if (key === 'steps') {
|
|
78
|
+
// Steps array starts
|
|
79
|
+
indent = currentIndent;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (trimmed.startsWith('- name:')) {
|
|
83
|
+
// New step
|
|
84
|
+
if (currentStep && currentStep.name) {
|
|
85
|
+
result.steps.push(currentStep);
|
|
86
|
+
}
|
|
87
|
+
currentStep = {
|
|
88
|
+
name: value,
|
|
89
|
+
type: 'agent'
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else if (currentStep) {
|
|
93
|
+
// Step properties
|
|
94
|
+
if (key === 'type')
|
|
95
|
+
currentStep.type = value;
|
|
96
|
+
else if (key === 'agent')
|
|
97
|
+
currentStep.agent = value;
|
|
98
|
+
else if (key === 'tool')
|
|
99
|
+
currentStep.tool = value;
|
|
100
|
+
else if (key === 'input')
|
|
101
|
+
currentStep.input = value;
|
|
102
|
+
else if (key === 'output')
|
|
103
|
+
currentStep.output = value;
|
|
104
|
+
else if (key === 'condition')
|
|
105
|
+
currentStep.condition = value;
|
|
106
|
+
else if (key === 'onError')
|
|
107
|
+
currentStep.onError = value;
|
|
108
|
+
else if (key === 'maxRetries')
|
|
109
|
+
currentStep.maxRetries = parseInt(value);
|
|
110
|
+
else if (key === 'timeout')
|
|
111
|
+
currentStep.timeout = parseInt(value);
|
|
112
|
+
else if (key === 'loopCondition')
|
|
113
|
+
currentStep.loopCondition = value;
|
|
114
|
+
else if (key === 'maxIterations')
|
|
115
|
+
currentStep.maxIterations = parseInt(value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Add last step
|
|
119
|
+
if (currentStep && currentStep.name) {
|
|
120
|
+
result.steps.push(currentStep);
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create executable workflow from YAML definition
|
|
126
|
+
*/
|
|
127
|
+
function createWorkflowFromYAML(definition, agents = {}, tools = {}) {
|
|
128
|
+
const errors = [];
|
|
129
|
+
const workflow = new index_1.Workflow(definition.name);
|
|
130
|
+
for (const stepDef of definition.steps) {
|
|
131
|
+
try {
|
|
132
|
+
const stepConfig = createStepConfig(stepDef, agents, tools, errors);
|
|
133
|
+
if (stepConfig) {
|
|
134
|
+
workflow.addStep(stepConfig);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
errors.push(`Error creating step ${stepDef.name}: ${error.message}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { workflow, definition, errors };
|
|
142
|
+
}
|
|
143
|
+
function createStepConfig(stepDef, agents, tools, errors) {
|
|
144
|
+
const { name, type, agent, tool, onError, maxRetries, timeout, condition } = stepDef;
|
|
145
|
+
let execute;
|
|
146
|
+
switch (type) {
|
|
147
|
+
case 'agent':
|
|
148
|
+
if (!agent) {
|
|
149
|
+
errors.push(`Step ${name}: agent type requires 'agent' field`);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const agentInstance = agents[agent];
|
|
153
|
+
if (!agentInstance) {
|
|
154
|
+
errors.push(`Step ${name}: agent '${agent}' not found`);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
execute = async (input) => {
|
|
158
|
+
if (typeof agentInstance.chat === 'function') {
|
|
159
|
+
return agentInstance.chat(typeof input === 'string' ? input : JSON.stringify(input));
|
|
160
|
+
}
|
|
161
|
+
return agentInstance(input);
|
|
162
|
+
};
|
|
163
|
+
break;
|
|
164
|
+
case 'tool':
|
|
165
|
+
if (!tool) {
|
|
166
|
+
errors.push(`Step ${name}: tool type requires 'tool' field`);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const toolInstance = tools[tool];
|
|
170
|
+
if (!toolInstance) {
|
|
171
|
+
errors.push(`Step ${name}: tool '${tool}' not found`);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
execute = async (input) => {
|
|
175
|
+
if (typeof toolInstance.execute === 'function') {
|
|
176
|
+
return toolInstance.execute(input);
|
|
177
|
+
}
|
|
178
|
+
if (typeof toolInstance.run === 'function') {
|
|
179
|
+
return toolInstance.run(input);
|
|
180
|
+
}
|
|
181
|
+
return toolInstance(input);
|
|
182
|
+
};
|
|
183
|
+
break;
|
|
184
|
+
case 'condition':
|
|
185
|
+
execute = async (input, context) => {
|
|
186
|
+
// Evaluate condition and return input or skip
|
|
187
|
+
if (condition) {
|
|
188
|
+
// Simple condition evaluation
|
|
189
|
+
const result = evaluateCondition(condition, input, context);
|
|
190
|
+
return result ? input : null;
|
|
191
|
+
}
|
|
192
|
+
return input;
|
|
193
|
+
};
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
execute = async (input) => input;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
name,
|
|
200
|
+
execute,
|
|
201
|
+
onError,
|
|
202
|
+
maxRetries,
|
|
203
|
+
timeout,
|
|
204
|
+
condition: condition ? (context) => evaluateCondition(condition, null, context) : undefined
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function evaluateCondition(condition, input, context) {
|
|
208
|
+
// Simple condition evaluation
|
|
209
|
+
// Supports: "result.success", "input.length > 0", etc.
|
|
210
|
+
try {
|
|
211
|
+
// Create a safe evaluation context
|
|
212
|
+
const evalContext = {
|
|
213
|
+
input,
|
|
214
|
+
context,
|
|
215
|
+
result: context?.get?.('lastResult'),
|
|
216
|
+
...context?.metadata
|
|
217
|
+
};
|
|
218
|
+
// Simple expression evaluation
|
|
219
|
+
if (condition.includes('===')) {
|
|
220
|
+
const [left, right] = condition.split('===').map(s => s.trim());
|
|
221
|
+
return getNestedValue(evalContext, left) === parseValue(right);
|
|
222
|
+
}
|
|
223
|
+
if (condition.includes('!==')) {
|
|
224
|
+
const [left, right] = condition.split('!==').map(s => s.trim());
|
|
225
|
+
return getNestedValue(evalContext, left) !== parseValue(right);
|
|
226
|
+
}
|
|
227
|
+
if (condition.includes('>')) {
|
|
228
|
+
const [left, right] = condition.split('>').map(s => s.trim());
|
|
229
|
+
return getNestedValue(evalContext, left) > parseValue(right);
|
|
230
|
+
}
|
|
231
|
+
if (condition.includes('<')) {
|
|
232
|
+
const [left, right] = condition.split('<').map(s => s.trim());
|
|
233
|
+
return getNestedValue(evalContext, left) < parseValue(right);
|
|
234
|
+
}
|
|
235
|
+
// Boolean check
|
|
236
|
+
return !!getNestedValue(evalContext, condition);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function getNestedValue(obj, path) {
|
|
243
|
+
return path.split('.').reduce((current, key) => current?.[key], obj);
|
|
244
|
+
}
|
|
245
|
+
function parseValue(value) {
|
|
246
|
+
value = value.trim();
|
|
247
|
+
if (value === 'true')
|
|
248
|
+
return true;
|
|
249
|
+
if (value === 'false')
|
|
250
|
+
return false;
|
|
251
|
+
if (value === 'null')
|
|
252
|
+
return null;
|
|
253
|
+
if (value.startsWith('"') && value.endsWith('"'))
|
|
254
|
+
return value.slice(1, -1);
|
|
255
|
+
if (value.startsWith("'") && value.endsWith("'"))
|
|
256
|
+
return value.slice(1, -1);
|
|
257
|
+
const num = Number(value);
|
|
258
|
+
if (!isNaN(num))
|
|
259
|
+
return num;
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Load workflow from YAML file
|
|
264
|
+
*/
|
|
265
|
+
async function loadWorkflowFromFile(filePath, agents = {}, tools = {}) {
|
|
266
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
267
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
268
|
+
const definition = parseYAMLWorkflow(content);
|
|
269
|
+
return createWorkflowFromYAML(definition, agents, tools);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Validate YAML workflow definition
|
|
273
|
+
*/
|
|
274
|
+
function validateWorkflowDefinition(definition) {
|
|
275
|
+
const errors = [];
|
|
276
|
+
if (!definition.name) {
|
|
277
|
+
errors.push('Workflow must have a name');
|
|
278
|
+
}
|
|
279
|
+
if (!definition.steps || definition.steps.length === 0) {
|
|
280
|
+
errors.push('Workflow must have at least one step');
|
|
281
|
+
}
|
|
282
|
+
const stepNames = new Set();
|
|
283
|
+
for (const step of definition.steps) {
|
|
284
|
+
if (!step.name) {
|
|
285
|
+
errors.push('Each step must have a name');
|
|
286
|
+
}
|
|
287
|
+
else if (stepNames.has(step.name)) {
|
|
288
|
+
errors.push(`Duplicate step name: ${step.name}`);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
stepNames.add(step.name);
|
|
292
|
+
}
|
|
293
|
+
if (!step.type) {
|
|
294
|
+
errors.push(`Step ${step.name}: must have a type`);
|
|
295
|
+
}
|
|
296
|
+
if (step.type === 'agent' && !step.agent) {
|
|
297
|
+
errors.push(`Step ${step.name}: agent type requires 'agent' field`);
|
|
298
|
+
}
|
|
299
|
+
if (step.type === 'tool' && !step.tool) {
|
|
300
|
+
errors.push(`Step ${step.name}: tool type requires 'tool' field`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return errors;
|
|
304
|
+
}
|