@mynitorai/sdk 0.2.5 → 0.2.7

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.
Files changed (2) hide show
  1. package/dist/cli.js +81 -9
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -11,6 +11,84 @@ async function run() {
11
11
  process.exit(1);
12
12
  }
13
13
  const command = process.argv[2];
14
+ const BASE_URL = process.env.MYNITOR_API_URL || 'https://app.mynitor.ai';
15
+ if (command === 'doctor') {
16
+ const pkg = require('../package.json');
17
+ console.log(`🩺 MyNitor Doctor (v${pkg.version})`);
18
+ console.log('---------------------------');
19
+ if (!apiKey) {
20
+ console.error('❌ API Key: Missing (MYNITOR_API_KEY not found in env)');
21
+ }
22
+ else {
23
+ const prefix = apiKey.substring(0, 8);
24
+ const last4 = apiKey.substring(apiKey.length - 4);
25
+ console.log(`✅ API Key: Detected (${prefix}...${last4})`);
26
+ }
27
+ try {
28
+ console.log('📡 Testing Connection...');
29
+ const endpoint = `${BASE_URL}/api/v1/onboarding/status`;
30
+ const res = await fetch(endpoint, {
31
+ headers: { 'Authorization': `Bearer ${apiKey}` }
32
+ });
33
+ if (res.ok) {
34
+ const data = await res.json();
35
+ console.log(`✅ Connection: MyNitor Cloud is reachable`);
36
+ console.log(`✅ Organization: ${data.orgId || 'Verified'}`);
37
+ }
38
+ else {
39
+ console.error(`❌ Connection: API returned ${res.status} (${res.statusText})`);
40
+ }
41
+ }
42
+ catch (e) {
43
+ console.error('❌ Connection: Failed to reach MyNitor Cloud');
44
+ console.error(` Error details: ${e.message || e}`);
45
+ if (e.code === 'ENOTFOUND')
46
+ console.log(' 💡 Suggestion: Check your internet connection or DNS settings.');
47
+ if (e.code === 'ECONNREFUSED')
48
+ console.log(' 💡 Suggestion: The server refused the connection. Is the API URL correct?');
49
+ if (e.message?.includes('certificate'))
50
+ console.log(' 💡 Suggestion: This looks like an SSL/Certificate issue.');
51
+ }
52
+ return;
53
+ }
54
+ if (command === 'mock') {
55
+ console.log('🎭 MyNitor: Sending mock OpenAI event to Cloud API...');
56
+ try {
57
+ const endpoint = `${BASE_URL}/api/v1/events`;
58
+ const response = await fetch(endpoint, {
59
+ method: 'POST',
60
+ headers: {
61
+ 'Content-Type': 'application/json',
62
+ 'Authorization': `Bearer ${apiKey}`
63
+ },
64
+ body: JSON.stringify({
65
+ event_version: '1.0',
66
+ timestamp: new Date().toISOString(),
67
+ agent: 'mynitor-cli-mock',
68
+ workflow: 'diagnostic-mock',
69
+ provider: 'openai',
70
+ model: 'gpt-4o',
71
+ input_tokens: 150,
72
+ output_tokens: 450,
73
+ latency_ms: 1200,
74
+ status: 'success',
75
+ metadata: { type: 'diagnostic-mock' }
76
+ })
77
+ });
78
+ if (response.ok) {
79
+ console.log('✅ Mock event sent successfully!');
80
+ console.log('✨ Check your dashboard /events page to see the generated data.');
81
+ }
82
+ else {
83
+ const text = await response.text();
84
+ console.error(`❌ Failed: ${response.status} ${text}`);
85
+ }
86
+ }
87
+ catch (error) {
88
+ console.error('❌ Network Error:', error.message || error);
89
+ }
90
+ return;
91
+ }
14
92
  if (command === 'ping') {
15
93
  console.log('🚀 MyNitor: Sending verification signal to Cloud API...');
16
94
  try {
@@ -18,13 +96,7 @@ async function run() {
18
96
  apiKey,
19
97
  environment: 'onboarding-test'
20
98
  });
21
- // Trigger a manual event to verify connection
22
- // We use a custom internal method or just a standard track if available
23
- // In the current SDK, we can use the private sendEvent if it were public,
24
- // or just trigger instrument() and a small log.
25
- // For now, let's just use a fetch directly to verify connectivity
26
- // and trigger the onboarding checkmark.
27
- const endpoint = 'https://app.mynitor.ai/api/v1/events';
99
+ const endpoint = `${BASE_URL}/api/v1/events`;
28
100
  const response = await fetch(endpoint, {
29
101
  method: 'POST',
30
102
  headers: {
@@ -56,12 +128,12 @@ async function run() {
56
128
  }
57
129
  catch (error) {
58
130
  console.error('❌ Network Error: Could not reach MyNitor Cloud.');
59
- console.error(error);
131
+ console.error(error.message || error);
60
132
  process.exit(1);
61
133
  }
62
134
  }
63
135
  else {
64
- console.log('Usage: npx @mynitorai/sdk ping');
136
+ console.log('Usage: npx @mynitorai/sdk [ping|doctor|mock]');
65
137
  }
66
138
  }
67
139
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mynitorai/sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Production safety and observability for AI systems.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -33,4 +33,4 @@
33
33
  "openai": "^4.0.0",
34
34
  "@types/node": "^20.0.0"
35
35
  }
36
- }
36
+ }