praisonai 1.2.0 → 1.2.1

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/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from './knowledge';
3
3
  export * from './llm';
4
4
  export * from './memory';
5
5
  export * from './process';
6
- export { Tool, BaseTool, FunctionTool, tool, ToolRegistry, getRegistry, registerTool, getTool, type ToolConfig, type ToolContext, type ToolParameters } from './tools';
6
+ export { BaseTool, ToolResult, ToolValidationError, validateTool, createTool, FunctionTool, tool, ToolRegistry, getRegistry, registerTool, getTool, type ToolConfig, type ToolContext, type ToolParameters } from './tools';
7
7
  export * from './tools/arxivTools';
8
8
  export * from './tools/mcpSse';
9
9
  export * from './session';
package/dist/index.js CHANGED
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Chunking = exports.createPromptExpanderAgent = exports.PromptExpanderAgent = exports.createQueryRewriterAgent = exports.QueryRewriterAgent = exports.createDeepResearchAgent = exports.DeepResearchAgent = exports.createImageAgent = exports.ImageAgent = exports.createAutoAgents = exports.AutoAgents = exports.cleanupTelemetry = exports.disableTelemetry = exports.enableTelemetry = exports.getTelemetry = exports.TelemetryCollector = exports.createMemory = exports.Memory = exports.help = exports.version = exports.listProviders = exports.chat = exports.parseSkillFile = exports.createSkillManager = exports.SkillManager = exports.getObservabilityAdapter = exports.setObservabilityAdapter = exports.ConsoleObservabilityAdapter = exports.MemoryObservabilityAdapter = exports.EvalSuite = exports.reliabilityEval = exports.performanceEval = exports.accuracyEval = exports.createKnowledgeBase = exports.KnowledgeBase = exports.createContextAgent = exports.ContextAgent = exports.routeConditions = exports.createRouter = exports.RouterAgent = exports.handoffFilters = exports.handoff = exports.Handoff = exports.getTool = exports.registerTool = exports.getRegistry = exports.ToolRegistry = exports.tool = exports.FunctionTool = exports.BaseTool = void 0;
18
- exports.BaseProvider = exports.GoogleProvider = exports.AnthropicProvider = exports.OpenAIProvider = exports.getAvailableProviders = exports.isProviderAvailable = exports.parseModelString = exports.getDefaultProvider = exports.createProvider = exports.createPlanStorage = exports.createTodoList = exports.createPlan = exports.PlanStorage = exports.TodoItem = exports.TodoList = exports.PlanStep = exports.Plan = exports.createLLMGuardrail = exports.LLMGuardrail = exports.createChunking = void 0;
17
+ exports.createQueryRewriterAgent = exports.QueryRewriterAgent = exports.createDeepResearchAgent = exports.DeepResearchAgent = exports.createImageAgent = exports.ImageAgent = exports.createAutoAgents = exports.AutoAgents = exports.cleanupTelemetry = exports.disableTelemetry = exports.enableTelemetry = exports.getTelemetry = exports.TelemetryCollector = exports.createMemory = exports.Memory = exports.help = exports.version = exports.listProviders = exports.chat = exports.parseSkillFile = exports.createSkillManager = exports.SkillManager = exports.getObservabilityAdapter = exports.setObservabilityAdapter = exports.ConsoleObservabilityAdapter = exports.MemoryObservabilityAdapter = exports.EvalSuite = exports.reliabilityEval = exports.performanceEval = exports.accuracyEval = exports.createKnowledgeBase = exports.KnowledgeBase = exports.createContextAgent = exports.ContextAgent = exports.routeConditions = exports.createRouter = exports.RouterAgent = exports.handoffFilters = exports.handoff = exports.Handoff = exports.getTool = exports.registerTool = exports.getRegistry = exports.ToolRegistry = exports.tool = exports.FunctionTool = exports.createTool = exports.validateTool = exports.ToolValidationError = exports.BaseTool = void 0;
18
+ exports.BaseProvider = exports.GoogleProvider = exports.AnthropicProvider = exports.OpenAIProvider = exports.getAvailableProviders = exports.isProviderAvailable = exports.parseModelString = exports.getDefaultProvider = exports.createProvider = exports.createPlanStorage = exports.createTodoList = exports.createPlan = exports.PlanStorage = exports.TodoItem = exports.TodoList = exports.PlanStep = exports.Plan = exports.createLLMGuardrail = exports.LLMGuardrail = exports.createChunking = exports.Chunking = exports.createPromptExpanderAgent = exports.PromptExpanderAgent = void 0;
19
19
  // Export all public modules
