@visibe.ai/node 0.1.8 → 0.1.10
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/cjs/api.js +5 -0
- package/dist/cjs/index.js +20 -4
- package/dist/esm/api.js +5 -0
- package/dist/esm/index.js +20 -4
- package/package.json +1 -1
package/dist/cjs/api.js
CHANGED
|
@@ -12,6 +12,11 @@ class APIClient {
|
|
|
12
12
|
if (!this._enabled) {
|
|
13
13
|
process.emitWarning('[Visibe] No API key provided — tracing is disabled. Set VISIBE_API_KEY or pass apiKey= to enable.', { type: 'VisibleSDKWarning', code: 'VISIBE_NO_API_KEY' });
|
|
14
14
|
}
|
|
15
|
+
else if (options.apiKey &&
|
|
16
|
+
!options.apiKey.startsWith('sk_live_') &&
|
|
17
|
+
!options.apiKey.startsWith('sk_test_')) {
|
|
18
|
+
process.emitWarning('[Visibe] API key format unrecognized (expected sk_live_* or sk_test_*).', { type: 'VisibleSDKWarning', code: 'VISIBE_INVALID_KEY_FORMAT' });
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
// ---------------------------------------------------------------------------
|
|
17
22
|
// validateKey() — called once at startup in the background.
|
package/dist/cjs/index.js
CHANGED
|
@@ -53,7 +53,7 @@ function patchFramework(framework, client) {
|
|
|
53
53
|
case 'openai': {
|
|
54
54
|
const openaiModule = require('openai');
|
|
55
55
|
_originalOpenAI = openaiModule.OpenAI;
|
|
56
|
-
|
|
56
|
+
const PatchedOpenAI = class extends _originalOpenAI {
|
|
57
57
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
58
|
constructor(...args) {
|
|
59
59
|
super(...args);
|
|
@@ -63,12 +63,19 @@ function patchFramework(framework, client) {
|
|
|
63
63
|
catch { /* never crash new OpenAI() */ }
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
+
// Use defineProperty because openai exports OpenAI/default as getter-only properties
|
|
67
|
+
// (no setter). Direct assignment silently fails in that case.
|
|
68
|
+
const setProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
69
|
+
setProp(openaiModule, 'OpenAI', PatchedOpenAI);
|
|
70
|
+
// Also patch .default so that `import OpenAI from 'openai'` (esModuleInterop)
|
|
71
|
+
// picks up the instrumented class — TypeScript compiles default imports to .default.
|
|
72
|
+
setProp(openaiModule, 'default', PatchedOpenAI);
|
|
66
73
|
break;
|
|
67
74
|
}
|
|
68
75
|
case 'anthropic': {
|
|
69
76
|
const anthropicModule = require('@anthropic-ai/sdk');
|
|
70
77
|
_originalAnthropic = anthropicModule.Anthropic;
|
|
71
|
-
|
|
78
|
+
const PatchedAnthropic = class extends _originalAnthropic {
|
|
72
79
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
80
|
constructor(...args) {
|
|
74
81
|
super(...args);
|
|
@@ -78,6 +85,11 @@ function patchFramework(framework, client) {
|
|
|
78
85
|
catch { /* never crash new Anthropic() */ }
|
|
79
86
|
}
|
|
80
87
|
};
|
|
88
|
+
// Same getter-only issue as openai — use defineProperty.
|
|
89
|
+
const setAnthropicProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
90
|
+
setAnthropicProp(anthropicModule, 'Anthropic', PatchedAnthropic);
|
|
91
|
+
// Also patch .default for esModuleInterop default import support.
|
|
92
|
+
setAnthropicProp(anthropicModule, 'default', PatchedAnthropic);
|
|
81
93
|
break;
|
|
82
94
|
}
|
|
83
95
|
case 'bedrock': {
|
|
@@ -172,14 +184,18 @@ async function shutdown() {
|
|
|
172
184
|
// Restore patched constructors so the SDK leaves no trace after shutdown.
|
|
173
185
|
try {
|
|
174
186
|
if (_originalOpenAI) {
|
|
175
|
-
require('openai')
|
|
187
|
+
const m = require('openai');
|
|
188
|
+
Object.defineProperty(m, 'OpenAI', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
189
|
+
Object.defineProperty(m, 'default', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
176
190
|
_originalOpenAI = null;
|
|
177
191
|
}
|
|
178
192
|
}
|
|
179
193
|
catch { /* package may have been unloaded */ }
|
|
180
194
|
try {
|
|
181
195
|
if (_originalAnthropic) {
|
|
182
|
-
require('@anthropic-ai/sdk')
|
|
196
|
+
const m = require('@anthropic-ai/sdk');
|
|
197
|
+
Object.defineProperty(m, 'Anthropic', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
198
|
+
Object.defineProperty(m, 'default', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
183
199
|
_originalAnthropic = null;
|
|
184
200
|
}
|
|
185
201
|
}
|
package/dist/esm/api.js
CHANGED
|
@@ -9,6 +9,11 @@ export class APIClient {
|
|
|
9
9
|
if (!this._enabled) {
|
|
10
10
|
process.emitWarning('[Visibe] No API key provided — tracing is disabled. Set VISIBE_API_KEY or pass apiKey= to enable.', { type: 'VisibleSDKWarning', code: 'VISIBE_NO_API_KEY' });
|
|
11
11
|
}
|
|
12
|
+
else if (options.apiKey &&
|
|
13
|
+
!options.apiKey.startsWith('sk_live_') &&
|
|
14
|
+
!options.apiKey.startsWith('sk_test_')) {
|
|
15
|
+
process.emitWarning('[Visibe] API key format unrecognized (expected sk_live_* or sk_test_*).', { type: 'VisibleSDKWarning', code: 'VISIBE_INVALID_KEY_FORMAT' });
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
// ---------------------------------------------------------------------------
|
|
14
19
|
// validateKey() — called once at startup in the background.
|
package/dist/esm/index.js
CHANGED
|
@@ -47,7 +47,7 @@ function patchFramework(framework, client) {
|
|
|
47
47
|
case 'openai': {
|
|
48
48
|
const openaiModule = require('openai');
|
|
49
49
|
_originalOpenAI = openaiModule.OpenAI;
|
|
50
|
-
|
|
50
|
+
const PatchedOpenAI = class extends _originalOpenAI {
|
|
51
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
52
|
constructor(...args) {
|
|
53
53
|
super(...args);
|
|
@@ -57,12 +57,19 @@ function patchFramework(framework, client) {
|
|
|
57
57
|
catch { /* never crash new OpenAI() */ }
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
+
// Use defineProperty because openai exports OpenAI/default as getter-only properties
|
|
61
|
+
// (no setter). Direct assignment silently fails in that case.
|
|
62
|
+
const setProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
63
|
+
setProp(openaiModule, 'OpenAI', PatchedOpenAI);
|
|
64
|
+
// Also patch .default so that `import OpenAI from 'openai'` (esModuleInterop)
|
|
65
|
+
// picks up the instrumented class — TypeScript compiles default imports to .default.
|
|
66
|
+
setProp(openaiModule, 'default', PatchedOpenAI);
|
|
60
67
|
break;
|
|
61
68
|
}
|
|
62
69
|
case 'anthropic': {
|
|
63
70
|
const anthropicModule = require('@anthropic-ai/sdk');
|
|
64
71
|
_originalAnthropic = anthropicModule.Anthropic;
|
|
65
|
-
|
|
72
|
+
const PatchedAnthropic = class extends _originalAnthropic {
|
|
66
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
74
|
constructor(...args) {
|
|
68
75
|
super(...args);
|
|
@@ -72,6 +79,11 @@ function patchFramework(framework, client) {
|
|
|
72
79
|
catch { /* never crash new Anthropic() */ }
|
|
73
80
|
}
|
|
74
81
|
};
|
|
82
|
+
// Same getter-only issue as openai — use defineProperty.
|
|
83
|
+
const setAnthropicProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
84
|
+
setAnthropicProp(anthropicModule, 'Anthropic', PatchedAnthropic);
|
|
85
|
+
// Also patch .default for esModuleInterop default import support.
|
|
86
|
+
setAnthropicProp(anthropicModule, 'default', PatchedAnthropic);
|
|
75
87
|
break;
|
|
76
88
|
}
|
|
77
89
|
case 'bedrock': {
|
|
@@ -166,14 +178,18 @@ export async function shutdown() {
|
|
|
166
178
|
// Restore patched constructors so the SDK leaves no trace after shutdown.
|
|
167
179
|
try {
|
|
168
180
|
if (_originalOpenAI) {
|
|
169
|
-
require('openai')
|
|
181
|
+
const m = require('openai');
|
|
182
|
+
Object.defineProperty(m, 'OpenAI', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
183
|
+
Object.defineProperty(m, 'default', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
170
184
|
_originalOpenAI = null;
|
|
171
185
|
}
|
|
172
186
|
}
|
|
173
187
|
catch { /* package may have been unloaded */ }
|
|
174
188
|
try {
|
|
175
189
|
if (_originalAnthropic) {
|
|
176
|
-
require('@anthropic-ai/sdk')
|
|
190
|
+
const m = require('@anthropic-ai/sdk');
|
|
191
|
+
Object.defineProperty(m, 'Anthropic', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
192
|
+
Object.defineProperty(m, 'default', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
177
193
|
_originalAnthropic = null;
|
|
178
194
|
}
|
|
179
195
|
}
|
package/package.json
CHANGED