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,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Skills System - Agent Skills standard implementation
|
|
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.SkillManager = void 0;
|
|
40
|
+
exports.parseSkillFile = parseSkillFile;
|
|
41
|
+
exports.createSkillManager = createSkillManager;
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
/**
|
|
45
|
+
* Parse SKILL.md file
|
|
46
|
+
*/
|
|
47
|
+
function parseSkillFile(content) {
|
|
48
|
+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
49
|
+
if (!frontmatterMatch) {
|
|
50
|
+
throw new Error('Invalid SKILL.md format: missing frontmatter');
|
|
51
|
+
}
|
|
52
|
+
const [, frontmatter, instructions] = frontmatterMatch;
|
|
53
|
+
const metadata = parseYamlFrontmatter(frontmatter);
|
|
54
|
+
if (!metadata.name || !metadata.description) {
|
|
55
|
+
throw new Error('Invalid SKILL.md: name and description are required');
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
metadata: {
|
|
59
|
+
name: metadata.name,
|
|
60
|
+
description: metadata.description,
|
|
61
|
+
license: metadata.license,
|
|
62
|
+
compatibility: metadata.compatibility,
|
|
63
|
+
allowedTools: metadata['allowed-tools']?.split(/\s+/),
|
|
64
|
+
metadata: metadata.metadata
|
|
65
|
+
},
|
|
66
|
+
instructions: instructions.trim()
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Simple YAML frontmatter parser
|
|
71
|
+
*/
|
|
72
|
+
function parseYamlFrontmatter(yaml) {
|
|
73
|
+
const result = {};
|
|
74
|
+
const lines = yaml.split('\n');
|
|
75
|
+
let currentKey = '';
|
|
76
|
+
let inMetadata = false;
|
|
77
|
+
const metadataObj = {};
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
if (line.startsWith('metadata:')) {
|
|
80
|
+
inMetadata = true;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (inMetadata && line.startsWith(' ')) {
|
|
84
|
+
const match = line.match(/^\s+(\w+):\s*(.*)$/);
|
|
85
|
+
if (match) {
|
|
86
|
+
metadataObj[match[1]] = match[2].replace(/^["']|["']$/g, '');
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
else if (inMetadata && !line.startsWith(' ')) {
|
|
91
|
+
inMetadata = false;
|
|
92
|
+
result.metadata = metadataObj;
|
|
93
|
+
}
|
|
94
|
+
const match = line.match(/^(\S+):\s*(.*)$/);
|
|
95
|
+
if (match) {
|
|
96
|
+
currentKey = match[1];
|
|
97
|
+
result[currentKey] = match[2].replace(/^["']|["']$/g, '');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (inMetadata) {
|
|
101
|
+
result.metadata = metadataObj;
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Skill Manager - Load and manage skills
|
|
107
|
+
*/
|
|
108
|
+
class SkillManager {
|
|
109
|
+
constructor(options = {}) {
|
|
110
|
+
this.skills = new Map();
|
|
111
|
+
this.discoveryPaths = [];
|
|
112
|
+
this.setupDiscoveryPaths(options);
|
|
113
|
+
}
|
|
114
|
+
setupDiscoveryPaths(options) {
|
|
115
|
+
if (options.paths) {
|
|
116
|
+
this.discoveryPaths.push(...options.paths);
|
|
117
|
+
}
|
|
118
|
+
if (options.includeProject !== false) {
|
|
119
|
+
this.discoveryPaths.push('./.praison/skills');
|
|
120
|
+
this.discoveryPaths.push('./.claude/skills');
|
|
121
|
+
}
|
|
122
|
+
if (options.includeUser !== false) {
|
|
123
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
124
|
+
if (home) {
|
|
125
|
+
this.discoveryPaths.push(path.join(home, '.praison/skills'));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (options.includeSystem) {
|
|
129
|
+
this.discoveryPaths.push('/etc/praison/skills');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Discover and load skills from configured paths
|
|
134
|
+
*/
|
|
135
|
+
async discover() {
|
|
136
|
+
const discovered = [];
|
|
137
|
+
for (const basePath of this.discoveryPaths) {
|
|
138
|
+
if (!fs.existsSync(basePath))
|
|
139
|
+
continue;
|
|
140
|
+
const entries = fs.readdirSync(basePath, { withFileTypes: true });
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
if (entry.isDirectory()) {
|
|
143
|
+
const skillPath = path.join(basePath, entry.name, 'SKILL.md');
|
|
144
|
+
if (fs.existsSync(skillPath)) {
|
|
145
|
+
try {
|
|
146
|
+
const skill = await this.loadSkill(skillPath);
|
|
147
|
+
skill.path = path.join(basePath, entry.name);
|
|
148
|
+
discovered.push(skill);
|
|
149
|
+
this.skills.set(skill.metadata.name, skill);
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
// Skip invalid skills
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return discovered;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Load a skill from a SKILL.md file
|
|
162
|
+
*/
|
|
163
|
+
async loadSkill(skillPath) {
|
|
164
|
+
const content = fs.readFileSync(skillPath, 'utf-8');
|
|
165
|
+
return parseSkillFile(content);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Register a skill manually
|
|
169
|
+
*/
|
|
170
|
+
register(skill) {
|
|
171
|
+
this.skills.set(skill.metadata.name, skill);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get a skill by name
|
|
175
|
+
*/
|
|
176
|
+
get(name) {
|
|
177
|
+
return this.skills.get(name);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* List all loaded skills
|
|
181
|
+
*/
|
|
182
|
+
list() {
|
|
183
|
+
return Array.from(this.skills.values());
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Generate XML prompt for skills
|
|
187
|
+
*/
|
|
188
|
+
generatePrompt(skillNames) {
|
|
189
|
+
const skillsToInclude = skillNames
|
|
190
|
+
? skillNames.map(n => this.skills.get(n)).filter(Boolean)
|
|
191
|
+
: this.list();
|
|
192
|
+
if (skillsToInclude.length === 0)
|
|
193
|
+
return '';
|
|
194
|
+
const parts = ['<skills>'];
|
|
195
|
+
for (const skill of skillsToInclude) {
|
|
196
|
+
parts.push(` <skill name="${skill.metadata.name}">`);
|
|
197
|
+
parts.push(` <description>${skill.metadata.description}</description>`);
|
|
198
|
+
parts.push(` <instructions>${skill.instructions}</instructions>`);
|
|
199
|
+
parts.push(' </skill>');
|
|
200
|
+
}
|
|
201
|
+
parts.push('</skills>');
|
|
202
|
+
return parts.join('\n');
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Validate a skill
|
|
206
|
+
*/
|
|
207
|
+
validate(skill) {
|
|
208
|
+
const errors = [];
|
|
209
|
+
if (!skill.metadata.name) {
|
|
210
|
+
errors.push('Missing required field: name');
|
|
211
|
+
}
|
|
212
|
+
else if (!/^[a-z0-9-]{1,64}$/.test(skill.metadata.name)) {
|
|
213
|
+
errors.push('Invalid name: must be 1-64 lowercase chars, numbers, or hyphens');
|
|
214
|
+
}
|
|
215
|
+
if (!skill.metadata.description) {
|
|
216
|
+
errors.push('Missing required field: description');
|
|
217
|
+
}
|
|
218
|
+
else if (skill.metadata.description.length > 1024) {
|
|
219
|
+
errors.push('Description too long: max 1024 characters');
|
|
220
|
+
}
|
|
221
|
+
if (skill.instructions.length > 5000) {
|
|
222
|
+
errors.push('Instructions too long: max 5000 characters');
|
|
223
|
+
}
|
|
224
|
+
return { valid: errors.length === 0, errors };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.SkillManager = SkillManager;
|
|
228
|
+
/**
|
|
229
|
+
* Create a skill manager
|
|
230
|
+
*/
|
|
231
|
+
function createSkillManager(options) {
|
|
232
|
+
return new SkillManager(options);
|
|
233
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry - Usage tracking and analytics
|
|
3
|
+
*/
|
|
4
|
+
export interface TelemetryEvent {
|
|
5
|
+
name: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
userId?: string;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TelemetryConfig {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
flushInterval?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Telemetry collector for tracking usage
|
|
19
|
+
*/
|
|
20
|
+
export declare class TelemetryCollector {
|
|
21
|
+
private events;
|
|
22
|
+
private enabled;
|
|
23
|
+
private endpoint?;
|
|
24
|
+
private batchSize;
|
|
25
|
+
private flushInterval;
|
|
26
|
+
private flushTimer?;
|
|
27
|
+
private userId?;
|
|
28
|
+
private sessionId;
|
|
29
|
+
constructor(config?: TelemetryConfig);
|
|
30
|
+
private checkEnabled;
|
|
31
|
+
/**
|
|
32
|
+
* Track an event
|
|
33
|
+
*/
|
|
34
|
+
track(name: string, properties?: Record<string, any>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Track feature usage
|
|
37
|
+
*/
|
|
38
|
+
trackFeatureUsage(feature: string, metadata?: Record<string, any>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Track agent execution
|
|
41
|
+
*/
|
|
42
|
+
trackAgentExecution(agentName: string, duration: number, success: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Track tool call
|
|
45
|
+
*/
|
|
46
|
+
trackToolCall(toolName: string, duration: number, success: boolean): void;
|
|
47
|
+
/**
|
|
48
|
+
* Track LLM call
|
|
49
|
+
*/
|
|
50
|
+
trackLLMCall(provider: string, model: string, tokens: number, duration: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Track error
|
|
53
|
+
*/
|
|
54
|
+
trackError(error: string, context?: Record<string, any>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set user ID
|
|
57
|
+
*/
|
|
58
|
+
setUserId(userId: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Flush events
|
|
61
|
+
*/
|
|
62
|
+
flush(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Enable telemetry
|
|
65
|
+
*/
|
|
66
|
+
enable(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Disable telemetry
|
|
69
|
+
*/
|
|
70
|
+
disable(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Check if telemetry is enabled
|
|
73
|
+
*/
|
|
74
|
+
isEnabled(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get pending events count
|
|
77
|
+
*/
|
|
78
|
+
getPendingCount(): number;
|
|
79
|
+
/**
|
|
80
|
+
* Cleanup resources
|
|
81
|
+
*/
|
|
82
|
+
cleanup(): void;
|
|
83
|
+
private startFlushTimer;
|
|
84
|
+
private stopFlushTimer;
|
|
85
|
+
private generateSessionId;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get global telemetry instance
|
|
89
|
+
*/
|
|
90
|
+
export declare function getTelemetry(): TelemetryCollector;
|
|
91
|
+
/**
|
|
92
|
+
* Enable telemetry
|
|
93
|
+
*/
|
|
94
|
+
export declare function enableTelemetry(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Disable telemetry
|
|
97
|
+
*/
|
|
98
|
+
export declare function disableTelemetry(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Cleanup telemetry resources
|
|
101
|
+
*/
|
|
102
|
+
export declare function cleanupTelemetry(): void;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry - Usage tracking and analytics
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TelemetryCollector = void 0;
|
|
7
|
+
exports.getTelemetry = getTelemetry;
|
|
8
|
+
exports.enableTelemetry = enableTelemetry;
|
|
9
|
+
exports.disableTelemetry = disableTelemetry;
|
|
10
|
+
exports.cleanupTelemetry = cleanupTelemetry;
|
|
11
|
+
/**
|
|
12
|
+
* Telemetry collector for tracking usage
|
|
13
|
+
*/
|
|
14
|
+
class TelemetryCollector {
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
this.events = [];
|
|
17
|
+
this.enabled = config.enabled ?? this.checkEnabled();
|
|
18
|
+
this.endpoint = config.endpoint;
|
|
19
|
+
this.batchSize = config.batchSize ?? 100;
|
|
20
|
+
this.flushInterval = config.flushInterval ?? 60000;
|
|
21
|
+
this.sessionId = this.generateSessionId();
|
|
22
|
+
if (this.enabled && this.flushInterval > 0) {
|
|
23
|
+
this.startFlushTimer();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
checkEnabled() {
|
|
27
|
+
const disabled = process.env.PRAISONAI_TELEMETRY_DISABLED === 'true' ||
|
|
28
|
+
process.env.PRAISONAI_DISABLE_TELEMETRY === 'true' ||
|
|
29
|
+
process.env.DO_NOT_TRACK === 'true';
|
|
30
|
+
return !disabled;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Track an event
|
|
34
|
+
*/
|
|
35
|
+
track(name, properties) {
|
|
36
|
+
if (!this.enabled)
|
|
37
|
+
return;
|
|
38
|
+
const event = {
|
|
39
|
+
name,
|
|
40
|
+
timestamp: Date.now(),
|
|
41
|
+
properties,
|
|
42
|
+
userId: this.userId,
|
|
43
|
+
sessionId: this.sessionId
|
|
44
|
+
};
|
|
45
|
+
this.events.push(event);
|
|
46
|
+
if (this.events.length >= this.batchSize) {
|
|
47
|
+
this.flush();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Track feature usage
|
|
52
|
+
*/
|
|
53
|
+
trackFeatureUsage(feature, metadata) {
|
|
54
|
+
this.track('feature_usage', { feature, ...metadata });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Track agent execution
|
|
58
|
+
*/
|
|
59
|
+
trackAgentExecution(agentName, duration, success) {
|
|
60
|
+
this.track('agent_execution', { agentName, duration, success });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Track tool call
|
|
64
|
+
*/
|
|
65
|
+
trackToolCall(toolName, duration, success) {
|
|
66
|
+
this.track('tool_call', { toolName, duration, success });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Track LLM call
|
|
70
|
+
*/
|
|
71
|
+
trackLLMCall(provider, model, tokens, duration) {
|
|
72
|
+
this.track('llm_call', { provider, model, tokens, duration });
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Track error
|
|
76
|
+
*/
|
|
77
|
+
trackError(error, context) {
|
|
78
|
+
this.track('error', { error, ...context });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set user ID
|
|
82
|
+
*/
|
|
83
|
+
setUserId(userId) {
|
|
84
|
+
this.userId = userId;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Flush events
|
|
88
|
+
*/
|
|
89
|
+
async flush() {
|
|
90
|
+
if (this.events.length === 0)
|
|
91
|
+
return;
|
|
92
|
+
const eventsToSend = [...this.events];
|
|
93
|
+
this.events = [];
|
|
94
|
+
if (this.endpoint) {
|
|
95
|
+
try {
|
|
96
|
+
await fetch(this.endpoint, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json' },
|
|
99
|
+
body: JSON.stringify({ events: eventsToSend })
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// Silently fail - never break user applications
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Enable telemetry
|
|
109
|
+
*/
|
|
110
|
+
enable() {
|
|
111
|
+
this.enabled = true;
|
|
112
|
+
this.startFlushTimer();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Disable telemetry
|
|
116
|
+
*/
|
|
117
|
+
disable() {
|
|
118
|
+
this.enabled = false;
|
|
119
|
+
this.stopFlushTimer();
|
|
120
|
+
this.events = [];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if telemetry is enabled
|
|
124
|
+
*/
|
|
125
|
+
isEnabled() {
|
|
126
|
+
return this.enabled;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get pending events count
|
|
130
|
+
*/
|
|
131
|
+
getPendingCount() {
|
|
132
|
+
return this.events.length;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Cleanup resources
|
|
136
|
+
*/
|
|
137
|
+
cleanup() {
|
|
138
|
+
this.stopFlushTimer();
|
|
139
|
+
this.flush();
|
|
140
|
+
}
|
|
141
|
+
startFlushTimer() {
|
|
142
|
+
if (this.flushTimer)
|
|
143
|
+
return;
|
|
144
|
+
this.flushTimer = setInterval(() => this.flush(), this.flushInterval);
|
|
145
|
+
}
|
|
146
|
+
stopFlushTimer() {
|
|
147
|
+
if (this.flushTimer) {
|
|
148
|
+
clearInterval(this.flushTimer);
|
|
149
|
+
this.flushTimer = undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
generateSessionId() {
|
|
153
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.TelemetryCollector = TelemetryCollector;
|
|
157
|
+
// Global telemetry instance
|
|
158
|
+
let globalTelemetry = null;
|
|
159
|
+
/**
|
|
160
|
+
* Get global telemetry instance
|
|
161
|
+
*/
|
|
162
|
+
function getTelemetry() {
|
|
163
|
+
if (!globalTelemetry) {
|
|
164
|
+
globalTelemetry = new TelemetryCollector();
|
|
165
|
+
}
|
|
166
|
+
return globalTelemetry;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Enable telemetry
|
|
170
|
+
*/
|
|
171
|
+
function enableTelemetry() {
|
|
172
|
+
getTelemetry().enable();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Disable telemetry
|
|
176
|
+
*/
|
|
177
|
+
function disableTelemetry() {
|
|
178
|
+
getTelemetry().disable();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Cleanup telemetry resources
|
|
182
|
+
*/
|
|
183
|
+
function cleanupTelemetry() {
|
|
184
|
+
if (globalTelemetry) {
|
|
185
|
+
globalTelemetry.cleanup();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Decorator and Registry - Type-safe tool creation and management
|
|
3
|
+
*/
|
|
4
|
+
export interface ToolParameters {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, {
|
|
7
|
+
type: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
enum?: string[];
|
|
10
|
+
default?: any;
|
|
11
|
+
}>;
|
|
12
|
+
required?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface ToolConfig<TParams = any, TResult = any> {
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
parameters?: ToolParameters | any;
|
|
18
|
+
category?: string;
|
|
19
|
+
execute: (params: TParams, context?: ToolContext) => Promise<TResult> | TResult;
|
|
20
|
+
}
|
|
21
|
+
export interface ToolContext {
|
|
22
|
+
agentName?: string;
|
|
23
|
+
sessionId?: string;
|
|
24
|
+
runId?: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
export interface ToolDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
parameters: ToolParameters;
|
|
31
|
+
category?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Tool class - Represents an executable tool
|
|
35
|
+
*/
|
|
36
|
+
export declare class FunctionTool<TParams = any, TResult = any> {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly description: string;
|
|
39
|
+
readonly parameters: ToolParameters;
|
|
40
|
+
readonly category?: string;
|
|
41
|
+
private readonly executeFn;
|
|
42
|
+
constructor(config: ToolConfig<TParams, TResult>);
|
|
43
|
+
private normalizeParameters;
|
|
44
|
+
private zodToJsonSchema;
|
|
45
|
+
private zodFieldToJsonSchema;
|
|
46
|
+
execute(params: TParams, context?: ToolContext): Promise<TResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the tool definition for LLM
|
|
49
|
+
*/
|
|
50
|
+
getDefinition(): ToolDefinition;
|
|
51
|
+
/**
|
|
52
|
+
* Get OpenAI-compatible tool format
|
|
53
|
+
*/
|
|
54
|
+
toOpenAITool(): {
|
|
55
|
+
type: 'function';
|
|
56
|
+
function: {
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
parameters: any;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a tool from a configuration object
|
|
65
|
+
*/
|
|
66
|
+
export declare function tool<TParams = any, TResult = any>(config: ToolConfig<TParams, TResult>): FunctionTool<TParams, TResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Tool Registry - Manages tool registration and lookup
|
|
69
|
+
*/
|
|
70
|
+
export declare class ToolRegistry {
|
|
71
|
+
private tools;
|
|
72
|
+
register(tool: FunctionTool, options?: {
|
|
73
|
+
overwrite?: boolean;
|
|
74
|
+
}): this;
|
|
75
|
+
get(name: string): FunctionTool | undefined;
|
|
76
|
+
has(name: string): boolean;
|
|
77
|
+
list(): FunctionTool[];
|
|
78
|
+
getByCategory(category: string): FunctionTool[];
|
|
79
|
+
getDefinitions(): ToolDefinition[];
|
|
80
|
+
toOpenAITools(): Array<{
|
|
81
|
+
type: 'function';
|
|
82
|
+
function: any;
|
|
83
|
+
}>;
|
|
84
|
+
delete(name: string): boolean;
|
|
85
|
+
clear(): void;
|
|
86
|
+
}
|
|
87
|
+
export declare function getRegistry(): ToolRegistry;
|
|
88
|
+
export declare function registerTool(tool: FunctionTool, options?: {
|
|
89
|
+
overwrite?: boolean;
|
|
90
|
+
}): void;
|
|
91
|
+
export declare function getTool(name: string): FunctionTool | undefined;
|