@visibe.ai/node 0.1.9 → 0.1.11
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/index.js +21 -11
- package/dist/esm/index.js +21 -11
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -53,7 +53,9 @@ function patchFramework(framework, client) {
|
|
|
53
53
|
case 'openai': {
|
|
54
54
|
const openaiModule = require('openai');
|
|
55
55
|
_originalOpenAI = openaiModule.OpenAI;
|
|
56
|
-
|
|
56
|
+
// Named 'OpenAI' so client.constructor.name === 'OpenAI' after construction.
|
|
57
|
+
// applyIntegration() in client.ts uses constructor.name to detect the client type.
|
|
58
|
+
const PatchedOpenAI = class OpenAI extends _originalOpenAI {
|
|
57
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
60
|
constructor(...args) {
|
|
59
61
|
super(...args);
|
|
@@ -63,16 +65,20 @@ function patchFramework(framework, client) {
|
|
|
63
65
|
catch { /* never crash new OpenAI() */ }
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
|
-
|
|
68
|
+
// Use defineProperty because openai exports OpenAI/default as getter-only properties
|
|
69
|
+
// (no setter). Direct assignment silently fails in that case.
|
|
70
|
+
const setProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
71
|
+
setProp(openaiModule, 'OpenAI', PatchedOpenAI);
|
|
67
72
|
// Also patch .default so that `import OpenAI from 'openai'` (esModuleInterop)
|
|
68
73
|
// picks up the instrumented class — TypeScript compiles default imports to .default.
|
|
69
|
-
openaiModule
|
|
74
|
+
setProp(openaiModule, 'default', PatchedOpenAI);
|
|
70
75
|
break;
|
|
71
76
|
}
|
|
72
77
|
case 'anthropic': {
|
|
73
78
|
const anthropicModule = require('@anthropic-ai/sdk');
|
|
74
79
|
_originalAnthropic = anthropicModule.Anthropic;
|
|
75
|
-
|
|
80
|
+
// Named 'Anthropic' so constructor.name check in applyIntegration() matches.
|
|
81
|
+
const PatchedAnthropic = class Anthropic extends _originalAnthropic {
|
|
76
82
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
83
|
constructor(...args) {
|
|
78
84
|
super(...args);
|
|
@@ -82,15 +88,17 @@ function patchFramework(framework, client) {
|
|
|
82
88
|
catch { /* never crash new Anthropic() */ }
|
|
83
89
|
}
|
|
84
90
|
};
|
|
85
|
-
|
|
91
|
+
// Same getter-only issue as openai — use defineProperty.
|
|
92
|
+
const setAnthropicProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
93
|
+
setAnthropicProp(anthropicModule, 'Anthropic', PatchedAnthropic);
|
|
86
94
|
// Also patch .default for esModuleInterop default import support.
|
|
87
|
-
anthropicModule
|
|
95
|
+
setAnthropicProp(anthropicModule, 'default', PatchedAnthropic);
|
|
88
96
|
break;
|
|
89
97
|
}
|
|
90
98
|
case 'bedrock': {
|
|
91
99
|
const bedrockModule = require('@aws-sdk/client-bedrock-runtime');
|
|
92
100
|
_originalBedrockClient = bedrockModule.BedrockRuntimeClient;
|
|
93
|
-
bedrockModule.BedrockRuntimeClient = class extends _originalBedrockClient {
|
|
101
|
+
bedrockModule.BedrockRuntimeClient = class BedrockRuntimeClient extends _originalBedrockClient {
|
|
94
102
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
103
|
constructor(...args) {
|
|
96
104
|
super(...args);
|
|
@@ -179,16 +187,18 @@ async function shutdown() {
|
|
|
179
187
|
// Restore patched constructors so the SDK leaves no trace after shutdown.
|
|
180
188
|
try {
|
|
181
189
|
if (_originalOpenAI) {
|
|
182
|
-
require('openai')
|
|
183
|
-
|
|
190
|
+
const m = require('openai');
|
|
191
|
+
Object.defineProperty(m, 'OpenAI', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
192
|
+
Object.defineProperty(m, 'default', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
184
193
|
_originalOpenAI = null;
|
|
185
194
|
}
|
|
186
195
|
}
|
|
187
196
|
catch { /* package may have been unloaded */ }
|
|
188
197
|
try {
|
|
189
198
|
if (_originalAnthropic) {
|
|
190
|
-
require('@anthropic-ai/sdk')
|
|
191
|
-
|
|
199
|
+
const m = require('@anthropic-ai/sdk');
|
|
200
|
+
Object.defineProperty(m, 'Anthropic', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
201
|
+
Object.defineProperty(m, 'default', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
192
202
|
_originalAnthropic = null;
|
|
193
203
|
}
|
|
194
204
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -47,7 +47,9 @@ function patchFramework(framework, client) {
|
|
|
47
47
|
case 'openai': {
|
|
48
48
|
const openaiModule = require('openai');
|
|
49
49
|
_originalOpenAI = openaiModule.OpenAI;
|
|
50
|
-
|
|
50
|
+
// Named 'OpenAI' so client.constructor.name === 'OpenAI' after construction.
|
|
51
|
+
// applyIntegration() in client.ts uses constructor.name to detect the client type.
|
|
52
|
+
const PatchedOpenAI = class OpenAI extends _originalOpenAI {
|
|
51
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
54
|
constructor(...args) {
|
|
53
55
|
super(...args);
|
|
@@ -57,16 +59,20 @@ function patchFramework(framework, client) {
|
|
|
57
59
|
catch { /* never crash new OpenAI() */ }
|
|
58
60
|
}
|
|
59
61
|
};
|
|
60
|
-
|
|
62
|
+
// Use defineProperty because openai exports OpenAI/default as getter-only properties
|
|
63
|
+
// (no setter). Direct assignment silently fails in that case.
|
|
64
|
+
const setProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
65
|
+
setProp(openaiModule, 'OpenAI', PatchedOpenAI);
|
|
61
66
|
// Also patch .default so that `import OpenAI from 'openai'` (esModuleInterop)
|
|
62
67
|
// picks up the instrumented class — TypeScript compiles default imports to .default.
|
|
63
|
-
openaiModule
|
|
68
|
+
setProp(openaiModule, 'default', PatchedOpenAI);
|
|
64
69
|
break;
|
|
65
70
|
}
|
|
66
71
|
case 'anthropic': {
|
|
67
72
|
const anthropicModule = require('@anthropic-ai/sdk');
|
|
68
73
|
_originalAnthropic = anthropicModule.Anthropic;
|
|
69
|
-
|
|
74
|
+
// Named 'Anthropic' so constructor.name check in applyIntegration() matches.
|
|
75
|
+
const PatchedAnthropic = class Anthropic extends _originalAnthropic {
|
|
70
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
77
|
constructor(...args) {
|
|
72
78
|
super(...args);
|
|
@@ -76,15 +82,17 @@ function patchFramework(framework, client) {
|
|
|
76
82
|
catch { /* never crash new Anthropic() */ }
|
|
77
83
|
}
|
|
78
84
|
};
|
|
79
|
-
|
|
85
|
+
// Same getter-only issue as openai — use defineProperty.
|
|
86
|
+
const setAnthropicProp = (obj, key, val) => Object.defineProperty(obj, key, { value: val, configurable: true, writable: true, enumerable: true });
|
|
87
|
+
setAnthropicProp(anthropicModule, 'Anthropic', PatchedAnthropic);
|
|
80
88
|
// Also patch .default for esModuleInterop default import support.
|
|
81
|
-
anthropicModule
|
|
89
|
+
setAnthropicProp(anthropicModule, 'default', PatchedAnthropic);
|
|
82
90
|
break;
|
|
83
91
|
}
|
|
84
92
|
case 'bedrock': {
|
|
85
93
|
const bedrockModule = require('@aws-sdk/client-bedrock-runtime');
|
|
86
94
|
_originalBedrockClient = bedrockModule.BedrockRuntimeClient;
|
|
87
|
-
bedrockModule.BedrockRuntimeClient = class extends _originalBedrockClient {
|
|
95
|
+
bedrockModule.BedrockRuntimeClient = class BedrockRuntimeClient extends _originalBedrockClient {
|
|
88
96
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
97
|
constructor(...args) {
|
|
90
98
|
super(...args);
|
|
@@ -173,16 +181,18 @@ export async function shutdown() {
|
|
|
173
181
|
// Restore patched constructors so the SDK leaves no trace after shutdown.
|
|
174
182
|
try {
|
|
175
183
|
if (_originalOpenAI) {
|
|
176
|
-
require('openai')
|
|
177
|
-
|
|
184
|
+
const m = require('openai');
|
|
185
|
+
Object.defineProperty(m, 'OpenAI', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
186
|
+
Object.defineProperty(m, 'default', { value: _originalOpenAI, configurable: true, writable: true, enumerable: true });
|
|
178
187
|
_originalOpenAI = null;
|
|
179
188
|
}
|
|
180
189
|
}
|
|
181
190
|
catch { /* package may have been unloaded */ }
|
|
182
191
|
try {
|
|
183
192
|
if (_originalAnthropic) {
|
|
184
|
-
require('@anthropic-ai/sdk')
|
|
185
|
-
|
|
193
|
+
const m = require('@anthropic-ai/sdk');
|
|
194
|
+
Object.defineProperty(m, 'Anthropic', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
195
|
+
Object.defineProperty(m, 'default', { value: _originalAnthropic, configurable: true, writable: true, enumerable: true });
|
|
186
196
|
_originalAnthropic = null;
|
|
187
197
|
}
|
|
188
198
|
}
|
package/package.json
CHANGED