praisonai 1.1.0 → 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.
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praisonai",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",
@@ -65,7 +65,6 @@
65
65
  "fast-xml-parser": "^4.5.1",
66
66
  "node-fetch": "^2.6.9",
67
67
  "openai": "^4.81.0",
68
- "praisonai": "latest",
69
68
  "@modelcontextprotocol/sdk": "^1.12.1"
70
69
  },
71
70
  "optionalDependencies": {