@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
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Decorators for automatic event tracking.
|
|
4
|
+
*
|
|
5
|
+
* This module provides the @track decorator for automatic monitoring of functions.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createTrackDecorator = createTrackDecorator;
|
|
9
|
+
const models_1 = require("./models");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
/**
|
|
12
|
+
* Create a track decorator bound to a monitor instance.
|
|
13
|
+
* @param monitorInstance - CSMonitor or AsyncCSMonitor instance
|
|
14
|
+
* @returns Track decorator function
|
|
15
|
+
*/
|
|
16
|
+
function createTrackDecorator(monitorInstance) {
|
|
17
|
+
return function track(options = {}) {
|
|
18
|
+
const { eventType = 'function_call', captureInput = true, captureOutput = true, metadata = {}, } = options;
|
|
19
|
+
return function decorator(target, _propertyKey, descriptor) {
|
|
20
|
+
// Handle method decorator (descriptor provided)
|
|
21
|
+
if (descriptor) {
|
|
22
|
+
const originalMethod = descriptor.value;
|
|
23
|
+
const isAsync = originalMethod.constructor.name === 'AsyncFunction' ||
|
|
24
|
+
originalMethod[Symbol.toStringTag] === 'AsyncFunction';
|
|
25
|
+
if (isAsync) {
|
|
26
|
+
descriptor.value = async function asyncWrapper(...args) {
|
|
27
|
+
return await executeTracked(originalMethod, args, eventType, captureInput, captureOutput, metadata, monitorInstance, true);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
descriptor.value = function syncWrapper(...args) {
|
|
32
|
+
return executeTracked(originalMethod, args, eventType, captureInput, captureOutput, metadata, monitorInstance, false);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return descriptor;
|
|
36
|
+
}
|
|
37
|
+
// Handle function decorator (no descriptor)
|
|
38
|
+
const isAsync = target.constructor.name === 'AsyncFunction' ||
|
|
39
|
+
target[Symbol.toStringTag] === 'AsyncFunction';
|
|
40
|
+
if (isAsync) {
|
|
41
|
+
return (async function asyncWrapper(...args) {
|
|
42
|
+
return await executeTracked(target, args, eventType, captureInput, captureOutput, metadata, monitorInstance, true);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return (function syncWrapper(...args) {
|
|
47
|
+
return executeTracked(target, args, eventType, captureInput, captureOutput, metadata, monitorInstance, false);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Execute function with tracking.
|
|
55
|
+
*/
|
|
56
|
+
function executeTracked(func, args, eventType, captureInput, captureOutput, metadata, monitorInstance, isAsync) {
|
|
57
|
+
// Start timing
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
const startTimestamp = (0, utils_1.getIsoTimestamp)();
|
|
60
|
+
// Capture input
|
|
61
|
+
let inputData;
|
|
62
|
+
if (captureInput) {
|
|
63
|
+
inputData = captureFunctionInput(func, args);
|
|
64
|
+
}
|
|
65
|
+
// Apply redaction if configured
|
|
66
|
+
if (monitorInstance.config.redactKeys.length > 0 && inputData) {
|
|
67
|
+
inputData = (0, utils_1.redactSensitiveData)(inputData, monitorInstance.config.redactKeys);
|
|
68
|
+
}
|
|
69
|
+
// Execute function
|
|
70
|
+
let error = null;
|
|
71
|
+
let outputData;
|
|
72
|
+
let status = 'success';
|
|
73
|
+
let errorMessage;
|
|
74
|
+
let output;
|
|
75
|
+
// Helper to create and log event
|
|
76
|
+
const logEvent = () => {
|
|
77
|
+
// Calculate latency
|
|
78
|
+
const endTime = Date.now();
|
|
79
|
+
const latencyMs = endTime - startTime;
|
|
80
|
+
// Build metadata
|
|
81
|
+
const eventMetadata = {
|
|
82
|
+
function_name: func.name || 'anonymous',
|
|
83
|
+
...metadata,
|
|
84
|
+
};
|
|
85
|
+
// Create and log event
|
|
86
|
+
const event = models_1.Event.create(monitorInstance.config.agentId, eventType, inputData, outputData, eventMetadata, undefined, // cost_usd
|
|
87
|
+
latencyMs, status, errorMessage, startTimestamp);
|
|
88
|
+
// Add event to queue (handle both sync and async)
|
|
89
|
+
if ('_addEvent' in monitorInstance) {
|
|
90
|
+
monitorInstance._addEvent(event);
|
|
91
|
+
}
|
|
92
|
+
else if ('_addEventAsync' in monitorInstance) {
|
|
93
|
+
monitorInstance._addEventAsync(event).catch((err) => {
|
|
94
|
+
monitorInstance.logger.error(`Error adding event: ${err}`);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
if (isAsync) {
|
|
99
|
+
// Async execution
|
|
100
|
+
return (async () => {
|
|
101
|
+
try {
|
|
102
|
+
output = await func(...args);
|
|
103
|
+
// Capture output
|
|
104
|
+
if (captureOutput) {
|
|
105
|
+
outputData = (0, utils_1.safeSerialize)(output);
|
|
106
|
+
}
|
|
107
|
+
// Apply redaction if configured
|
|
108
|
+
if (monitorInstance.config.redactKeys.length > 0 && outputData) {
|
|
109
|
+
outputData = (0, utils_1.redactSensitiveData)(outputData, monitorInstance.config.redactKeys);
|
|
110
|
+
}
|
|
111
|
+
// Log event (await if async monitor)
|
|
112
|
+
if ('_addEventAsync' in monitorInstance) {
|
|
113
|
+
await monitorInstance._addEventAsync(models_1.Event.create(monitorInstance.config.agentId, eventType, inputData, outputData, {
|
|
114
|
+
function_name: func.name || 'anonymous',
|
|
115
|
+
...metadata,
|
|
116
|
+
}, undefined, Date.now() - startTime, status, errorMessage, startTimestamp));
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
logEvent();
|
|
120
|
+
}
|
|
121
|
+
return output;
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
error = e;
|
|
125
|
+
status = 'failure';
|
|
126
|
+
errorMessage = (0, utils_1.formatErrorMessage)(e);
|
|
127
|
+
monitorInstance.logger.debug(`Function ${func.name} raised error: ${errorMessage}`);
|
|
128
|
+
// Log error event
|
|
129
|
+
if ('_addEventAsync' in monitorInstance) {
|
|
130
|
+
await monitorInstance._addEventAsync(models_1.Event.create(monitorInstance.config.agentId, eventType, inputData, outputData, {
|
|
131
|
+
function_name: func.name || 'anonymous',
|
|
132
|
+
...metadata,
|
|
133
|
+
}, undefined, Date.now() - startTime, status, errorMessage, startTimestamp));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
logEvent();
|
|
137
|
+
}
|
|
138
|
+
throw e; // Re-throw the error
|
|
139
|
+
}
|
|
140
|
+
})();
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// Sync execution
|
|
144
|
+
try {
|
|
145
|
+
output = func(...args);
|
|
146
|
+
// Capture output
|
|
147
|
+
if (captureOutput) {
|
|
148
|
+
outputData = (0, utils_1.safeSerialize)(output);
|
|
149
|
+
}
|
|
150
|
+
// Apply redaction if configured
|
|
151
|
+
if (monitorInstance.config.redactKeys.length > 0 && outputData) {
|
|
152
|
+
outputData = (0, utils_1.redactSensitiveData)(outputData, monitorInstance.config.redactKeys);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
error = e;
|
|
157
|
+
status = 'failure';
|
|
158
|
+
errorMessage = (0, utils_1.formatErrorMessage)(e);
|
|
159
|
+
monitorInstance.logger.debug(`Function ${func.name} raised error: ${errorMessage}`);
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
logEvent();
|
|
163
|
+
}
|
|
164
|
+
// Re-raise error if one occurred
|
|
165
|
+
if (error) {
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
return output;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Capture function input arguments.
|
|
173
|
+
*/
|
|
174
|
+
function captureFunctionInput(func, args) {
|
|
175
|
+
try {
|
|
176
|
+
// Try to get function parameter names from source
|
|
177
|
+
const funcStr = func.toString();
|
|
178
|
+
const match = funcStr.match(/\(([^)]*)\)/);
|
|
179
|
+
if (match && match[1]) {
|
|
180
|
+
const paramNames = match[1]
|
|
181
|
+
.split(',')
|
|
182
|
+
.map((p) => p.trim().split('=')[0].trim())
|
|
183
|
+
.filter((p) => p.length > 0);
|
|
184
|
+
const inputDict = {};
|
|
185
|
+
for (let i = 0; i < paramNames.length && i < args.length; i++) {
|
|
186
|
+
inputDict[paramNames[i]] = (0, utils_1.safeSerialize)(args[i]);
|
|
187
|
+
}
|
|
188
|
+
// Add any remaining args
|
|
189
|
+
if (args.length > paramNames.length) {
|
|
190
|
+
inputDict['_extra_args'] = args.slice(paramNames.length).map(utils_1.safeSerialize);
|
|
191
|
+
}
|
|
192
|
+
return inputDict;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
// Fall through to fallback
|
|
197
|
+
}
|
|
198
|
+
// Fallback: just capture args as-is
|
|
199
|
+
return {
|
|
200
|
+
args: args.map(utils_1.safeSerialize),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAsBH,oDAmFC;AAvGD,qCAAiC;AACjC,mCAAkG;AAclG;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,eAA2C;IAC9E,OAAO,SAAS,KAAK,CAAC,UAAwB,EAAE;QAC9C,MAAM,EACJ,SAAS,GAAG,eAAe,EAC3B,YAAY,GAAG,IAAI,EACnB,aAAa,GAAG,IAAI,EACpB,QAAQ,GAAG,EAAE,GACd,GAAG,OAAO,CAAC;QAEZ,OAAO,SAAS,SAAS,CACvB,MAAS,EACT,YAA8B,EAC9B,UAA+B;YAE/B,gDAAgD;YAChD,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;gBACxC,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe;oBACjE,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,eAAe,CAAC;gBAEzD,IAAI,OAAO,EAAE,CAAC;oBACZ,UAAU,CAAC,KAAK,GAAG,KAAK,UAAU,YAAY,CAAgB,GAAG,IAAe;wBAC9E,OAAO,MAAM,cAAc,CACzB,cAA0D,EAC1D,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,aAAa,EACb,QAA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AAI,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;gBACpC,SAAS,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,qBAAa,CAAC,CAAC;YAC9E,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,2BAA2B;IAC7B,CAAC;IAED,oCAAoC;IACpC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,qBAAa,CAAC;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom exceptions for CSMonitor SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the exception hierarchy used by the SDK.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Base exception for all CSMonitor errors.
|
|
8
|
+
* All custom exceptions in the SDK inherit from this base class.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CSMonitorError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Configuration error.
|
|
15
|
+
* Raised when the SDK is configured incorrectly.
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
* - Invalid API key format
|
|
19
|
+
* - Missing required parameters
|
|
20
|
+
* - Invalid configuration values
|
|
21
|
+
*/
|
|
22
|
+
export declare class ConfigError extends CSMonitorError {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Authentication error.
|
|
27
|
+
* Raised when API key authentication fails.
|
|
28
|
+
*/
|
|
29
|
+
export declare class AuthenticationError extends CSMonitorError {
|
|
30
|
+
readonly statusCode: number;
|
|
31
|
+
constructor(message: string, statusCode?: number);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* API request error.
|
|
35
|
+
* Raised when an API request fails.
|
|
36
|
+
*/
|
|
37
|
+
export declare class APIError extends CSMonitorError {
|
|
38
|
+
readonly statusCode?: number;
|
|
39
|
+
readonly responseBody?: string;
|
|
40
|
+
constructor(message: string, statusCode?: number, responseBody?: string);
|
|
41
|
+
toString(): string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Network error.
|
|
45
|
+
* Raised when a network request fails (timeout, connection error, etc.).
|
|
46
|
+
*/
|
|
47
|
+
export declare class NetworkError extends CSMonitorError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validation error.
|
|
52
|
+
* Raised when event data fails validation before sending to API.
|
|
53
|
+
*/
|
|
54
|
+
export declare class ValidationError extends CSMonitorError {
|
|
55
|
+
constructor(message: string);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAK5B;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,cAAc;gBACjC,OAAO,EAAE,MAAM;CAK5B;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY;CAMtD;AAED;;;GAGG;AACH,qBAAa,QAAS,SAAQ,cAAc;IAC1C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;IAQvE,QAAQ,IAAI,MAAM;CAUnB;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,cAAc;gBAClC,OAAO,EAAE,MAAM;CAK5B;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom exceptions for CSMonitor SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module defines the exception hierarchy used by the SDK.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ValidationError = exports.NetworkError = exports.APIError = exports.AuthenticationError = exports.ConfigError = exports.CSMonitorError = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Base exception for all CSMonitor errors.
|
|
11
|
+
* All custom exceptions in the SDK inherit from this base class.
|
|
12
|
+
*/
|
|
13
|
+
class CSMonitorError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'CSMonitorError';
|
|
17
|
+
Object.setPrototypeOf(this, CSMonitorError.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.CSMonitorError = CSMonitorError;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration error.
|
|
23
|
+
* Raised when the SDK is configured incorrectly.
|
|
24
|
+
*
|
|
25
|
+
* Examples:
|
|
26
|
+
* - Invalid API key format
|
|
27
|
+
* - Missing required parameters
|
|
28
|
+
* - Invalid configuration values
|
|
29
|
+
*/
|
|
30
|
+
class ConfigError extends CSMonitorError {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'ConfigError';
|
|
34
|
+
Object.setPrototypeOf(this, ConfigError.prototype);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ConfigError = ConfigError;
|
|
38
|
+
/**
|
|
39
|
+
* Authentication error.
|
|
40
|
+
* Raised when API key authentication fails.
|
|
41
|
+
*/
|
|
42
|
+
class AuthenticationError extends CSMonitorError {
|
|
43
|
+
constructor(message, statusCode = 401) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = 'AuthenticationError';
|
|
46
|
+
this.statusCode = statusCode;
|
|
47
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AuthenticationError = AuthenticationError;
|
|
51
|
+
/**
|
|
52
|
+
* API request error.
|
|
53
|
+
* Raised when an API request fails.
|
|
54
|
+
*/
|
|
55
|
+
class APIError extends CSMonitorError {
|
|
56
|
+
constructor(message, statusCode, responseBody) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = 'APIError';
|
|
59
|
+
this.statusCode = statusCode;
|
|
60
|
+
this.responseBody = responseBody;
|
|
61
|
+
Object.setPrototypeOf(this, APIError.prototype);
|
|
62
|
+
}
|
|
63
|
+
toString() {
|
|
64
|
+
let msg = super.toString();
|
|
65
|
+
if (this.statusCode) {
|
|
66
|
+
msg += ` (status code: ${this.statusCode})`;
|
|
67
|
+
}
|
|
68
|
+
if (this.responseBody) {
|
|
69
|
+
msg += ` - Response: ${this.responseBody}`;
|
|
70
|
+
}
|
|
71
|
+
return msg;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.APIError = APIError;
|
|
75
|
+
/**
|
|
76
|
+
* Network error.
|
|
77
|
+
* Raised when a network request fails (timeout, connection error, etc.).
|
|
78
|
+
*/
|
|
79
|
+
class NetworkError extends CSMonitorError {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = 'NetworkError';
|
|
83
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.NetworkError = NetworkError;
|
|
87
|
+
/**
|
|
88
|
+
* Validation error.
|
|
89
|
+
* Raised when event data fails validation before sending to API.
|
|
90
|
+
*/
|
|
91
|
+
class ValidationError extends CSMonitorError {
|
|
92
|
+
constructor(message) {
|
|
93
|
+
super(message);
|
|
94
|
+
this.name = 'ValidationError';
|
|
95
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.ValidationError = ValidationError;
|
|
99
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH;;;GAGG;AACH,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACF;AAND,wCAMC;AAED;;;;;;;;GAQG;AACH,MAAa,WAAY,SAAQ,cAAc;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CACF;AAND,kCAMC;AAED;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,cAAc;IAGrD,YAAY,OAAe,EAAE,aAAqB,GAAG;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AATD,kDASC;AAED;;;GAGG;AACH,MAAa,QAAS,SAAQ,cAAc;IAI1C,YAAY,OAAe,EAAE,UAAmB,EAAE,YAAqB;QACrE,KAAK,CAAC,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*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { CSMonitor } from '@csaimonitor/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const monitor = new CSMonitor({
|
|
11
|
+
* apiKey: 'your_key',
|
|
12
|
+
* agentId: 'my_agent',
|
|
13
|
+
* apiUrl: 'http://localhost:3002/api/v1'
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* @monitor.track()
|
|
17
|
+
* function myAgentFunction(query: string): string {
|
|
18
|
+
* return `Response to: ${query}`;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* const result = myAgentFunction('Hello');
|
|
22
|
+
* monitor.flush();
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { AsyncCSMonitor } from '@csaimonitor/sdk';
|
|
28
|
+
*
|
|
29
|
+
* const monitor = new AsyncCSMonitor({
|
|
30
|
+
* apiKey: 'your_key',
|
|
31
|
+
* agentId: 'my_agent'
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* @monitor.track()
|
|
35
|
+
* async function asyncFunction(data: unknown) {
|
|
36
|
+
* return await process(data);
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* await monitor.flush();
|
|
40
|
+
* await monitor.stop();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export { CSMonitor, TrackedEvent } from './client';
|
|
44
|
+
export { AsyncCSMonitor, AsyncTrackedEvent } from './async-client';
|
|
45
|
+
export { Event, EventMetadata } from './models';
|
|
46
|
+
export { CSMonitorConfig, CSMonitorConfigOptions } from './config';
|
|
47
|
+
export { CSMonitorError, APIError, AuthenticationError, ConfigError, NetworkError, ValidationError, } from './exceptions';
|
|
48
|
+
export declare const VERSION = "0.1.0";
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,EACL,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CSMonitor SDK for Node.js/TypeScript.
|
|
4
|
+
*
|
|
5
|
+
* A developer-friendly SDK for monitoring AI agents in production.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { CSMonitor } from '@csaimonitor/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const monitor = new CSMonitor({
|
|
12
|
+
* apiKey: 'your_key',
|
|
13
|
+
* agentId: 'my_agent',
|
|
14
|
+
* apiUrl: 'http://localhost:3002/api/v1'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* @monitor.track()
|
|
18
|
+
* function myAgentFunction(query: string): string {
|
|
19
|
+
* return `Response to: ${query}`;
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const result = myAgentFunction('Hello');
|
|
23
|
+
* monitor.flush();
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { AsyncCSMonitor } from '@csaimonitor/sdk';
|
|
29
|
+
*
|
|
30
|
+
* const monitor = new AsyncCSMonitor({
|
|
31
|
+
* apiKey: 'your_key',
|
|
32
|
+
* agentId: 'my_agent'
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* @monitor.track()
|
|
36
|
+
* async function asyncFunction(data: unknown) {
|
|
37
|
+
* return await process(data);
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* await monitor.flush();
|
|
41
|
+
* await monitor.stop();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.VERSION = exports.ValidationError = exports.NetworkError = exports.ConfigError = exports.AuthenticationError = exports.APIError = exports.CSMonitorError = exports.CSMonitorConfig = exports.Event = exports.AsyncTrackedEvent = exports.AsyncCSMonitor = exports.TrackedEvent = exports.CSMonitor = void 0;
|
|
46
|
+
// Main clients
|
|
47
|
+
var client_1 = require("./client");
|
|
48
|
+
Object.defineProperty(exports, "CSMonitor", { enumerable: true, get: function () { return client_1.CSMonitor; } });
|
|
49
|
+
Object.defineProperty(exports, "TrackedEvent", { enumerable: true, get: function () { return client_1.TrackedEvent; } });
|
|
50
|
+
var async_client_1 = require("./async-client");
|
|
51
|
+
Object.defineProperty(exports, "AsyncCSMonitor", { enumerable: true, get: function () { return async_client_1.AsyncCSMonitor; } });
|
|
52
|
+
Object.defineProperty(exports, "AsyncTrackedEvent", { enumerable: true, get: function () { return async_client_1.AsyncTrackedEvent; } });
|
|
53
|
+
// Models
|
|
54
|
+
var models_1 = require("./models");
|
|
55
|
+
Object.defineProperty(exports, "Event", { enumerable: true, get: function () { return models_1.Event; } });
|
|
56
|
+
// Config
|
|
57
|
+
var config_1 = require("./config");
|
|
58
|
+
Object.defineProperty(exports, "CSMonitorConfig", { enumerable: true, get: function () { return config_1.CSMonitorConfig; } });
|
|
59
|
+
// Exceptions
|
|
60
|
+
var exceptions_1 = require("./exceptions");
|
|
61
|
+
Object.defineProperty(exports, "CSMonitorError", { enumerable: true, get: function () { return exceptions_1.CSMonitorError; } });
|
|
62
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return exceptions_1.APIError; } });
|
|
63
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return exceptions_1.AuthenticationError; } });
|
|
64
|
+
Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return exceptions_1.ConfigError; } });
|
|
65
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return exceptions_1.NetworkError; } });
|
|
66
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return exceptions_1.ValidationError; } });
|
|
67
|
+
// Version
|
|
68
|
+
exports.VERSION = '0.1.0';
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;AAEH,eAAe;AACf,mCAAmD;AAA1C,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAChC,+CAAmE;AAA1D,8GAAA,cAAc,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAE1C,SAAS;AACT,mCAAgD;AAAvC,+FAAA,KAAK,OAAA;AAEd,SAAS;AACT,mCAAmE;AAA1D,yGAAA,eAAe,OAAA;AAExB,aAAa;AACb,2CAOsB;AANpB,4GAAA,cAAc,OAAA;AACd,sGAAA,QAAQ,OAAA;AACR,iHAAA,mBAAmB,OAAA;AACnB,yGAAA,WAAW,OAAA;AACX,0GAAA,YAAY,OAAA;AACZ,6GAAA,eAAe,OAAA;AAGjB,UAAU;AACG,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data models for CSMonitor SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the core data structures used by the SDK.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Metadata for an event.
|
|
8
|
+
*/
|
|
9
|
+
export interface EventMetadata {
|
|
10
|
+
model?: string;
|
|
11
|
+
user_id?: string;
|
|
12
|
+
session_id?: string;
|
|
13
|
+
tags?: string[];
|
|
14
|
+
custom?: Record<string, unknown>;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* An event to be tracked.
|
|
19
|
+
* This class represents a single monitoring event that will be sent to the CSMonitor API.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Event {
|
|
22
|
+
readonly agent_id: string;
|
|
23
|
+
readonly event_type: string;
|
|
24
|
+
readonly timestamp: string;
|
|
25
|
+
readonly input_data?: Record<string, unknown>;
|
|
26
|
+
readonly output_data?: Record<string, unknown>;
|
|
27
|
+
readonly metadata?: EventMetadata;
|
|
28
|
+
readonly cost_usd?: number;
|
|
29
|
+
readonly latency_ms?: number;
|
|
30
|
+
readonly status: string;
|
|
31
|
+
readonly error_message?: string;
|
|
32
|
+
constructor(agent_id: string, event_type: string, timestamp: string, input_data?: Record<string, unknown>, output_data?: Record<string, unknown>, metadata?: EventMetadata, cost_usd?: number, latency_ms?: number, status?: string, error_message?: string);
|
|
33
|
+
/**
|
|
34
|
+
* Create a new Event with automatic timestamp.
|
|
35
|
+
* @param agent_id - Identifier for the agent
|
|
36
|
+
* @param event_type - Type of event
|
|
37
|
+
* @param input_data - Input data
|
|
38
|
+
* @param output_data - Output data
|
|
39
|
+
* @param metadata - Additional metadata
|
|
40
|
+
* @param cost_usd - Cost in USD
|
|
41
|
+
* @param latency_ms - Latency in milliseconds
|
|
42
|
+
* @param status - Event status
|
|
43
|
+
* @param error_message - Error message if status is "failure"
|
|
44
|
+
* @param timestamp - Override timestamp (ISO 8601 format)
|
|
45
|
+
* @returns New Event instance
|
|
46
|
+
*/
|
|
47
|
+
static create(agent_id: string, event_type: string, input_data?: Record<string, unknown>, output_data?: Record<string, unknown>, metadata?: EventMetadata, cost_usd?: number, latency_ms?: number, status?: string, error_message?: string, timestamp?: string): Event;
|
|
48
|
+
/**
|
|
49
|
+
* Convert to dictionary for API submission.
|
|
50
|
+
* @returns Dictionary representation with undefined values filtered out
|
|
51
|
+
*/
|
|
52
|
+
toDict(): Record<string, unknown>;
|
|
53
|
+
/**
|
|
54
|
+
* Convert to JSON string.
|
|
55
|
+
* @returns JSON string representation
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): string;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,KAAK;IAChB,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrD,SAAgB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtD,SAAgB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,aAAa,CAAC,EAAE,MAAM,CAAC;gBAGrC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,QAAQ,CAAC,EAAE,aAAa,EACxB,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,GAAE,MAAkB,EAC1B,aAAa,CAAC,EAAE,MAAM;IAcxB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,MAAM,CACX,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,QAAQ,CAAC,EAAE,aAAa,EACxB,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,GAAE,MAAkB,EAC1B,aAAa,CAAC,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM,GACjB,KAAK;IAiBR;;;OAGG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA8BjC;;;OAGG;IACH,MAAM,IAAI,MAAM;CAGjB"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Data models for CSMonitor SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module defines the core data structures used by the SDK.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Event = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* An event to be tracked.
|
|
11
|
+
* This class represents a single monitoring event that will be sent to the CSMonitor API.
|
|
12
|
+
*/
|
|
13
|
+
class Event {
|
|
14
|
+
constructor(agent_id, event_type, timestamp, input_data, output_data, metadata, cost_usd, latency_ms, status = 'success', error_message) {
|
|
15
|
+
this.agent_id = agent_id;
|
|
16
|
+
this.event_type = event_type;
|
|
17
|
+
this.timestamp = timestamp;
|
|
18
|
+
this.input_data = input_data;
|
|
19
|
+
this.output_data = output_data;
|
|
20
|
+
this.metadata = metadata;
|
|
21
|
+
this.cost_usd = cost_usd;
|
|
22
|
+
this.latency_ms = latency_ms;
|
|
23
|
+
this.status = status;
|
|
24
|
+
this.error_message = error_message;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a new Event with automatic timestamp.
|
|
28
|
+
* @param agent_id - Identifier for the agent
|
|
29
|
+
* @param event_type - Type of event
|
|
30
|
+
* @param input_data - Input data
|
|
31
|
+
* @param output_data - Output data
|
|
32
|
+
* @param metadata - Additional metadata
|
|
33
|
+
* @param cost_usd - Cost in USD
|
|
34
|
+
* @param latency_ms - Latency in milliseconds
|
|
35
|
+
* @param status - Event status
|
|
36
|
+
* @param error_message - Error message if status is "failure"
|
|
37
|
+
* @param timestamp - Override timestamp (ISO 8601 format)
|
|
38
|
+
* @returns New Event instance
|
|
39
|
+
*/
|
|
40
|
+
static create(agent_id, event_type, input_data, output_data, metadata, cost_usd, latency_ms, status = 'success', error_message, timestamp) {
|
|
41
|
+
const eventTimestamp = timestamp || new Date().toISOString();
|
|
42
|
+
return new Event(agent_id, event_type, eventTimestamp, input_data, output_data, metadata, cost_usd, latency_ms, status, error_message);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Convert to dictionary for API submission.
|
|
46
|
+
* @returns Dictionary representation with undefined values filtered out
|
|
47
|
+
*/
|
|
48
|
+
toDict() {
|
|
49
|
+
const result = {
|
|
50
|
+
agent_id: this.agent_id,
|
|
51
|
+
event_type: this.event_type,
|
|
52
|
+
timestamp: this.timestamp,
|
|
53
|
+
status: this.status,
|
|
54
|
+
};
|
|
55
|
+
if (this.input_data !== undefined) {
|
|
56
|
+
result.input_data = this.input_data;
|
|
57
|
+
}
|
|
58
|
+
if (this.output_data !== undefined) {
|
|
59
|
+
result.output_data = this.output_data;
|
|
60
|
+
}
|
|
61
|
+
if (this.metadata !== undefined) {
|
|
62
|
+
result.metadata = this.metadata;
|
|
63
|
+
}
|
|
64
|
+
if (this.cost_usd !== undefined) {
|
|
65
|
+
result.cost_usd = this.cost_usd;
|
|
66
|
+
}
|
|
67
|
+
if (this.latency_ms !== undefined) {
|
|
68
|
+
result.latency_ms = this.latency_ms;
|
|
69
|
+
}
|
|
70
|
+
if (this.error_message !== undefined) {
|
|
71
|
+
result.error_message = this.error_message;
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert to JSON string.
|
|
77
|
+
* @returns JSON string representation
|
|
78
|
+
*/
|
|
79
|
+
toJSON() {
|
|
80
|
+
return JSON.stringify(this.toDict());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Event = Event;
|
|
84
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAcH;;;GAGG;AACH,MAAa,KAAK;IAYhB,YACE,QAAgB,EAChB,UAAkB,EAClB,SAAiB,EACjB,UAAoC,EACpC,WAAqC,EACrC,QAAwB,EACxB,QAAiB,EACjB,UAAmB,EACnB,SAAiB,SAAS,EAC1B,aAAsB;QAEtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,C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