20
20
  __exportStar(require("./agent"), exports);
21
21
  __exportStar(require("./knowledge"), exports);
@@ -25,6 +25,9 @@ __exportStar(require("./process"), exports);
25
25
  // Export tools (excluding conflicting types)
26
26
  var tools_1 = require("./tools");
27
27
  Object.defineProperty(exports, "BaseTool", { enumerable: true, get: function () { return tools_1.BaseTool; } });
28
+ Object.defineProperty(exports, "ToolValidationError", { enumerable: true, get: function () { return tools_1.ToolValidationError; } });
29
+ Object.defineProperty(exports, "validateTool", { enumerable: true, get: function () { return tools_1.validateTool; } });
30
+ Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return tools_1.createTool; } });
28
31
  Object.defineProperty(exports, "FunctionTool", { enumerable: true, get: function () { return tools_1.FunctionTool; } });
29
32
  Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return tools_1.tool; } });
30
33
  Object.defineProperty(exports, "ToolRegistry", { enumerable: true, get: function () { return tools_1.ToolRegistry; } });
@@ -1,4 +1,4 @@
1
- import { BaseTool } from './index';
1
+ import { BaseTool } from './base';
2
2
  export interface ArxivPaper {
3
3
  id: string;
4
4
  title: string;
@@ -8,12 +8,25 @@ export interface ArxivPaper {
8
8
  updated: string;
9
9
  link: string;
10
10
  }
11
- export declare class ArxivSearchTool extends BaseTool {
11
+ export declare class ArxivSearchTool extends BaseTool<{
12
+ query: string;
13
+ maxResults?: number;
14
+ }, ArxivPaper[]> {
15
+ name: string;
16
+ description: string;
12
17
  private parser;
13
18
  constructor();
14
- execute(query: string, maxResults?: number): Promise<ArxivPaper[]>;
19
+ run(params: {
20
+ query: string;
21
+ maxResults?: number;
22
+ }): Promise<ArxivPaper[]>;
15
23
  }
16
- export declare class ArxivDownloadTool extends BaseTool {
17
- constructor();
18
- execute(paperId: string): Promise<Buffer>;
24
+ export declare class ArxivDownloadTool extends BaseTool<{
25
+ paperId: string;
26
+ }, Buffer> {
27
+ name: string;
28
+ description: string;
29
+ run(params: {
30
+ paperId: string;
31
+ }): Promise<Buffer>;
19
32
  }
@@ -5,17 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ArxivDownloadTool = exports.ArxivSearchTool = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- const index_1 = require("./index");
9
8
  const fast_xml_parser_1 = require("fast-xml-parser");
10
- class ArxivSearchTool extends index_1.BaseTool {
9
+ const base_1 = require("./base");
10
+ class ArxivSearchTool extends base_1.BaseTool {
11
11
  constructor() {
12
- super('arxiv-search', 'Search for academic papers on arXiv');
12
+ super();
13
+ this.name = 'arxiv-search';
14
+ this.description = 'Search for academic papers on arXiv';
13
15
  this.parser = new fast_xml_parser_1.XMLParser({
14
16
  ignoreAttributes: false,
15
17
  attributeNamePrefix: '@_'
16
18
  });
17
19
  }
18
- async execute(query, maxResults = 10) {
20
+ async run(params) {
21
+ const { query, maxResults = 10 } = params;
19
22
  try {
20
23
  const response = await axios_1.default.get(`http://export.arxiv.org/api/query`, {
21
24
  params: {
@@ -53,11 +56,14 @@ class ArxivSearchTool extends index_1.BaseTool {
53
56
  }
54
57
  }
55
58
  exports.ArxivSearchTool = ArxivSearchTool;
56
- class ArxivDownloadTool extends index_1.BaseTool {
59
+ class ArxivDownloadTool extends base_1.BaseTool {
57
60
  constructor() {
58
- super('arxiv-download', 'Download PDF of an arXiv paper');
61
+ super(...arguments);
62
+ this.name = 'arxiv-download';
63
+ this.description = 'Download PDF of an arXiv paper';
59
64
  }
60
- async execute(paperId) {
65
+ async run(params) {
66
+ const { paperId } = params;
61
67
  try {
62
68
  const response = await axios_1.default.get(`https://arxiv.org/pdf/${paperId}.pdf`, {
63
69
  responseType: 'arraybuffer'
@@ -0,0 +1,97 @@
1
+ /**
2
+ * BaseTool - Abstract base class for creating custom tools (plugins)
3
+ *
4
+ * This provides the same extensibility pattern as Python's BaseTool.
5
+ * External developers can create plugins by extending BaseTool.
6
+ *
7
+ * Usage:
8
+ * import { BaseTool } from 'praisonai';
9
+ *
10
+ * class MyTool extends BaseTool {
11
+ * name = 'my_tool';
12
+ * description = 'Does something useful';
13
+ *
14
+ * async run(params: { query: string }): Promise<string> {
15
+ * return `Result for ${params.query}`;
16
+ * }
17
+ * }
18
+ */
19
+ export interface ToolResult<T = any> {
20
+ output: T;
21
+ success: boolean;
22
+ error?: string;
23
+ metadata?: Record<string, any>;
24
+ }
25
+ export declare class ToolValidationError extends Error {
26
+ constructor(message: string);
27
+ }
28
+ export interface ToolParameters {
29
+ type: 'object';
30
+ properties: Record<string, {
31
+ type: string;
32
+ description?: string;
33
+ enum?: string[];
34
+ default?: any;
35
+ }>;
36
+ required?: string[];
37
+ }
38
+ /**
39
+ * Abstract base class for all PraisonAI tools.
40
+ *
41
+ * Subclass this to create custom tools that can be:
42
+ * - Used directly by agents
43
+ * - Distributed as npm packages (plugins)
44
+ * - Auto-discovered via package.json
45
+ */
46
+ export declare abstract class BaseTool<TParams = any, TResult = any> {
47
+ /** Unique identifier for the tool */
48
+ abstract name: string;
49
+ /** Human-readable description (used by LLM) */
50
+ abstract description: string;
51
+ /** Tool version string */
52
+ version: string;
53
+ /** JSON Schema for parameters */
54
+ parameters?: ToolParameters;
55
+ /**
56
+ * Execute the tool with given arguments.
57
+ * This method must be implemented by subclasses.
58
+ */
59
+ abstract run(params: TParams): Promise<TResult> | TResult;
60
+ /**
61
+ * Allow tool to be called directly like a function.
62
+ */
63
+ execute(params: TParams): Promise<TResult>;
64
+ /**
65
+ * Execute tool with error handling, returning ToolResult.
66
+ */
67
+ safeRun(params: TParams): Promise<ToolResult<TResult>>;
68
+ /**
69
+ * Get OpenAI-compatible function schema for this tool.
70
+ */
71
+ getSchema(): {
72
+ type: 'function';
73
+ function: {
74
+ name: string;
75
+ description: string;
76
+ parameters: any;
77
+ };
78
+ };
79
+ /**
80
+ * Validate the tool configuration.
81
+ */
82
+ validate(): boolean;
83
+ toString(): string;
84
+ }
85
+ /**
86
+ * Validate any tool-like object.
87
+ */
88
+ export declare function validateTool(tool: any): boolean;
89
+ /**
90
+ * Create a simple tool from a function (alternative to class-based approach)
91
+ */
92
+ export declare function createTool<TParams = any, TResult = any>(config: {
93
+ name: string;
94
+ description: string;
95
+ parameters?: ToolParameters;
96
+ run: (params: TParams) => Promise<TResult> | TResult;
97
+ }): BaseTool<TParams, TResult>;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /**
3
+ * BaseTool - Abstract base class for creating custom tools (plugins)
4
+ *
5
+ * This provides the same extensibility pattern as Python's BaseTool.
6
+ * External developers can create plugins by extending BaseTool.
7
+ *
8
+ * Usage:
9
+ * import { BaseTool } from 'praisonai';
10
+ *
11
+ * class MyTool extends BaseTool {
12
+ * name = 'my_tool';
13
+ * description = 'Does something useful';
14
+ *
15
+ * async run(params: { query: string }): Promise<string> {
16
+ * return `Result for ${params.query}`;
17
+ * }
18
+ * }
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.BaseTool = exports.ToolValidationError = void 0;
22
+ exports.validateTool = validateTool;
23
+ exports.createTool = createTool;
24
+ class ToolValidationError extends Error {
25
+ constructor(message) {
26
+ super(message);
27
+ this.name = 'ToolValidationError';
28
+ }
29
+ }
30
+ exports.ToolValidationError = ToolValidationError;
31
+ /**
32
+ * Abstract base class for all PraisonAI tools.
33
+ *
34
+ * Subclass this to create custom tools that can be:
35
+ * - Used directly by agents
36
+ * - Distributed as npm packages (plugins)
37
+ * - Auto-discovered via package.json
38
+ */
39
+ class BaseTool {
40
+ constructor() {
41
+ /** Tool version string */
42
+ this.version = '1.0.0';
43
+ }
44
+ /**
45
+ * Allow tool to be called directly like a function.
46
+ */
47
+ async execute(params) {
48
+ return this.run(params);
49
+ }
50
+ /**
51
+ * Execute tool with error handling, returning ToolResult.
52
+ */
53
+ async safeRun(params) {
54
+ try {
55
+ const output = await this.run(params);
56
+ return { output, success: true };
57
+ }
58
+ catch (error) {
59
+ return {
60
+ output: null,
61
+ success: false,
62
+ error: error.message
63
+ };
64
+ }
65
+ }
66
+ /**
67
+ * Get OpenAI-compatible function schema for this tool.
68
+ */
69
+ getSchema() {
70
+ return {
71
+ type: 'function',
72
+ function: {
73
+ name: this.name,
74
+ description: this.description,
75
+ parameters: this.parameters || { type: 'object', properties: {}, required: [] }
76
+ }
77
+ };
78
+ }
79
+ /**
80
+ * Validate the tool configuration.
81
+ */
82
+ validate() {
83
+ const errors = [];
84
+ if (!this.name || typeof this.name !== 'string') {
85
+ errors.push("Tool must have a non-empty string 'name'");
86
+ }
87
+ if (!this.description || typeof this.description !== 'string') {
88
+ errors.push("Tool must have a non-empty string 'description'");
89
+ }
90
+ if (errors.length > 0) {
91
+ throw new ToolValidationError(`Tool '${this.name}' validation failed: ${errors.join('; ')}`);
92
+ }
93
+ return true;
94
+ }
95
+ toString() {
96
+ return `${this.constructor.name}(name='${this.name}')`;
97
+ }
98
+ }
99
+ exports.BaseTool = BaseTool;
100
+ /**
101
+ * Validate any tool-like object.
102
+ */
103
+ function validateTool(tool) {
104
+ if (tool instanceof BaseTool) {
105
+ return tool.validate();
106
+ }
107
+ if (typeof tool === 'function' || (tool && typeof tool.run === 'function')) {
108
+ const name = tool.name || tool.__name__;
109
+ if (!name) {
110
+ throw new ToolValidationError('Tool must have a name');
111
+ }
112
+ return true;
113
+ }
114
+ throw new ToolValidationError(`Invalid tool type: ${typeof tool}`);
115
+ }
116
+ /**
117
+ * Create a simple tool from a function (alternative to class-based approach)
118
+ */
119
+ function createTool(config) {
120
+ return {
121
+ name: config.name,
122
+ description: config.description,
123
+ version: '1.0.0',
124
+ parameters: config.parameters,
125
+ run: config.run,
126
+ execute: async (params) => config.run(params),
127
+ safeRun: async (params) => {
128
+ try {
129
+ const output = await config.run(params);
130
+ return { output, success: true };
131
+ }
132
+ catch (error) {
133
+ return { output: null, success: false, error: error.message };
134
+ }
135
+ },
136
+ getSchema: () => ({
137
+ type: 'function',
138
+ function: {
139
+ name: config.name,
140
+ description: config.description,
141
+ parameters: config.parameters || { type: 'object', properties: {}, required: [] }
142
+ }
143
+ }),
144
+ validate: () => true,
145
+ toString: () => `Tool(name='${config.name}')`
146
+ };
147
+ }
@@ -1,14 +1,4 @@
1
- export interface Tool {
2
- name: string;
3
- description: string;
4
- execute(...args: any[]): Promise<any>;
5
- }
6
- export declare class BaseTool implements Tool {
7
- name: string;
8
- description: string;
9
- constructor(name: string, description: string);
10
- execute(...args: any[]): Promise<any>;
11
- }
1
+ export { BaseTool, ToolResult, ToolValidationError, validateTool, createTool, type ToolParameters } from './base';
12
2
  export * from './decorator';
13
3
  export * from './arxivTools';
14
4
  export * from './mcpSse';
@@ -14,17 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BaseTool = void 0;
18
- class BaseTool {
19
- constructor(name, description) {
20
- this.name = name;
21
- this.description = description;
22
- }
23
- async execute(...args) {
24
- throw new Error('Method not implemented.');
25
- }
26
- }
27
- exports.BaseTool = BaseTool;
17
+ exports.createTool = exports.validateTool = exports.ToolValidationError = exports.BaseTool = void 0;
18
+ // Export base tool interfaces and classes
19
+ var base_1 = require("./base");
20
+ Object.defineProperty(exports, "BaseTool", { enumerable: true, get: function () { return base_1.BaseTool; } });
21
+ Object.defineProperty(exports, "ToolValidationError", { enumerable: true, get: function () { return base_1.ToolValidationError; } });
22
+ Object.defineProperty(exports, "validateTool", { enumerable: true, get: function () { return base_1.validateTool; } });
23
+ Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return base_1.createTool; } });
28
24
  // Export decorator and registry
29
25
  __exportStar(require("./decorator"), exports);
30
26
  // Export all tool modules
@@ -1,16 +1,18 @@
1
1
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import { BaseTool } from './index';
2
+ import { BaseTool } from './base';
3
3
  export interface MCPToolInfo {
4
4
  name: string;
5
5
  description?: string;
6
6
  inputSchema?: any;
7
7
  }
8
- export declare class MCPTool extends BaseTool {
8
+ export declare class MCPTool extends BaseTool<any, any> {
9
+ name: string;
10
+ description: string;
9
11
  private client;
10
12
  private inputSchema;
11
13
  constructor(info: MCPToolInfo, client: Client);
12
14
  get schemaProperties(): Record<string, any> | undefined;
13
- execute(args?: any): Promise<any>;
15
+ run(args?: any): Promise<any>;
14
16
  toOpenAITool(): {
15
17
  type: string;
16
18
  function: {
@@ -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 index_1 = require("./index");
7
- class MCPTool extends index_1.BaseTool {
6
+ const base_1 = require("./base");
7
+ class MCPTool extends base_1.BaseTool {
8
8
  constructor(info, client) {
9
- super(info.name, info.description || `Call the ${info.name} tool`);
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 execute(args = {}) {
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praisonai",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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",