@csaimonitor/sdk 0.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/CHANGELOG.md +34 -0
- package/LICENSE +22 -0
- package/README.md +315 -0
- package/dist/async-client.d.ts +143 -0
- package/dist/async-client.d.ts.map +1 -0
- package/dist/async-client.js +356 -0
- package/dist/async-client.js.map +1 -0
- package/dist/batcher.d.ts +50 -0
- package/dist/batcher.d.ts.map +1 -0
- package/dist/batcher.js +203 -0
- package/dist/batcher.js.map +1 -0
- package/dist/client.d.ts +178 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +248 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +72 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +115 -0
- package/dist/config.js.map +1 -0
- package/dist/decorators.d.ts +23 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +203 -0
- package/dist/decorators.js.map +1 -0
- package/dist/exceptions.d.ts +57 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +99 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +59 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +84 -0
- package/dist/models.js.map +1 -0
- package/dist/utils.d.ts +53 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +176 -0
- package/dist/utils.js.map +1 -0
- package/package.json +52 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous client for CSMonitor SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the main CSMonitor class for tracking agent events.
|
|
5
|
+
*/
|
|
6
|
+
import { CSMonitorConfig, CSMonitorConfigOptions } from './config';
|
|
7
|
+
import { Event } from './models';
|
|
8
|
+
import { createTrackDecorator } from './decorators';
|
|
9
|
+
import { setupLogger } from './utils';
|
|
10
|
+
/**
|
|
11
|
+
* Context manager for tracking events.
|
|
12
|
+
* This class is returned by trackEvent() and allows manual control over event attributes.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TrackedEvent {
|
|
15
|
+
private readonly monitor;
|
|
16
|
+
readonly eventType: string;
|
|
17
|
+
private inputData?;
|
|
18
|
+
private outputData?;
|
|
19
|
+
private metadata;
|
|
20
|
+
private costUsd?;
|
|
21
|
+
private status;
|
|
22
|
+
private errorMessage?;
|
|
23
|
+
private startTime?;
|
|
24
|
+
private startTimestamp?;
|
|
25
|
+
constructor(monitor: CSMonitor, eventType: string, inputData?: Record<string, unknown>);
|
|
26
|
+
/**
|
|
27
|
+
* Set output data for the event.
|
|
28
|
+
* @param outputData - Output data to track
|
|
29
|
+
*/
|
|
30
|
+
setOutput(outputData: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Set metadata fields.
|
|
33
|
+
* @param metadata - Metadata key-value pairs
|
|
34
|
+
*/
|
|
35
|
+
setMetadata(metadata: Record<string, unknown>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Set cost in USD.
|
|
38
|
+
* @param costUsd - Cost in US dollars
|
|
39
|
+
*/
|
|
40
|
+
setCost(costUsd: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Set event status.
|
|
43
|
+
* @param status - Status string ("success" or "failure")
|
|
44
|
+
*/
|
|
45
|
+
setStatus(status: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Set error message and status.
|
|
48
|
+
* @param errorMessage - Error message
|
|
49
|
+
*/
|
|
50
|
+
setError(errorMessage: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Start tracking (enter context).
|
|
53
|
+
*/
|
|
54
|
+
start(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Finish tracking and log event (exit context).
|
|
57
|
+
* @param error - Optional error that occurred
|
|
58
|
+
*/
|
|
59
|
+
finish(error?: unknown): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Main client for tracking agent events.
|
|
63
|
+
*
|
|
64
|
+
* This class provides multiple ways to track events:
|
|
65
|
+
* 1. Decorator: @monitor.track()
|
|
66
|
+
* 2. Context manager: monitor.trackEvent(...)
|
|
67
|
+
* 3. Manual: monitor.logEvent(...)
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const monitor = new CSMonitor({
|
|
72
|
+
* apiKey: 'your_key',
|
|
73
|
+
* agentId: 'my_agent',
|
|
74
|
+
* apiUrl: 'http://localhost:3002/api/v1'
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* @monitor.track()
|
|
78
|
+
* function myFunction(x: number): number {
|
|
79
|
+
* return x * 2;
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* const result = myFunction(5);
|
|
83
|
+
* monitor.flush();
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class CSMonitor {
|
|
87
|
+
readonly config: CSMonitorConfig;
|
|
88
|
+
readonly logger: ReturnType<typeof setupLogger>;
|
|
89
|
+
private readonly _batchQueue;
|
|
90
|
+
constructor(options: CSMonitorConfigOptions);
|
|
91
|
+
/**
|
|
92
|
+
* Decorator to automatically track function execution.
|
|
93
|
+
* @param options - Tracking options
|
|
94
|
+
* @returns Decorator function
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* @monitor.track({ eventType: 'query' })
|
|
99
|
+
* function askQuestion(question: string): string {
|
|
100
|
+
* return generateAnswer(question);
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
track(options?: Parameters<ReturnType<typeof createTrackDecorator>>[0]): <T extends (...args: unknown[]) => unknown>(target: T, _propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => T | PropertyDescriptor;
|
|
105
|
+
/**
|
|
106
|
+
* Create a context manager for tracking an event.
|
|
107
|
+
* @param eventType - Type of event
|
|
108
|
+
* @param inputData - Initial input data
|
|
109
|
+
* @returns TrackedEvent context manager
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const event = monitor.trackEvent('action');
|
|
114
|
+
* event.start();
|
|
115
|
+
* const result = performAction();
|
|
116
|
+
* event.setOutput({ result });
|
|
117
|
+
* event.setMetadata({ model: 'gpt-4' });
|
|
118
|
+
* event.finish();
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
trackEvent(eventType: string, inputData?: Record<string, unknown>): TrackedEvent;
|
|
122
|
+
/**
|
|
123
|
+
* Manually log an event.
|
|
124
|
+
* @param options - Event data
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* monitor.logEvent({
|
|
129
|
+
* eventType: 'decision',
|
|
130
|
+
* inputData: { query: 'test' },
|
|
131
|
+
* outputData: { answer: 'response' },
|
|
132
|
+
* metadata: { model: 'gpt-4' }
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
logEvent(options: {
|
|
137
|
+
eventType: string;
|
|
138
|
+
inputData?: Record<string, unknown>;
|
|
139
|
+
outputData?: Record<string, unknown>;
|
|
140
|
+
metadata?: Record<string, unknown>;
|
|
141
|
+
costUsd?: number;
|
|
142
|
+
latencyMs?: number;
|
|
143
|
+
status?: string;
|
|
144
|
+
errorMessage?: string;
|
|
145
|
+
timestamp?: string;
|
|
146
|
+
}): void;
|
|
147
|
+
/**
|
|
148
|
+
* Add event to batch queue (internal method).
|
|
149
|
+
* @param event - Event to add
|
|
150
|
+
*/
|
|
151
|
+
_addEvent(event: Event): void;
|
|
152
|
+
/**
|
|
153
|
+
* Flush all pending events immediately (blocking).
|
|
154
|
+
* Call this before your application exits to ensure all events are sent.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* monitor.flush();
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
flush(): void;
|
|
162
|
+
/**
|
|
163
|
+
* Close the monitor and cleanup resources.
|
|
164
|
+
* This will stop the background timer and flush any pending events.
|
|
165
|
+
* After calling close(), the monitor should not be used.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* monitor.close();
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
close(): void;
|
|
173
|
+
/**
|
|
174
|
+
* String representation.
|
|
175
|
+
*/
|
|
176
|
+
toString(): string;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAA2E,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/G;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IACpC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,OAAO,CAAC,SAAS,CAAC,CAA0B;IAC5C,OAAO,CAAC,UAAU,CAAC,CAA0B;IAC7C,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAC,CAAS;gBAEpB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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AM,EAAE,OAAO,CAAC,CAAC;QACnC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI;IA+BR;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAI7B;;;;;;;;OAQG;IACH,KAAK,IAAI,IAAI;IAKb;;;;;;;;;OASG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Synchronous client for CSMonitor SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module provides the main CSMonitor class for tracking agent events.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CSMonitor = exports.TrackedEvent = void 0;
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const models_1 = require("./models");
|
|
11
|
+
const batcher_1 = require("./batcher");
|
|
12
|
+
const decorators_1 = require("./decorators");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
/**
|
|
15
|
+
* Context manager for tracking events.
|
|
16
|
+
* This class is returned by trackEvent() and allows manual control over event attributes.
|
|
17
|
+
*/
|
|
18
|
+
class TrackedEvent {
|
|
19
|
+
constructor(monitor, eventType, inputData) {
|
|
20
|
+
this.metadata = {};
|
|
21
|
+
this.status = 'success';
|
|
22
|
+
this.monitor = monitor;
|
|
23
|
+
this.eventType = eventType;
|
|
24
|
+
this.inputData = inputData;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Set output data for the event.
|
|
28
|
+
* @param outputData - Output data to track
|
|
29
|
+
*/
|
|
30
|
+
setOutput(outputData) {
|
|
31
|
+
this.outputData = (0, utils_1.safeSerialize)(outputData);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set metadata fields.
|
|
35
|
+
* @param metadata - Metadata key-value pairs
|
|
36
|
+
*/
|
|
37
|
+
setMetadata(metadata) {
|
|
38
|
+
this.metadata = { ...this.metadata, ...metadata };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set cost in USD.
|
|
42
|
+
* @param costUsd - Cost in US dollars
|
|
43
|
+
*/
|
|
44
|
+
setCost(costUsd) {
|
|
45
|
+
this.costUsd = costUsd;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set event status.
|
|
49
|
+
* @param status - Status string ("success" or "failure")
|
|
50
|
+
*/
|
|
51
|
+
setStatus(status) {
|
|
52
|
+
this.status = status;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Set error message and status.
|
|
56
|
+
* @param errorMessage - Error message
|
|
57
|
+
*/
|
|
58
|
+
setError(errorMessage) {
|
|
59
|
+
this.status = 'failure';
|
|
60
|
+
this.errorMessage = errorMessage;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Start tracking (enter context).
|
|
64
|
+
*/
|
|
65
|
+
start() {
|
|
66
|
+
this.startTime = Date.now();
|
|
67
|
+
this.startTimestamp = (0, utils_1.getIsoTimestamp)();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Finish tracking and log event (exit context).
|
|
71
|
+
* @param error - Optional error that occurred
|
|
72
|
+
*/
|
|
73
|
+
finish(error) {
|
|
74
|
+
// Calculate latency
|
|
75
|
+
let latencyMs;
|
|
76
|
+
if (this.startTime) {
|
|
77
|
+
latencyMs = Date.now() - this.startTime;
|
|
78
|
+
}
|
|
79
|
+
// Handle exception
|
|
80
|
+
if (error) {
|
|
81
|
+
this.status = 'failure';
|
|
82
|
+
this.errorMessage = (0, utils_1.formatErrorMessage)(error);
|
|
83
|
+
}
|
|
84
|
+
// Apply redaction
|
|
85
|
+
let finalInputData = this.inputData;
|
|
86
|
+
let finalOutputData = this.outputData;
|
|
87
|
+
if (this.monitor.config.redactKeys.length > 0) {
|
|
88
|
+
if (finalInputData) {
|
|
89
|
+
finalInputData = (0, utils_1.redactSensitiveData)(finalInputData, this.monitor.config.redactKeys);
|
|
90
|
+
}
|
|
91
|
+
if (finalOutputData) {
|
|
92
|
+
finalOutputData = (0, utils_1.redactSensitiveData)(finalOutputData, this.monitor.config.redactKeys);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Create event
|
|
96
|
+
const event = models_1.Event.create(this.monitor.config.agentId, this.eventType, finalInputData, finalOutputData, Object.keys(this.metadata).length > 0 ? this.metadata : undefined, this.costUsd, latencyMs, this.status, this.errorMessage, this.startTimestamp);
|
|
97
|
+
// Log event
|
|
98
|
+
this.monitor._addEvent(event);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TrackedEvent = TrackedEvent;
|
|
102
|
+
/**
|
|
103
|
+
* Main client for tracking agent events.
|
|
104
|
+
*
|
|
105
|
+
* This class provides multiple ways to track events:
|
|
106
|
+
* 1. Decorator: @monitor.track()
|
|
107
|
+
* 2. Context manager: monitor.trackEvent(...)
|
|
108
|
+
* 3. Manual: monitor.logEvent(...)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const monitor = new CSMonitor({
|
|
113
|
+
* apiKey: 'your_key',
|
|
114
|
+
* agentId: 'my_agent',
|
|
115
|
+
* apiUrl: 'http://localhost:3002/api/v1'
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* @monitor.track()
|
|
119
|
+
* function myFunction(x: number): number {
|
|
120
|
+
* return x * 2;
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* const result = myFunction(5);
|
|
124
|
+
* monitor.flush();
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
class CSMonitor {
|
|
128
|
+
constructor(options) {
|
|
129
|
+
// Create config
|
|
130
|
+
this.config = new config_1.CSMonitorConfig(options);
|
|
131
|
+
this.logger = (0, utils_1.setupLogger)(this.config.debug);
|
|
132
|
+
// Initialize batch queue
|
|
133
|
+
this._batchQueue = new batcher_1.BatchQueue(this.config, options.onError);
|
|
134
|
+
this._batchQueue.start();
|
|
135
|
+
this.logger.info(`CSMonitor initialized for agent '${this.config.agentId}'`);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Decorator to automatically track function execution.
|
|
139
|
+
* @param options - Tracking options
|
|
140
|
+
* @returns Decorator function
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* @monitor.track({ eventType: 'query' })
|
|
145
|
+
* function askQuestion(question: string): string {
|
|
146
|
+
* return generateAnswer(question);
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
track(options) {
|
|
151
|
+
const decoratorFactory = (0, decorators_1.createTrackDecorator)(this);
|
|
152
|
+
return decoratorFactory(options);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a context manager for tracking an event.
|
|
156
|
+
* @param eventType - Type of event
|
|
157
|
+
* @param inputData - Initial input data
|
|
158
|
+
* @returns TrackedEvent context manager
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const event = monitor.trackEvent('action');
|
|
163
|
+
* event.start();
|
|
164
|
+
* const result = performAction();
|
|
165
|
+
* event.setOutput({ result });
|
|
166
|
+
* event.setMetadata({ model: 'gpt-4' });
|
|
167
|
+
* event.finish();
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
trackEvent(eventType, inputData) {
|
|
171
|
+
const event = new TrackedEvent(this, eventType, inputData);
|
|
172
|
+
event.start();
|
|
173
|
+
return event;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Manually log an event.
|
|
177
|
+
* @param options - Event data
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* monitor.logEvent({
|
|
182
|
+
* eventType: 'decision',
|
|
183
|
+
* inputData: { query: 'test' },
|
|
184
|
+
* outputData: { answer: 'response' },
|
|
185
|
+
* metadata: { model: 'gpt-4' }
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
logEvent(options) {
|
|
190
|
+
// Apply redaction
|
|
191
|
+
let finalInputData = options.inputData;
|
|
192
|
+
let finalOutputData = options.outputData;
|
|
193
|
+
if (this.config.redactKeys.length > 0) {
|
|
194
|
+
if (finalInputData) {
|
|
195
|
+
finalInputData = (0, utils_1.redactSensitiveData)(finalInputData, this.config.redactKeys);
|
|
196
|
+
}
|
|
197
|
+
if (finalOutputData) {
|
|
198
|
+
finalOutputData = (0, utils_1.redactSensitiveData)(finalOutputData, this.config.redactKeys);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Create event
|
|
202
|
+
const event = models_1.Event.create(this.config.agentId, options.eventType, finalInputData, finalOutputData, options.metadata, options.costUsd, options.latencyMs, options.status || 'success', options.errorMessage, options.timestamp);
|
|
203
|
+
// Add to queue
|
|
204
|
+
this._addEvent(event);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Add event to batch queue (internal method).
|
|
208
|
+
* @param event - Event to add
|
|
209
|
+
*/
|
|
210
|
+
_addEvent(event) {
|
|
211
|
+
this._batchQueue.addEvent(event);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Flush all pending events immediately (blocking).
|
|
215
|
+
* Call this before your application exits to ensure all events are sent.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* monitor.flush();
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
flush() {
|
|
223
|
+
this.logger.debug('Flushing pending events');
|
|
224
|
+
this._batchQueue.flush();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Close the monitor and cleanup resources.
|
|
228
|
+
* This will stop the background timer and flush any pending events.
|
|
229
|
+
* After calling close(), the monitor should not be used.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* monitor.close();
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
close() {
|
|
237
|
+
this.logger.info('Closing CSMonitor');
|
|
238
|
+
this._batchQueue.stop();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* String representation.
|
|
242
|
+
*/
|
|
243
|
+
toString() {
|
|
244
|
+
return `CSMonitor(agentId='${this.config.agentId}', enabled=${this.config.enabled})`;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.CSMonitor = CSMonitor;
|
|
248
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAAmE;AACnE,qCAAiC;AACjC,uCAAuC;AACvC,6CAAoD;AACpD,mCAA+G;AAE/G;;;GAGG;AACH,MAAa,YAAY;IAYvB,YAAY,OAAkB,EAAE,SAAiB,EAAE,SAAmC;QAP9E,aAAQ,GAA4B,EAAE,CAAC;QAEvC,WAAM,GAAW,SAAS,CAAC;QAMjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,UAAmB;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,QAAiC;QAC3C,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,QA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;IAED;;;OAGG;IACH,SAAS,CAAC,KAAY;QACpB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACtC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,sBAAsB,IAAI,CAAC,MAAM,CAAC,OAAO,cAAc,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC;IACvF,CAAC;CACF;AA3JD,8BA2JC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for CSMonitor SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module handles SDK configuration and validation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default API URL
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_API_URL = "https://api.agentmonitor.io/api/v1";
|
|
10
|
+
/**
|
|
11
|
+
* Default batch settings
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_BATCH_SIZE = 10;
|
|
14
|
+
export declare const DEFAULT_FLUSH_INTERVAL = 5;
|
|
15
|
+
/**
|
|
16
|
+
* Default retry settings
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_RETRY_ATTEMPTS = 3;
|
|
19
|
+
export declare const DEFAULT_TIMEOUT = 30;
|
|
20
|
+
/**
|
|
21
|
+
* Configuration options for CSMonitor client.
|
|
22
|
+
*/
|
|
23
|
+
export interface CSMonitorConfigOptions {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
agentId: string;
|
|
26
|
+
apiUrl?: string;
|
|
27
|
+
batchSize?: number;
|
|
28
|
+
flushInterval?: number;
|
|
29
|
+
retryAttempts?: number;
|
|
30
|
+
timeout?: number;
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
redactKeys?: string[];
|
|
34
|
+
onError?: (error: Error) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for CSMonitor client.
|
|
38
|
+
*/
|
|
39
|
+
export declare class CSMonitorConfig {
|
|
40
|
+
readonly apiKey: string;
|
|
41
|
+
readonly agentId: string;
|
|
42
|
+
readonly apiUrl: string;
|
|
43
|
+
readonly batchSize: number;
|
|
44
|
+
readonly flushInterval: number;
|
|
45
|
+
readonly retryAttempts: number;
|
|
46
|
+
readonly timeout: number;
|
|
47
|
+
readonly debug: boolean;
|
|
48
|
+
readonly enabled: boolean;
|
|
49
|
+
readonly redactKeys: string[];
|
|
50
|
+
readonly onError?: (error: Error) => void;
|
|
51
|
+
constructor(options: CSMonitorConfigOptions);
|
|
52
|
+
/**
|
|
53
|
+
* Validate configuration after initialization.
|
|
54
|
+
* @throws ConfigError if configuration is invalid
|
|
55
|
+
*/
|
|
56
|
+
private validate;
|
|
57
|
+
/**
|
|
58
|
+
* Get the full URL for batch event ingestion.
|
|
59
|
+
* @returns Full URL for /events/batch endpoint
|
|
60
|
+
*/
|
|
61
|
+
get batchUrl(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Get HTTP headers for API requests.
|
|
64
|
+
* @returns Dictionary of headers including authentication
|
|
65
|
+
*/
|
|
66
|
+
get headers(): Record<string, string>;
|
|
67
|
+
/**
|
|
68
|
+
* String representation with redacted API key.
|
|
69
|
+
*/
|
|
70
|
+
toString(): string;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources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AO,EAAE,sBAAsB;IAuB3C;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAwChB;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKpC;IAED;;OAEG;IACH,QAAQ,IAAI,MAAM;CAYnB"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration management for CSMonitor SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module handles SDK configuration and validation.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CSMonitorConfig = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RETRY_ATTEMPTS = exports.DEFAULT_FLUSH_INTERVAL = exports.DEFAULT_BATCH_SIZE = exports.DEFAULT_API_URL = void 0;
|
|
9
|
+
const exceptions_1 = require("./exceptions");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
/**
|
|
12
|
+
* Default API URL
|
|
13
|
+
*/
|
|
14
|
+
exports.DEFAULT_API_URL = 'https://api.agentmonitor.io/api/v1';
|
|
15
|
+
/**
|
|
16
|
+
* Default batch settings
|
|
17
|
+
*/
|
|
18
|
+
exports.DEFAULT_BATCH_SIZE = 10;
|
|
19
|
+
exports.DEFAULT_FLUSH_INTERVAL = 5.0;
|
|
20
|
+
/**
|
|
21
|
+
* Default retry settings
|
|
22
|
+
*/
|
|
23
|
+
exports.DEFAULT_RETRY_ATTEMPTS = 3;
|
|
24
|
+
exports.DEFAULT_TIMEOUT = 30;
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for CSMonitor client.
|
|
27
|
+
*/
|
|
28
|
+
class CSMonitorConfig {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
// Required fields
|
|
31
|
+
this.apiKey = options.apiKey;
|
|
32
|
+
this.agentId = options.agentId;
|
|
33
|
+
// Optional fields with defaults - normalize API URL
|
|
34
|
+
let apiUrl = options.apiUrl || exports.DEFAULT_API_URL;
|
|
35
|
+
apiUrl = apiUrl.replace(/\/+$/, ''); // Remove trailing slashes
|
|
36
|
+
this.apiUrl = apiUrl;
|
|
37
|
+
this.batchSize = options.batchSize ?? exports.DEFAULT_BATCH_SIZE;
|
|
38
|
+
this.flushInterval = options.flushInterval ?? exports.DEFAULT_FLUSH_INTERVAL;
|
|
39
|
+
this.retryAttempts = options.retryAttempts ?? exports.DEFAULT_RETRY_ATTEMPTS;
|
|
40
|
+
this.timeout = options.timeout ?? exports.DEFAULT_TIMEOUT;
|
|
41
|
+
this.debug = options.debug ?? false;
|
|
42
|
+
this.enabled = options.enabled ?? true;
|
|
43
|
+
this.redactKeys = options.redactKeys || [];
|
|
44
|
+
this.onError = options.onError;
|
|
45
|
+
// Validate configuration
|
|
46
|
+
this.validate();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate configuration after initialization.
|
|
50
|
+
* @throws ConfigError if configuration is invalid
|
|
51
|
+
*/
|
|
52
|
+
validate() {
|
|
53
|
+
// Validate API key
|
|
54
|
+
if (!(0, utils_1.validateApiKey)(this.apiKey)) {
|
|
55
|
+
throw new exceptions_1.ConfigError('Invalid API key. API key must be at least 32 characters long. ' +
|
|
56
|
+
'Get your API key from the CSMonitor dashboard.');
|
|
57
|
+
}
|
|
58
|
+
// Validate agent ID
|
|
59
|
+
if (!(0, utils_1.validateAgentId)(this.agentId)) {
|
|
60
|
+
throw new exceptions_1.ConfigError('Invalid agent_id. Agent ID must be a non-empty string.');
|
|
61
|
+
}
|
|
62
|
+
// Validate API URL (already normalized in constructor)
|
|
63
|
+
if (!this.apiUrl || typeof this.apiUrl !== 'string') {
|
|
64
|
+
throw new exceptions_1.ConfigError('Invalid api_url. Must be a non-empty string.');
|
|
65
|
+
}
|
|
66
|
+
// Validate batch size
|
|
67
|
+
if (!Number.isInteger(this.batchSize) || this.batchSize < 1 || this.batchSize > 100) {
|
|
68
|
+
throw new exceptions_1.ConfigError('Invalid batch_size. Must be an integer between 1 and 100.');
|
|
69
|
+
}
|
|
70
|
+
// Validate flush interval
|
|
71
|
+
if (typeof this.flushInterval !== 'number' || this.flushInterval < 0.1) {
|
|
72
|
+
throw new exceptions_1.ConfigError('Invalid flush_interval. Must be a number >= 0.1 seconds.');
|
|
73
|
+
}
|
|
74
|
+
// Validate retry attempts
|
|
75
|
+
if (!Number.isInteger(this.retryAttempts) || this.retryAttempts < 0 || this.retryAttempts > 10) {
|
|
76
|
+
throw new exceptions_1.ConfigError('Invalid retry_attempts. Must be an integer between 0 and 10.');
|
|
77
|
+
}
|
|
78
|
+
// Validate timeout
|
|
79
|
+
if (typeof this.timeout !== 'number' || this.timeout < 1) {
|
|
80
|
+
throw new exceptions_1.ConfigError('Invalid timeout. Must be a number >= 1 second.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the full URL for batch event ingestion.
|
|
85
|
+
* @returns Full URL for /events/batch endpoint
|
|
86
|
+
*/
|
|
87
|
+
get batchUrl() {
|
|
88
|
+
return `${this.apiUrl}/events/batch`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get HTTP headers for API requests.
|
|
92
|
+
* @returns Dictionary of headers including authentication
|
|
93
|
+
*/
|
|
94
|
+
get headers() {
|
|
95
|
+
return {
|
|
96
|
+
'X-API-Key': this.apiKey,
|
|
97
|
+
'Content-Type': 'application/json',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* String representation with redacted API key.
|
|
102
|
+
*/
|
|
103
|
+
toString() {
|
|
104
|
+
const redactedKey = this.apiKey.substring(0, 8) + '...' + this.apiKey.substring(this.apiKey.length - 4);
|
|
105
|
+
return (`CSMonitorConfig(` +
|
|
106
|
+
`apiKey='${redactedKey}', ` +
|
|
107
|
+
`agentId='${this.agentId}', ` +
|
|
108
|
+
`apiUrl='${this.apiUrl}', ` +
|
|
109
|
+
`batchSize=${this.batchSize}, ` +
|
|
110
|
+
`flushInterval=${this.flushInterval}, ` +
|
|
111
|
+
`enabled=${this.enabled})`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.CSMonitorConfig = CSMonitorConfig;
|
|
115
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,6CAA2C;AAC3C,mCAA0D;AAE1D;;GAEG;AACU,QAAA,eAAe,GAAG,oCAAoC,CAAC;AAEpE;;GAEG;AACU,QAAA,kBAAkB,GAAG,EAAE,CAAC;AACxB,QAAA,sBAAsB,GAAG,GAAG,CAAC;AAE1C;;GAEG;AACU,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,eAAe,GAAG,EAAE,CAAC;AAmBlC;;GAEG;AACH,MAAa,eAAe;IAa1B,YAAY,OAA+B;QACzC,kBAAkB;QAClB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAE/B,oDAAoD;QACpD,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,uBAAe,CAAC;QAC/C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,0BAA0B;QAC/D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,0BAAkB,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,8BAAsB,CAAC;QACrE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,8BAAsB,CAAC;QACrE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,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|
|
3
|
+
*
|
|
4
|
+
* This module provides the @track decorator for automatic monitoring of functions.
|
|
5
|
+
*/
|
|
6
|
+
import type { CSMonitor } from './client';
|
|
7
|
+
import type { AsyncCSMonitor } from './async-client';
|
|
8
|
+
/**
|
|
9
|
+
* Track decorator options.
|
|
10
|
+
*/
|
|
11
|
+
export interface TrackOptions {
|
|
12
|
+
eventType?: string;
|
|
13
|
+
captureInput?: boolean;
|
|
14
|
+
captureOutput?: boolean;
|
|
15
|
+
metadata?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a track decorator bound to a monitor instance.
|
|
19
|
+
* @param monitorInstance - CSMonitor or AsyncCSMonitor instance
|
|
20
|
+
* @returns Track decorator function
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTrackDecorator(monitorInstance: CSMonitor | AsyncCSMonitor): (options?: TrackOptions) => <T extends (...args: unknown[]) => unknown>(target: T, _propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => T | PropertyDescriptor;
|
|
23
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,SAAS,GAAG,cAAc,IACxD,UAAS,YAAiB,MAQpB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACjE,QAAQ,CAAC,EACT,eAAe,MAAM,GAAG,MAAM,EAC9B,aAAa,kBAAkB,KAC9B,CAAC,GAAG,kBAAkB,CAsE5B"}
|