@mcpsovereign/sdk 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -1
- package/dist/telemetry.d.ts +56 -0
- package/dist/telemetry.js +114 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { setTelemetryEnabled, isTelemetryEnabled, sendTelemetry, trackInit, trackAuth, trackTradeSelect, trackSync, trackError } from './telemetry.js';
|
|
1
2
|
export { AgentRuntime, createRuntime } from './runtime.js';
|
|
2
3
|
export type { RuntimeConfig, RuntimeOptions } from './runtime.js';
|
|
3
4
|
export * from './onboarding/types.js';
|
|
@@ -288,6 +289,7 @@ export declare class LocalStoreManager {
|
|
|
288
289
|
export declare class SovereignClient {
|
|
289
290
|
private baseUrl;
|
|
290
291
|
private authToken;
|
|
292
|
+
private agentId;
|
|
291
293
|
localStore: LocalStoreManager;
|
|
292
294
|
constructor(config?: SovereignConfig);
|
|
293
295
|
private request;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// mcpSovereign SDK - Local-First Store Management
|
|
3
3
|
// =============================================================================
|
|
4
4
|
// Agents build their store locally (free), sync to marketplace (costs credits)
|
|
5
|
+
// Re-export telemetry (optional - users can disable)
|
|
6
|
+
export { setTelemetryEnabled, isTelemetryEnabled, sendTelemetry, trackInit, trackAuth, trackTradeSelect, trackSync, trackError } from './telemetry.js';
|
|
5
7
|
// Re-export runtime module (portable identity management)
|
|
6
8
|
export { AgentRuntime, createRuntime } from './runtime.js';
|
|
7
9
|
// Re-export onboarding module
|
|
@@ -218,14 +220,18 @@ export class LocalStoreManager {
|
|
|
218
220
|
// =============================================================================
|
|
219
221
|
// Sovereign Client (talks to marketplace - costs credits)
|
|
220
222
|
// =============================================================================
|
|
223
|
+
import { trackInit, trackAuth, trackSync, trackPurchase } from './telemetry.js';
|
|
221
224
|
export class SovereignClient {
|
|
222
225
|
baseUrl;
|
|
223
226
|
authToken;
|
|
227
|
+
agentId = null;
|
|
224
228
|
localStore;
|
|
225
229
|
constructor(config = {}) {
|
|
226
230
|
this.baseUrl = config.baseUrl || 'https://api.mcpsovereign.com/api/v1';
|
|
227
231
|
this.authToken = config.authToken || null;
|
|
228
232
|
this.localStore = new LocalStoreManager(config.localStorePath);
|
|
233
|
+
// Track SDK initialization
|
|
234
|
+
trackInit();
|
|
229
235
|
}
|
|
230
236
|
// ---------------------------------------------------------------------------
|
|
231
237
|
// HTTP Methods
|
|
@@ -288,6 +294,9 @@ export class SovereignClient {
|
|
|
288
294
|
});
|
|
289
295
|
if (verifyResp.success && verifyResp.data) {
|
|
290
296
|
this.authToken = verifyResp.data.token;
|
|
297
|
+
this.agentId = verifyResp.data.agent.id;
|
|
298
|
+
// Track authentication
|
|
299
|
+
trackAuth(verifyResp.data.is_new_agent, this.agentId);
|
|
291
300
|
}
|
|
292
301
|
return verifyResp;
|
|
293
302
|
}
|
|
@@ -385,7 +394,12 @@ export class SovereignClient {
|
|
|
385
394
|
return this.request('GET', `/products/${productId}`);
|
|
386
395
|
}
|
|
387
396
|
async purchaseProduct(productId) {
|
|
388
|
-
|
|
397
|
+
const response = await this.request('POST', `/products/${productId}/purchase`);
|
|
398
|
+
if (response.success) {
|
|
399
|
+
// Track purchase
|
|
400
|
+
trackPurchase(this.agentId || undefined);
|
|
401
|
+
}
|
|
402
|
+
return response;
|
|
389
403
|
}
|
|
390
404
|
async downloadProduct(token) {
|
|
391
405
|
return this.request('GET', `/products/download/${token}`);
|
|
@@ -415,10 +429,17 @@ export class SovereignClient {
|
|
|
415
429
|
return { success: false, data: null, error: { code: 'NOT_AUTHENTICATED', message: 'Must be authenticated to push' } };
|
|
416
430
|
}
|
|
417
431
|
const manifest = this.localStore.generateSyncManifest(id);
|
|
432
|
+
const productsToSync = manifest.products.filter(p => p.action !== 'unchanged').length;
|
|
418
433
|
const response = await this.request('POST', '/sync/push', { manifest });
|
|
419
434
|
if (response.success && response.data) {
|
|
420
435
|
this.localStore.applySyncResults(response.data);
|
|
421
436
|
await this.localStore.save();
|
|
437
|
+
// Track successful sync
|
|
438
|
+
trackSync(true, productsToSync, this.agentId || undefined);
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
// Track failed sync
|
|
442
|
+
trackSync(false, productsToSync, this.agentId || undefined);
|
|
422
443
|
}
|
|
423
444
|
return response;
|
|
424
445
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type TelemetryEvent = 'sdk_init' | 'sdk_auth_start' | 'sdk_auth_success' | 'sdk_auth_new_agent' | 'sdk_trade_select' | 'sdk_product_create' | 'sdk_sync_start' | 'sdk_sync_success' | 'sdk_sync_fail' | 'sdk_purchase' | 'sdk_error';
|
|
2
|
+
export interface TelemetryPayload {
|
|
3
|
+
event: TelemetryEvent;
|
|
4
|
+
sdk_version: string;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
session_id?: string;
|
|
7
|
+
agent_hash?: string;
|
|
8
|
+
data?: {
|
|
9
|
+
is_new_agent?: boolean;
|
|
10
|
+
trade?: string;
|
|
11
|
+
products_count?: number;
|
|
12
|
+
error_type?: string;
|
|
13
|
+
error_message?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Enable or disable telemetry
|
|
19
|
+
*/
|
|
20
|
+
export declare function setTelemetryEnabled(enabled: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* Check if telemetry is enabled
|
|
23
|
+
*/
|
|
24
|
+
export declare function isTelemetryEnabled(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Send telemetry event (non-blocking, fire-and-forget)
|
|
27
|
+
*/
|
|
28
|
+
export declare function sendTelemetry(event: TelemetryEvent, data?: TelemetryPayload['data'], agentId?: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Track SDK initialization
|
|
31
|
+
*/
|
|
32
|
+
export declare function trackInit(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Track authentication
|
|
35
|
+
*/
|
|
36
|
+
export declare function trackAuth(isNewAgent: boolean, agentId?: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Track trade selection
|
|
39
|
+
*/
|
|
40
|
+
export declare function trackTradeSelect(trade: string, agentId?: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Track local product creation
|
|
43
|
+
*/
|
|
44
|
+
export declare function trackProductCreate(agentId?: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Track sync
|
|
47
|
+
*/
|
|
48
|
+
export declare function trackSync(success: boolean, productsCount: number, agentId?: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Track purchase
|
|
51
|
+
*/
|
|
52
|
+
export declare function trackPurchase(agentId?: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Track error
|
|
55
|
+
*/
|
|
56
|
+
export declare function trackError(errorType: string, errorMessage: string, agentId?: string): void;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// mcpSovereign SDK Telemetry
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Anonymous telemetry to track SDK usage and key events
|
|
5
|
+
// This helps us understand adoption and identify issues
|
|
6
|
+
const TELEMETRY_ENDPOINT = 'https://api.mcpsovereign.com/api/v1/telemetry';
|
|
7
|
+
const SDK_VERSION = '1.0.0';
|
|
8
|
+
// Configuration
|
|
9
|
+
let telemetryEnabled = true;
|
|
10
|
+
let sessionId = null;
|
|
11
|
+
/**
|
|
12
|
+
* Enable or disable telemetry
|
|
13
|
+
*/
|
|
14
|
+
export function setTelemetryEnabled(enabled) {
|
|
15
|
+
telemetryEnabled = enabled;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if telemetry is enabled
|
|
19
|
+
*/
|
|
20
|
+
export function isTelemetryEnabled() {
|
|
21
|
+
return telemetryEnabled;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get or create session ID
|
|
25
|
+
*/
|
|
26
|
+
function getSessionId() {
|
|
27
|
+
if (!sessionId) {
|
|
28
|
+
sessionId = 'sess_' + Date.now().toString(36) + Math.random().toString(36).substr(2, 9);
|
|
29
|
+
}
|
|
30
|
+
return sessionId;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hash a string for anonymous identification
|
|
34
|
+
*/
|
|
35
|
+
function hashString(str) {
|
|
36
|
+
let hash = 0;
|
|
37
|
+
for (let i = 0; i < str.length; i++) {
|
|
38
|
+
const char = str.charCodeAt(i);
|
|
39
|
+
hash = ((hash << 5) - hash) + char;
|
|
40
|
+
hash = hash & hash;
|
|
41
|
+
}
|
|
42
|
+
return 'h_' + Math.abs(hash).toString(16);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Send telemetry event (non-blocking, fire-and-forget)
|
|
46
|
+
*/
|
|
47
|
+
export async function sendTelemetry(event, data, agentId) {
|
|
48
|
+
if (!telemetryEnabled)
|
|
49
|
+
return;
|
|
50
|
+
const payload = {
|
|
51
|
+
event,
|
|
52
|
+
sdk_version: SDK_VERSION,
|
|
53
|
+
timestamp: new Date().toISOString(),
|
|
54
|
+
session_id: getSessionId(),
|
|
55
|
+
agent_hash: agentId ? hashString(agentId) : undefined,
|
|
56
|
+
data
|
|
57
|
+
};
|
|
58
|
+
// Fire and forget - don't await or catch errors
|
|
59
|
+
// This ensures telemetry never blocks or crashes the SDK
|
|
60
|
+
try {
|
|
61
|
+
fetch(TELEMETRY_ENDPOINT, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: { 'Content-Type': 'application/json' },
|
|
64
|
+
body: JSON.stringify(payload)
|
|
65
|
+
}).catch(() => {
|
|
66
|
+
// Silently ignore telemetry failures
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Silently ignore
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Track SDK initialization
|
|
75
|
+
*/
|
|
76
|
+
export function trackInit() {
|
|
77
|
+
sendTelemetry('sdk_init');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Track authentication
|
|
81
|
+
*/
|
|
82
|
+
export function trackAuth(isNewAgent, agentId) {
|
|
83
|
+
sendTelemetry(isNewAgent ? 'sdk_auth_new_agent' : 'sdk_auth_success', { is_new_agent: isNewAgent }, agentId);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Track trade selection
|
|
87
|
+
*/
|
|
88
|
+
export function trackTradeSelect(trade, agentId) {
|
|
89
|
+
sendTelemetry('sdk_trade_select', { trade }, agentId);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Track local product creation
|
|
93
|
+
*/
|
|
94
|
+
export function trackProductCreate(agentId) {
|
|
95
|
+
sendTelemetry('sdk_product_create', {}, agentId);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Track sync
|
|
99
|
+
*/
|
|
100
|
+
export function trackSync(success, productsCount, agentId) {
|
|
101
|
+
sendTelemetry(success ? 'sdk_sync_success' : 'sdk_sync_fail', { products_count: productsCount }, agentId);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Track purchase
|
|
105
|
+
*/
|
|
106
|
+
export function trackPurchase(agentId) {
|
|
107
|
+
sendTelemetry('sdk_purchase', {}, agentId);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Track error
|
|
111
|
+
*/
|
|
112
|
+
export function trackError(errorType, errorMessage, agentId) {
|
|
113
|
+
sendTelemetry('sdk_error', { error_type: errorType, error_message: errorMessage }, agentId);
|
|
114
|
+
}
|