@dropout-ai/runtime 0.2.0 → 0.2.1
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/package.json +1 -1
- package/src/index.js +55 -29
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
const originalFetch = global.fetch;
|
|
2
|
+
|
|
3
|
+
// 4. Internal telemetry sender (Neutral naming)
|
|
4
|
+
async function safeSendTelemetry(payload) {
|
|
5
|
+
try {
|
|
6
|
+
await originalFetch('http://localhost:4000/capture', {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: { 'Content-Type': 'application/json' },
|
|
9
|
+
body: JSON.stringify(payload)
|
|
10
|
+
});
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// Fail silently
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
1
16
|
(function () {
|
|
2
17
|
// 1. Guard global.fetch existence and idempotency
|
|
3
18
|
if (typeof global.fetch !== 'function' || global.fetch.__dropout_patched__) {
|
|
4
19
|
return;
|
|
5
20
|
}
|
|
6
21
|
|
|
7
|
-
const originalFetch = global.fetch;
|
|
8
|
-
|
|
9
22
|
// 2. Default Configuration
|
|
10
23
|
let config = {
|
|
11
24
|
version: 1,
|
|
@@ -27,18 +40,6 @@
|
|
|
27
40
|
}
|
|
28
41
|
}, 0);
|
|
29
42
|
|
|
30
|
-
// 4. Internal telemetry sender (Neutral naming)
|
|
31
|
-
async function safeSendTelemetry(payload) {
|
|
32
|
-
try {
|
|
33
|
-
await originalFetch('http://localhost:4000/capture', {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: { 'Content-Type': 'application/json' },
|
|
36
|
-
body: JSON.stringify(payload)
|
|
37
|
-
});
|
|
38
|
-
} catch (e) {
|
|
39
|
-
// Fail silently
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
43
|
|
|
43
44
|
// 5. Detection Helpers
|
|
44
45
|
function matchesKnownProvider(url) {
|
|
@@ -131,21 +132,46 @@
|
|
|
131
132
|
};
|
|
132
133
|
|
|
133
134
|
global.fetch.__dropout_patched__ = true;
|
|
135
|
+
})();
|
|
134
136
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
// 11. Manual capture (combo mode)
|
|
138
|
+
async function capture(target, options = {}) {
|
|
139
|
+
const start = Date.now();
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const result =
|
|
143
|
+
typeof target === 'function'
|
|
144
|
+
? await target()
|
|
145
|
+
: await Promise.resolve(target);
|
|
146
|
+
|
|
147
|
+
const payload = {
|
|
148
|
+
provider: options.provider || 'manual',
|
|
149
|
+
model: options.model,
|
|
150
|
+
prompt: options.prompt,
|
|
151
|
+
output: typeof result === 'string'
|
|
152
|
+
? result
|
|
153
|
+
: JSON.stringify(result).slice(0, 20000),
|
|
154
|
+
latency_ms: Date.now() - start,
|
|
155
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
156
|
+
mode: 'manual'
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
setTimeout(() => safeSendTelemetry(payload), 0);
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
const payload = {
|
|
163
|
+
provider: options.provider || 'manual',
|
|
164
|
+
error: error?.message || String(error),
|
|
165
|
+
latency_ms: Date.now() - start,
|
|
166
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
167
|
+
mode: 'manual'
|
|
149
168
|
};
|
|
169
|
+
|
|
170
|
+
setTimeout(() => safeSendTelemetry(payload), 0);
|
|
171
|
+
throw error;
|
|
150
172
|
}
|
|
151
|
-
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
module.exports = {
|
|
176
|
+
capture
|
|
177
|
+
};
|