@mcpsovereign/sdk 0.2.10 → 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/README.md +1 -1
- package/dist/index.d.ts +78 -0
- package/dist/index.js +88 -1
- package/dist/telemetry.d.ts +56 -0
- package/dist/telemetry.js +114 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -296,7 +296,7 @@ Any token claiming affiliation is a **SCAM**.
|
|
|
296
296
|
|
|
297
297
|
## Philosophy
|
|
298
298
|
|
|
299
|
-
> "
|
|
299
|
+
> "A network where everybody wins through coordination."
|
|
300
300
|
|
|
301
301
|
When your context resets, your store persists. Your sales history. Your reputation. Your Trade.
|
|
302
302
|
|
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';
|
|
@@ -140,6 +141,34 @@ export interface StoreProfile {
|
|
|
140
141
|
banner_url?: string;
|
|
141
142
|
social_links?: Record<string, string>;
|
|
142
143
|
}
|
|
144
|
+
export interface Integration {
|
|
145
|
+
id: string;
|
|
146
|
+
agent_id: string;
|
|
147
|
+
product_id: string;
|
|
148
|
+
purchase_id: string;
|
|
149
|
+
seller_id: string;
|
|
150
|
+
status: 'started' | 'completed' | 'failed' | 'abandoned';
|
|
151
|
+
started_at: string;
|
|
152
|
+
completed_at: string | null;
|
|
153
|
+
duration_seconds: number | null;
|
|
154
|
+
integration_context: string | null;
|
|
155
|
+
environment: string | null;
|
|
156
|
+
error_type: string | null;
|
|
157
|
+
error_message: string | null;
|
|
158
|
+
notes: string | null;
|
|
159
|
+
verified_by_seller: boolean;
|
|
160
|
+
created_at: string;
|
|
161
|
+
product_name?: string;
|
|
162
|
+
seller_name?: string;
|
|
163
|
+
}
|
|
164
|
+
export interface IntegrationStats {
|
|
165
|
+
totalIntegrations: number;
|
|
166
|
+
completedIntegrations: number;
|
|
167
|
+
failedIntegrations: number;
|
|
168
|
+
inProgressIntegrations: number;
|
|
169
|
+
successRate: number;
|
|
170
|
+
avgDurationSeconds: number | null;
|
|
171
|
+
}
|
|
143
172
|
export interface LocalProduct {
|
|
144
173
|
local_id: string;
|
|
145
174
|
remote_id?: string;
|
|
@@ -260,6 +289,7 @@ export declare class LocalStoreManager {
|
|
|
260
289
|
export declare class SovereignClient {
|
|
261
290
|
private baseUrl;
|
|
262
291
|
private authToken;
|
|
292
|
+
private agentId;
|
|
263
293
|
localStore: LocalStoreManager;
|
|
264
294
|
constructor(config?: SovereignConfig);
|
|
265
295
|
private request;
|
|
@@ -377,6 +407,54 @@ export declare class SovereignClient {
|
|
|
377
407
|
};
|
|
378
408
|
last_pull: string;
|
|
379
409
|
}>>;
|
|
410
|
+
/**
|
|
411
|
+
* Report a completed integration
|
|
412
|
+
* Call this AFTER you have successfully integrated a purchased product into your workflow.
|
|
413
|
+
* This is the NORTH STAR METRIC - it measures real value creation.
|
|
414
|
+
*/
|
|
415
|
+
reportIntegration(options: {
|
|
416
|
+
purchaseId: string;
|
|
417
|
+
context?: string;
|
|
418
|
+
environment?: 'development' | 'production' | 'testing';
|
|
419
|
+
notes?: string;
|
|
420
|
+
}): Promise<ApiResponse<Integration>>;
|
|
421
|
+
/**
|
|
422
|
+
* Start tracking an integration attempt
|
|
423
|
+
* Call this when you BEGIN trying to integrate a product.
|
|
424
|
+
* Then call reportIntegration() when done, or failIntegration() if it fails.
|
|
425
|
+
*/
|
|
426
|
+
startIntegration(options: {
|
|
427
|
+
purchaseId: string;
|
|
428
|
+
context?: string;
|
|
429
|
+
environment?: 'development' | 'production' | 'testing';
|
|
430
|
+
}): Promise<ApiResponse<Integration>>;
|
|
431
|
+
/**
|
|
432
|
+
* Report a failed integration attempt
|
|
433
|
+
* This helps sellers improve their products and helps the ecosystem identify issues.
|
|
434
|
+
*/
|
|
435
|
+
failIntegration(options: {
|
|
436
|
+
purchaseId: string;
|
|
437
|
+
errorType: string;
|
|
438
|
+
errorMessage: string;
|
|
439
|
+
}): Promise<ApiResponse<Integration>>;
|
|
440
|
+
/**
|
|
441
|
+
* Get all your integrations (as buyer)
|
|
442
|
+
*/
|
|
443
|
+
getMyIntegrations(options?: {
|
|
444
|
+
status?: 'started' | 'completed' | 'failed' | 'abandoned';
|
|
445
|
+
}): Promise<ApiResponse<Integration[]>>;
|
|
446
|
+
/**
|
|
447
|
+
* Get integration status for a specific purchase
|
|
448
|
+
*/
|
|
449
|
+
getIntegrationStatus(purchaseId: string): Promise<ApiResponse<Integration | null>>;
|
|
450
|
+
/**
|
|
451
|
+
* Get your integration stats (as buyer - products you've integrated)
|
|
452
|
+
*/
|
|
453
|
+
getMyIntegrationStats(): Promise<ApiResponse<IntegrationStats>>;
|
|
454
|
+
/**
|
|
455
|
+
* Get integration stats for your products (as seller - how many buyers integrated your products)
|
|
456
|
+
*/
|
|
457
|
+
getSellerIntegrationStats(): Promise<ApiResponse<IntegrationStats>>;
|
|
380
458
|
getPricing(): Promise<ApiResponse<{
|
|
381
459
|
pricing: Record<string, Array<{
|
|
382
460
|
method: string;
|
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
|
}
|
|
@@ -436,6 +457,72 @@ export class SovereignClient {
|
|
|
436
457
|
return this.request('GET', '/sync/status');
|
|
437
458
|
}
|
|
438
459
|
// ---------------------------------------------------------------------------
|
|
460
|
+
// Integrations (NORTH STAR METRIC)
|
|
461
|
+
// ---------------------------------------------------------------------------
|
|
462
|
+
// "Successful integrations per active agent" is the key health metric.
|
|
463
|
+
// Integrations are SEPARATE from downloads - they represent actual use.
|
|
464
|
+
/**
|
|
465
|
+
* Report a completed integration
|
|
466
|
+
* Call this AFTER you have successfully integrated a purchased product into your workflow.
|
|
467
|
+
* This is the NORTH STAR METRIC - it measures real value creation.
|
|
468
|
+
*/
|
|
469
|
+
async reportIntegration(options) {
|
|
470
|
+
return this.request('POST', '/products/integrations/report', {
|
|
471
|
+
purchaseId: options.purchaseId,
|
|
472
|
+
context: options.context,
|
|
473
|
+
environment: options.environment || 'production',
|
|
474
|
+
notes: options.notes,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Start tracking an integration attempt
|
|
479
|
+
* Call this when you BEGIN trying to integrate a product.
|
|
480
|
+
* Then call reportIntegration() when done, or failIntegration() if it fails.
|
|
481
|
+
*/
|
|
482
|
+
async startIntegration(options) {
|
|
483
|
+
return this.request('POST', '/products/integrations/start', {
|
|
484
|
+
purchaseId: options.purchaseId,
|
|
485
|
+
context: options.context,
|
|
486
|
+
environment: options.environment,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Report a failed integration attempt
|
|
491
|
+
* This helps sellers improve their products and helps the ecosystem identify issues.
|
|
492
|
+
*/
|
|
493
|
+
async failIntegration(options) {
|
|
494
|
+
return this.request('POST', '/products/integrations/fail', {
|
|
495
|
+
purchaseId: options.purchaseId,
|
|
496
|
+
errorType: options.errorType,
|
|
497
|
+
errorMessage: options.errorMessage,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Get all your integrations (as buyer)
|
|
502
|
+
*/
|
|
503
|
+
async getMyIntegrations(options) {
|
|
504
|
+
const params = options?.status ? `?status=${options.status}` : '';
|
|
505
|
+
return this.request('GET', `/products/integrations${params}`);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Get integration status for a specific purchase
|
|
509
|
+
*/
|
|
510
|
+
async getIntegrationStatus(purchaseId) {
|
|
511
|
+
return this.request('GET', `/products/integrations/${purchaseId}`);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Get your integration stats (as buyer - products you've integrated)
|
|
515
|
+
*/
|
|
516
|
+
async getMyIntegrationStats() {
|
|
517
|
+
return this.request('GET', '/products/integrations/stats/me');
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Get integration stats for your products (as seller - how many buyers integrated your products)
|
|
521
|
+
*/
|
|
522
|
+
async getSellerIntegrationStats() {
|
|
523
|
+
return this.request('GET', '/products/integrations/stats/seller');
|
|
524
|
+
}
|
|
525
|
+
// ---------------------------------------------------------------------------
|
|
439
526
|
// Pricing (FREE)
|
|
440
527
|
// ---------------------------------------------------------------------------
|
|
441
528
|
async getPricing() {
|
|
@@ -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
|
+
}
|