@raindrop-ai/ai-sdk 0.0.33 → 0.0.34
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 +22 -0
- package/dist/{chunk-FIX66Y7M.mjs → chunk-OLOFN54C.mjs} +440 -77
- package/dist/{index-Dcf4FPZL.d.mts → index-HYjRP6nV.d.mts} +112 -2
- package/dist/{index-Dcf4FPZL.d.ts → index-HYjRP6nV.d.ts} +112 -2
- package/dist/index.browser.d.mts +112 -2
- package/dist/index.browser.d.ts +112 -2
- package/dist/index.browser.js +443 -76
- package/dist/index.browser.mjs +440 -77
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +443 -76
- package/dist/index.node.mjs +1 -1
- package/dist/index.workers.d.mts +1 -1
- package/dist/index.workers.d.ts +1 -1
- package/dist/index.workers.js +443 -76
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
2
|
|
|
3
|
-
// ../core/dist/chunk-
|
|
3
|
+
// ../core/dist/chunk-U5HUTMR5.js
|
|
4
4
|
function getCrypto() {
|
|
5
5
|
const c = globalThis.crypto;
|
|
6
6
|
return c;
|
|
@@ -55,6 +55,8 @@ function base64Encode(bytes) {
|
|
|
55
55
|
}
|
|
56
56
|
return out;
|
|
57
57
|
}
|
|
58
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
59
|
+
var MAX_RETRY_DELAY_MS = 3e4;
|
|
58
60
|
function wait(ms) {
|
|
59
61
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
60
62
|
}
|
|
@@ -62,6 +64,46 @@ function formatEndpoint(endpoint) {
|
|
|
62
64
|
if (!endpoint) return void 0;
|
|
63
65
|
return endpoint.endsWith("/") ? endpoint : `${endpoint}/`;
|
|
64
66
|
}
|
|
67
|
+
function redactUrlForLog(url) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = new URL(url);
|
|
70
|
+
parsed.username = "";
|
|
71
|
+
parsed.password = "";
|
|
72
|
+
parsed.search = "";
|
|
73
|
+
parsed.hash = "";
|
|
74
|
+
return parsed.toString();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return "<unparseable-url>";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var RATE_LIMITED_LOG_INTERVAL_MS = 3e4;
|
|
80
|
+
var rateLimitedLogLast = /* @__PURE__ */ new Map();
|
|
81
|
+
function rateLimitedLog(key, log) {
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const last = rateLimitedLogLast.get(key);
|
|
84
|
+
if (last !== void 0 && now - last < RATE_LIMITED_LOG_INTERVAL_MS) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
rateLimitedLogLast.set(key, now);
|
|
88
|
+
log();
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
async function raceWithTimeout(promise, timeoutMs) {
|
|
92
|
+
let timer;
|
|
93
|
+
const settledInTime = await Promise.race([
|
|
94
|
+
promise.then(
|
|
95
|
+
() => true,
|
|
96
|
+
() => true
|
|
97
|
+
),
|
|
98
|
+
new Promise((resolve) => {
|
|
99
|
+
var _a;
|
|
100
|
+
timer = setTimeout(() => resolve(false), Math.max(0, timeoutMs));
|
|
101
|
+
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
102
|
+
})
|
|
103
|
+
]);
|
|
104
|
+
if (timer) clearTimeout(timer);
|
|
105
|
+
return settledInTime;
|
|
106
|
+
}
|
|
65
107
|
function parseRetryAfter(headers) {
|
|
66
108
|
var _a;
|
|
67
109
|
const value = (_a = headers.get("Retry-After")) != null ? _a : headers.get("retry-after");
|
|
@@ -78,12 +120,12 @@ function parseRetryAfter(headers) {
|
|
|
78
120
|
function getRetryDelayMs(attemptNumber, previousError) {
|
|
79
121
|
if (previousError && typeof previousError === "object" && previousError !== null && "retryAfterMs" in previousError) {
|
|
80
122
|
const v = previousError.retryAfterMs;
|
|
81
|
-
if (typeof v === "number") return Math.max(0, v);
|
|
123
|
+
if (typeof v === "number") return Math.min(Math.max(0, v), MAX_RETRY_DELAY_MS);
|
|
82
124
|
}
|
|
83
125
|
if (attemptNumber <= 1) return 0;
|
|
84
126
|
const base = 500;
|
|
85
127
|
const factor = Math.pow(2, attemptNumber - 2);
|
|
86
|
-
return base * factor;
|
|
128
|
+
return Math.min(base * factor, MAX_RETRY_DELAY_MS);
|
|
87
129
|
}
|
|
88
130
|
async function withRetry(operation, opName2, opts) {
|
|
89
131
|
const prefix = opts.sdkName ? `[raindrop-ai/${opts.sdkName}]` : "[raindrop-ai/core]";
|
|
@@ -118,7 +160,9 @@ async function withRetry(operation, opName2, opts) {
|
|
|
118
160
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
119
161
|
}
|
|
120
162
|
async function postJson(url, body, headers, opts) {
|
|
121
|
-
|
|
163
|
+
var _a;
|
|
164
|
+
const opName2 = `POST ${redactUrlForLog(url)}`;
|
|
165
|
+
const timeoutMs = (_a = opts.timeoutMs) != null ? _a : DEFAULT_REQUEST_TIMEOUT_MS;
|
|
122
166
|
await withRetry(
|
|
123
167
|
async () => {
|
|
124
168
|
const resp = await fetch(url, {
|
|
@@ -127,7 +171,8 @@ async function postJson(url, body, headers, opts) {
|
|
|
127
171
|
"Content-Type": "application/json",
|
|
128
172
|
...headers
|
|
129
173
|
},
|
|
130
|
-
body: JSON.stringify(body)
|
|
174
|
+
body: JSON.stringify(body),
|
|
175
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
131
176
|
});
|
|
132
177
|
if (!resp.ok) {
|
|
133
178
|
const text = await resp.text().catch(() => "");
|
|
@@ -144,6 +189,27 @@ async function postJson(url, body, headers, opts) {
|
|
|
144
189
|
opts
|
|
145
190
|
);
|
|
146
191
|
}
|
|
192
|
+
var DEFAULT_MAX_TEXT_FIELD_CHARS = 1e6;
|
|
193
|
+
var TRUNCATION_MARKER = "...[truncated by raindrop]";
|
|
194
|
+
var currentDefaultMaxTextFieldChars = DEFAULT_MAX_TEXT_FIELD_CHARS;
|
|
195
|
+
function resolveMaxTextFieldChars(value) {
|
|
196
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
197
|
+
return Math.floor(value);
|
|
198
|
+
}
|
|
199
|
+
return currentDefaultMaxTextFieldChars;
|
|
200
|
+
}
|
|
201
|
+
function truncateToLimit(text, limit) {
|
|
202
|
+
if (limit > TRUNCATION_MARKER.length) {
|
|
203
|
+
return text.slice(0, limit - TRUNCATION_MARKER.length) + TRUNCATION_MARKER;
|
|
204
|
+
}
|
|
205
|
+
return text.slice(0, Math.max(0, limit));
|
|
206
|
+
}
|
|
207
|
+
function capText(value, limit) {
|
|
208
|
+
if (typeof value !== "string") return value;
|
|
209
|
+
const max = limit != null ? limit : currentDefaultMaxTextFieldChars;
|
|
210
|
+
if (value.length <= max) return value;
|
|
211
|
+
return truncateToLimit(value, max);
|
|
212
|
+
}
|
|
147
213
|
var SpanStatusCode = {
|
|
148
214
|
UNSET: 0,
|
|
149
215
|
ERROR: 2
|
|
@@ -331,6 +397,8 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
331
397
|
).catch(() => {
|
|
332
398
|
});
|
|
333
399
|
}
|
|
400
|
+
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
401
|
+
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
334
402
|
function mergePatches(target, source) {
|
|
335
403
|
var _a, _b, _c, _d;
|
|
336
404
|
const out = { ...target, ...source };
|
|
@@ -348,6 +416,7 @@ var EventShipper = class {
|
|
|
348
416
|
this.sticky = /* @__PURE__ */ new Map();
|
|
349
417
|
this.timers = /* @__PURE__ */ new Map();
|
|
350
418
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
419
|
+
this.hasShutdown = false;
|
|
351
420
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
352
421
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
353
422
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
@@ -357,6 +426,7 @@ var EventShipper = class {
|
|
|
357
426
|
this.sdkName = (_d = opts.sdkName) != null ? _d : "core";
|
|
358
427
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
359
428
|
this.defaultEventName = (_e = opts.defaultEventName) != null ? _e : "ai_generation";
|
|
429
|
+
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
360
430
|
this.localDebuggerUrl = (_f = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _f : void 0;
|
|
361
431
|
if (this.debug && this.localDebuggerUrl) {
|
|
362
432
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
@@ -379,10 +449,52 @@ var EventShipper = class {
|
|
|
379
449
|
authHeaders() {
|
|
380
450
|
return this.writeKey ? { Authorization: `Bearer ${this.writeKey}` } : {};
|
|
381
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Build the retry/timeout options for one POST, honoring the shutdown
|
|
454
|
+
* deadline. Returns `null` when the shutdown drain window is exhausted —
|
|
455
|
+
* the caller must drop the payload (with a rate-limited warning) instead
|
|
456
|
+
* of issuing a request that could outlive process exit.
|
|
457
|
+
*
|
|
458
|
+
* Checked fresh on EVERY send, so a shutdown that begins while the flush
|
|
459
|
+
* path is mid-drain takes effect immediately: no further retries, and the
|
|
460
|
+
* per-attempt timeout is clamped to the remaining window. After
|
|
461
|
+
* `shutdown()` returns (deadline cleared, `hasShutdown` still set),
|
|
462
|
+
* sends — late callers, or flush work the deadline abandoned mid-drain —
|
|
463
|
+
* run as a single short attempt rather than regaining the full retry
|
|
464
|
+
* schedule.
|
|
465
|
+
*/
|
|
466
|
+
requestOpts() {
|
|
467
|
+
if (this.shutdownDeadlineAt !== void 0) {
|
|
468
|
+
const remainingMs = this.shutdownDeadlineAt - Date.now();
|
|
469
|
+
if (remainingMs <= 0) return null;
|
|
470
|
+
return {
|
|
471
|
+
maxAttempts: 1,
|
|
472
|
+
debug: this.debug,
|
|
473
|
+
sdkName: this.sdkName,
|
|
474
|
+
timeoutMs: Math.min(DEFAULT_REQUEST_TIMEOUT_MS, remainingMs)
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
if (this.hasShutdown) {
|
|
478
|
+
return {
|
|
479
|
+
maxAttempts: 1,
|
|
480
|
+
debug: this.debug,
|
|
481
|
+
sdkName: this.sdkName,
|
|
482
|
+
timeoutMs: POST_SHUTDOWN_TIMEOUT_MS
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return { maxAttempts: 3, debug: this.debug, sdkName: this.sdkName };
|
|
486
|
+
}
|
|
382
487
|
async patch(eventId, patch) {
|
|
383
488
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
384
489
|
if (!this.enabled) return;
|
|
385
490
|
if (!eventId || !eventId.trim()) return;
|
|
491
|
+
const maxChars = resolveMaxTextFieldChars(this.maxTextFieldCharsOpt);
|
|
492
|
+
if (typeof patch.input === "string" && patch.input.length > maxChars) {
|
|
493
|
+
patch = { ...patch, input: capText(patch.input, maxChars) };
|
|
494
|
+
}
|
|
495
|
+
if (typeof patch.output === "string" && patch.output.length > maxChars) {
|
|
496
|
+
patch = { ...patch, output: capText(patch.output, maxChars) };
|
|
497
|
+
}
|
|
386
498
|
if (this.debug) {
|
|
387
499
|
console.log(`${this.prefix} queue patch`, {
|
|
388
500
|
eventId,
|
|
@@ -429,9 +541,16 @@ var EventShipper = class {
|
|
|
429
541
|
})));
|
|
430
542
|
}
|
|
431
543
|
async shutdown() {
|
|
432
|
-
|
|
433
|
-
this.
|
|
434
|
-
|
|
544
|
+
this.hasShutdown = true;
|
|
545
|
+
this.shutdownDeadlineAt = Date.now() + SHUTDOWN_DEADLINE_MS;
|
|
546
|
+
try {
|
|
547
|
+
for (const t of this.timers.values()) clearTimeout(t);
|
|
548
|
+
this.timers.clear();
|
|
549
|
+
const settled = await raceWithTimeout(this.flush(), SHUTDOWN_DEADLINE_MS);
|
|
550
|
+
if (!settled) this.warnShutdownDrop("in-flight request(s) at shutdown");
|
|
551
|
+
} finally {
|
|
552
|
+
this.shutdownDeadlineAt = void 0;
|
|
553
|
+
}
|
|
435
554
|
}
|
|
436
555
|
async trackSignal(signal) {
|
|
437
556
|
var _a, _b;
|
|
@@ -453,15 +572,19 @@ var EventShipper = class {
|
|
|
453
572
|
];
|
|
454
573
|
if (!this.writeKey) return;
|
|
455
574
|
const url = `${this.baseUrl}signals/track`;
|
|
575
|
+
const opts = this.requestOpts();
|
|
576
|
+
if (!opts) {
|
|
577
|
+
this.warnShutdownDrop("signal");
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
456
580
|
try {
|
|
457
|
-
await postJson(url, body, this.authHeaders(),
|
|
458
|
-
maxAttempts: 3,
|
|
459
|
-
debug: this.debug,
|
|
460
|
-
sdkName: this.sdkName
|
|
461
|
-
});
|
|
581
|
+
await postJson(url, body, this.authHeaders(), opts);
|
|
462
582
|
} catch (err) {
|
|
463
583
|
const msg = err instanceof Error ? err.message : String(err);
|
|
464
|
-
|
|
584
|
+
rateLimitedLog(
|
|
585
|
+
`${this.prefix}.send_signal_failed`,
|
|
586
|
+
() => console.warn(`${this.prefix} failed to send signal (dropping): ${msg}`)
|
|
587
|
+
);
|
|
465
588
|
}
|
|
466
589
|
}
|
|
467
590
|
async identify(users) {
|
|
@@ -485,17 +608,27 @@ var EventShipper = class {
|
|
|
485
608
|
if (!this.writeKey) return;
|
|
486
609
|
if (body.length === 0) return;
|
|
487
610
|
const url = `${this.baseUrl}users/identify`;
|
|
611
|
+
const opts = this.requestOpts();
|
|
612
|
+
if (!opts) {
|
|
613
|
+
this.warnShutdownDrop("identify");
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
488
616
|
try {
|
|
489
|
-
await postJson(url, body, this.authHeaders(),
|
|
490
|
-
maxAttempts: 3,
|
|
491
|
-
debug: this.debug,
|
|
492
|
-
sdkName: this.sdkName
|
|
493
|
-
});
|
|
617
|
+
await postJson(url, body, this.authHeaders(), opts);
|
|
494
618
|
} catch (err) {
|
|
495
619
|
const msg = err instanceof Error ? err.message : String(err);
|
|
496
|
-
|
|
620
|
+
rateLimitedLog(
|
|
621
|
+
`${this.prefix}.send_identify_failed`,
|
|
622
|
+
() => console.warn(`${this.prefix} failed to send identify (dropping): ${msg}`)
|
|
623
|
+
);
|
|
497
624
|
}
|
|
498
625
|
}
|
|
626
|
+
warnShutdownDrop(what) {
|
|
627
|
+
rateLimitedLog(
|
|
628
|
+
`${this.prefix}.shutdown_deadline`,
|
|
629
|
+
() => console.warn(`${this.prefix} shutdown flush deadline exceeded; dropping ${what}`)
|
|
630
|
+
);
|
|
631
|
+
}
|
|
499
632
|
async flushOne(eventId) {
|
|
500
633
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
501
634
|
if (!this.enabled) return;
|
|
@@ -571,11 +704,13 @@ var EventShipper = class {
|
|
|
571
704
|
if (!isPending) this.sticky.delete(eventId);
|
|
572
705
|
return;
|
|
573
706
|
}
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
707
|
+
const opts = this.requestOpts();
|
|
708
|
+
if (!opts) {
|
|
709
|
+
this.warnShutdownDrop(`track_partial ${eventId}`);
|
|
710
|
+
if (!isPending) this.sticky.delete(eventId);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const p = postJson(url, payload, this.authHeaders(), opts);
|
|
579
714
|
this.inFlight.add(p);
|
|
580
715
|
try {
|
|
581
716
|
try {
|
|
@@ -585,7 +720,10 @@ var EventShipper = class {
|
|
|
585
720
|
}
|
|
586
721
|
} catch (err) {
|
|
587
722
|
const msg = err instanceof Error ? err.message : String(err);
|
|
588
|
-
|
|
723
|
+
rateLimitedLog(
|
|
724
|
+
`${this.prefix}.send_track_partial_failed`,
|
|
725
|
+
() => console.warn(`${this.prefix} failed to send track_partial (dropping): ${msg}`)
|
|
726
|
+
);
|
|
589
727
|
}
|
|
590
728
|
} finally {
|
|
591
729
|
this.inFlight.delete(p);
|
|
@@ -684,10 +822,24 @@ function redactJsonAttributeValue(key, value) {
|
|
|
684
822
|
if (scrubbedJson === json) return void 0;
|
|
685
823
|
return { stringValue: scrubbedJson };
|
|
686
824
|
}
|
|
825
|
+
function applyOtelSpanAttributeLimit(limit) {
|
|
826
|
+
var _a, _b;
|
|
827
|
+
try {
|
|
828
|
+
const raw = (_b = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env) == null ? void 0 : _b.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT;
|
|
829
|
+
if (!raw) return limit;
|
|
830
|
+
const parsed = Number.parseInt(raw, 10);
|
|
831
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
832
|
+
return Math.min(limit, parsed);
|
|
833
|
+
}
|
|
834
|
+
} catch (e) {
|
|
835
|
+
}
|
|
836
|
+
return limit;
|
|
837
|
+
}
|
|
687
838
|
var TraceShipper = class {
|
|
688
839
|
constructor(opts) {
|
|
689
840
|
this.queue = [];
|
|
690
841
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
842
|
+
this.hasShutdown = false;
|
|
691
843
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
692
844
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
693
845
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
@@ -707,6 +859,39 @@ var TraceShipper = class {
|
|
|
707
859
|
}
|
|
708
860
|
this.transformSpanHook = opts.transformSpan;
|
|
709
861
|
this.disableDefaultRedaction = opts.disableDefaultRedaction === true;
|
|
862
|
+
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Cap every string attribute value on the span. O(#attributes) length
|
|
866
|
+
* checks; only oversized values pay a slice. Runs AFTER the redaction
|
|
867
|
+
* pipeline so the default secret-scrub still sees parseable JSON in
|
|
868
|
+
* `ai.request.providerOptions` / `ai.response.providerMetadata` (capping
|
|
869
|
+
* first could cut a JSON blob mid-way, fail the parse, and ship secrets
|
|
870
|
+
* in the surviving prefix).
|
|
871
|
+
*
|
|
872
|
+
* A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored
|
|
873
|
+
* for span content, matching the Python SDK and the OTel SDK convention.
|
|
874
|
+
*/
|
|
875
|
+
capSpanAttributes(span) {
|
|
876
|
+
var _a;
|
|
877
|
+
const maxChars = applyOtelSpanAttributeLimit(
|
|
878
|
+
resolveMaxTextFieldChars(this.maxTextFieldCharsOpt)
|
|
879
|
+
);
|
|
880
|
+
const attrs = span.attributes;
|
|
881
|
+
if (!attrs || attrs.length === 0) return span;
|
|
882
|
+
let nextAttrs;
|
|
883
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
884
|
+
const attr = attrs[i];
|
|
885
|
+
const value = (_a = attr.value) == null ? void 0 : _a.stringValue;
|
|
886
|
+
if (typeof value !== "string" || value.length <= maxChars) continue;
|
|
887
|
+
if (!nextAttrs) nextAttrs = attrs.slice();
|
|
888
|
+
nextAttrs[i] = {
|
|
889
|
+
key: attr.key,
|
|
890
|
+
value: { ...attr.value, stringValue: capText(value, maxChars) }
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
if (!nextAttrs) return span;
|
|
894
|
+
return { ...span, attributes: nextAttrs };
|
|
710
895
|
}
|
|
711
896
|
/**
|
|
712
897
|
* Apply the user `transformSpan` hook (if any) followed by the default
|
|
@@ -740,7 +925,7 @@ var TraceShipper = class {
|
|
|
740
925
|
if (!this.disableDefaultRedaction) {
|
|
741
926
|
current = defaultTransformSpan(current);
|
|
742
927
|
}
|
|
743
|
-
return current;
|
|
928
|
+
return this.capSpanAttributes(current);
|
|
744
929
|
}
|
|
745
930
|
isDebugEnabled() {
|
|
746
931
|
return this.debug;
|
|
@@ -861,6 +1046,16 @@ var TraceShipper = class {
|
|
|
861
1046
|
while (this.queue.length > 0) {
|
|
862
1047
|
const batch = this.queue.splice(0, this.maxBatchSize);
|
|
863
1048
|
if (!this.writeKey) continue;
|
|
1049
|
+
const opts = this.requestOpts();
|
|
1050
|
+
if (!opts) {
|
|
1051
|
+
rateLimitedLog(
|
|
1052
|
+
`${this.prefix}.shutdown_deadline`,
|
|
1053
|
+
() => console.warn(
|
|
1054
|
+
`${this.prefix} shutdown flush deadline exceeded; dropping ${batch.length} spans`
|
|
1055
|
+
)
|
|
1056
|
+
);
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
864
1059
|
const body = buildExportTraceServiceRequest(batch, this.serviceName, this.serviceVersion);
|
|
865
1060
|
const url = `${this.baseUrl}traces`;
|
|
866
1061
|
if (this.debug) {
|
|
@@ -869,11 +1064,7 @@ var TraceShipper = class {
|
|
|
869
1064
|
endpoint: url
|
|
870
1065
|
});
|
|
871
1066
|
}
|
|
872
|
-
const p = postJson(url, body, this.authHeaders(),
|
|
873
|
-
maxAttempts: 3,
|
|
874
|
-
debug: this.debug,
|
|
875
|
-
sdkName: this.sdkName
|
|
876
|
-
});
|
|
1067
|
+
const p = postJson(url, body, this.authHeaders(), opts);
|
|
877
1068
|
this.inFlight.add(p);
|
|
878
1069
|
try {
|
|
879
1070
|
try {
|
|
@@ -881,21 +1072,61 @@ var TraceShipper = class {
|
|
|
881
1072
|
if (this.debug) console.log(`${this.prefix} sent ${batch.length} spans`);
|
|
882
1073
|
} catch (err) {
|
|
883
1074
|
const msg = err instanceof Error ? err.message : String(err);
|
|
884
|
-
|
|
1075
|
+
rateLimitedLog(
|
|
1076
|
+
`${this.prefix}.send_spans_failed`,
|
|
1077
|
+
() => console.warn(`${this.prefix} failed to send ${batch.length} spans: ${msg}`)
|
|
1078
|
+
);
|
|
885
1079
|
}
|
|
886
1080
|
} finally {
|
|
887
1081
|
this.inFlight.delete(p);
|
|
888
1082
|
}
|
|
889
1083
|
}
|
|
890
1084
|
}
|
|
1085
|
+
/** See EventShipper.requestOpts — same shutdown-budget semantics. */
|
|
1086
|
+
requestOpts() {
|
|
1087
|
+
if (this.shutdownDeadlineAt !== void 0) {
|
|
1088
|
+
const remainingMs = this.shutdownDeadlineAt - Date.now();
|
|
1089
|
+
if (remainingMs <= 0) return null;
|
|
1090
|
+
return {
|
|
1091
|
+
maxAttempts: 1,
|
|
1092
|
+
debug: this.debug,
|
|
1093
|
+
sdkName: this.sdkName,
|
|
1094
|
+
timeoutMs: Math.min(DEFAULT_REQUEST_TIMEOUT_MS, remainingMs)
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
if (this.hasShutdown) {
|
|
1098
|
+
return {
|
|
1099
|
+
maxAttempts: 1,
|
|
1100
|
+
debug: this.debug,
|
|
1101
|
+
sdkName: this.sdkName,
|
|
1102
|
+
timeoutMs: POST_SHUTDOWN_TIMEOUT_MS
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
return { maxAttempts: 3, debug: this.debug, sdkName: this.sdkName };
|
|
1106
|
+
}
|
|
891
1107
|
async shutdown() {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1108
|
+
this.hasShutdown = true;
|
|
1109
|
+
this.shutdownDeadlineAt = Date.now() + SHUTDOWN_DEADLINE_MS;
|
|
1110
|
+
try {
|
|
1111
|
+
if (this.timer) {
|
|
1112
|
+
clearTimeout(this.timer);
|
|
1113
|
+
this.timer = void 0;
|
|
1114
|
+
}
|
|
1115
|
+
const drain = async () => {
|
|
1116
|
+
await this.flush();
|
|
1117
|
+
await Promise.all([...this.inFlight].map((p) => p.catch(() => {
|
|
1118
|
+
})));
|
|
1119
|
+
};
|
|
1120
|
+
const settled = await raceWithTimeout(drain(), SHUTDOWN_DEADLINE_MS);
|
|
1121
|
+
if (!settled) {
|
|
1122
|
+
rateLimitedLog(
|
|
1123
|
+
`${this.prefix}.shutdown_deadline`,
|
|
1124
|
+
() => console.warn(`${this.prefix} shutdown flush deadline exceeded; abandoning in-flight spans`)
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
} finally {
|
|
1128
|
+
this.shutdownDeadlineAt = void 0;
|
|
895
1129
|
}
|
|
896
|
-
await this.flush();
|
|
897
|
-
await Promise.all([...this.inFlight].map((p) => p.catch(() => {
|
|
898
|
-
})));
|
|
899
1130
|
}
|
|
900
1131
|
};
|
|
901
1132
|
var NOOP_SPAN = {
|
|
@@ -1017,6 +1248,133 @@ async function* asyncGeneratorWithCurrent(span, gen) {
|
|
|
1017
1248
|
}
|
|
1018
1249
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
1019
1250
|
|
|
1251
|
+
// src/internal/truncation.ts
|
|
1252
|
+
var TRUNCATION_MARKER2 = "...[truncated by raindrop]";
|
|
1253
|
+
var DEFAULT_MAX_TEXT_FIELD_CHARS2 = 1e6;
|
|
1254
|
+
var MAX_DEPTH = 12;
|
|
1255
|
+
var configuredMaxTextFieldChars;
|
|
1256
|
+
function setMaxTextFieldChars(limit) {
|
|
1257
|
+
if (limit === void 0) return;
|
|
1258
|
+
if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) {
|
|
1259
|
+
configuredMaxTextFieldChars = Math.floor(limit);
|
|
1260
|
+
} else {
|
|
1261
|
+
console.warn(`[raindrop-ai] maxTextFieldChars=${String(limit)} ignored; must be > 0`);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
function otelEnvLimit() {
|
|
1265
|
+
var _a;
|
|
1266
|
+
if (typeof process === "undefined") return void 0;
|
|
1267
|
+
const raw = (_a = process.env) == null ? void 0 : _a.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT;
|
|
1268
|
+
if (!raw) return void 0;
|
|
1269
|
+
const parsed = Number.parseInt(raw, 10);
|
|
1270
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
1271
|
+
}
|
|
1272
|
+
function effectiveMaxTextFieldChars() {
|
|
1273
|
+
const base = configuredMaxTextFieldChars != null ? configuredMaxTextFieldChars : DEFAULT_MAX_TEXT_FIELD_CHARS2;
|
|
1274
|
+
const env = otelEnvLimit();
|
|
1275
|
+
return env !== void 0 && env < base ? env : base;
|
|
1276
|
+
}
|
|
1277
|
+
function truncateToLimit2(text, limit) {
|
|
1278
|
+
if (limit > TRUNCATION_MARKER2.length) {
|
|
1279
|
+
return text.slice(0, limit - TRUNCATION_MARKER2.length) + TRUNCATION_MARKER2;
|
|
1280
|
+
}
|
|
1281
|
+
return text.slice(0, limit);
|
|
1282
|
+
}
|
|
1283
|
+
function capText2(value, limit) {
|
|
1284
|
+
if (typeof value !== "string") return value;
|
|
1285
|
+
const max = limit != null ? limit : effectiveMaxTextFieldChars();
|
|
1286
|
+
if (value.length <= max) return value;
|
|
1287
|
+
return truncateToLimit2(value, max);
|
|
1288
|
+
}
|
|
1289
|
+
function boundedClone2(value, budget, depth) {
|
|
1290
|
+
var _a, _b;
|
|
1291
|
+
if (budget.remaining <= 0) return TRUNCATION_MARKER2;
|
|
1292
|
+
if (typeof value === "string") {
|
|
1293
|
+
if (value.length > budget.remaining) {
|
|
1294
|
+
const taken = value.slice(0, Math.max(0, budget.remaining)) + TRUNCATION_MARKER2;
|
|
1295
|
+
budget.remaining = 0;
|
|
1296
|
+
return taken;
|
|
1297
|
+
}
|
|
1298
|
+
budget.remaining -= Math.max(value.length, 1);
|
|
1299
|
+
return value;
|
|
1300
|
+
}
|
|
1301
|
+
if (value === null || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
1302
|
+
budget.remaining -= 8;
|
|
1303
|
+
return value;
|
|
1304
|
+
}
|
|
1305
|
+
if (typeof value !== "object") {
|
|
1306
|
+
budget.remaining -= 1;
|
|
1307
|
+
return value;
|
|
1308
|
+
}
|
|
1309
|
+
if (value instanceof Uint8Array) {
|
|
1310
|
+
const maxBytes = Math.max(0, Math.ceil(budget.remaining * 3 / 4));
|
|
1311
|
+
if (value.byteLength > maxBytes) {
|
|
1312
|
+
const taken = base64Encode(value.subarray(0, maxBytes)) + TRUNCATION_MARKER2;
|
|
1313
|
+
budget.remaining = 0;
|
|
1314
|
+
return taken;
|
|
1315
|
+
}
|
|
1316
|
+
const encoded = base64Encode(value);
|
|
1317
|
+
budget.remaining -= Math.max(encoded.length, 1);
|
|
1318
|
+
return encoded;
|
|
1319
|
+
}
|
|
1320
|
+
if (depth >= MAX_DEPTH) {
|
|
1321
|
+
budget.remaining -= 16;
|
|
1322
|
+
const name = (_b = (_a = value.constructor) == null ? void 0 : _a.name) != null ? _b : "object";
|
|
1323
|
+
return `<max depth: ${name}>`;
|
|
1324
|
+
}
|
|
1325
|
+
const toJSON = value.toJSON;
|
|
1326
|
+
if (typeof toJSON === "function") {
|
|
1327
|
+
budget.remaining -= 2;
|
|
1328
|
+
return boundedClone2(toJSON.call(value), budget, depth + 1);
|
|
1329
|
+
}
|
|
1330
|
+
if (Array.isArray(value)) {
|
|
1331
|
+
budget.remaining -= 2;
|
|
1332
|
+
const out2 = [];
|
|
1333
|
+
for (const item of value) {
|
|
1334
|
+
if (budget.remaining <= 0) {
|
|
1335
|
+
out2.push(TRUNCATION_MARKER2);
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1338
|
+
out2.push(boundedClone2(item, budget, depth + 1));
|
|
1339
|
+
}
|
|
1340
|
+
return out2;
|
|
1341
|
+
}
|
|
1342
|
+
budget.remaining -= 2;
|
|
1343
|
+
const out = {};
|
|
1344
|
+
for (const key in value) {
|
|
1345
|
+
if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
|
|
1346
|
+
if (budget.remaining <= 0) {
|
|
1347
|
+
out["..."] = TRUNCATION_MARKER2;
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
let cappedKey = key;
|
|
1351
|
+
if (key.length > budget.remaining) {
|
|
1352
|
+
cappedKey = key.slice(0, Math.max(0, budget.remaining)) + TRUNCATION_MARKER2;
|
|
1353
|
+
budget.remaining = 0;
|
|
1354
|
+
out[cappedKey] = TRUNCATION_MARKER2;
|
|
1355
|
+
break;
|
|
1356
|
+
}
|
|
1357
|
+
budget.remaining -= Math.max(key.length, 1);
|
|
1358
|
+
out[cappedKey] = boundedClone2(value[key], budget, depth + 1);
|
|
1359
|
+
}
|
|
1360
|
+
return out;
|
|
1361
|
+
}
|
|
1362
|
+
function boundedStringify(value, limit) {
|
|
1363
|
+
const max = limit != null ? limit : effectiveMaxTextFieldChars();
|
|
1364
|
+
try {
|
|
1365
|
+
if (typeof value === "string") {
|
|
1366
|
+
const text2 = JSON.stringify(capText2(value, max));
|
|
1367
|
+
return text2.length <= max ? text2 : truncateToLimit2(text2, max);
|
|
1368
|
+
}
|
|
1369
|
+
const pruned = boundedClone2(value, { remaining: max + TRUNCATION_MARKER2.length + 256 }, 0);
|
|
1370
|
+
const text = JSON.stringify(pruned);
|
|
1371
|
+
if (text === void 0) return void 0;
|
|
1372
|
+
return text.length <= max ? text : truncateToLimit2(text, max);
|
|
1373
|
+
} catch (e) {
|
|
1374
|
+
return void 0;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1020
1378
|
// src/internal/wrap/helpers.ts
|
|
1021
1379
|
function isRecord(value) {
|
|
1022
1380
|
return typeof value === "object" && value !== null;
|
|
@@ -1041,21 +1399,10 @@ function isModuleNamespace(obj) {
|
|
|
1041
1399
|
}
|
|
1042
1400
|
}
|
|
1043
1401
|
function safeJson(value) {
|
|
1044
|
-
|
|
1045
|
-
return JSON.stringify(value);
|
|
1046
|
-
} catch (e) {
|
|
1047
|
-
return void 0;
|
|
1048
|
-
}
|
|
1402
|
+
return boundedStringify(value);
|
|
1049
1403
|
}
|
|
1050
1404
|
function safeJsonWithUint8(value) {
|
|
1051
|
-
|
|
1052
|
-
return JSON.stringify(value, (_key, v) => {
|
|
1053
|
-
if (v instanceof Uint8Array) return base64Encode(v);
|
|
1054
|
-
return v;
|
|
1055
|
-
});
|
|
1056
|
-
} catch (e) {
|
|
1057
|
-
return void 0;
|
|
1058
|
-
}
|
|
1405
|
+
return boundedStringify(value);
|
|
1059
1406
|
}
|
|
1060
1407
|
function extractModelInfo(model) {
|
|
1061
1408
|
if (typeof model === "string") {
|
|
@@ -1951,7 +2298,10 @@ var RaindropTelemetryIntegration = class {
|
|
|
1951
2298
|
inputAttrs.push(
|
|
1952
2299
|
attrStringArray(
|
|
1953
2300
|
"ai.prompt.tools",
|
|
1954
|
-
event.stepTools.map((t) =>
|
|
2301
|
+
event.stepTools.map((t) => {
|
|
2302
|
+
var _a;
|
|
2303
|
+
return (_a = safeJsonWithUint8(t)) != null ? _a : "";
|
|
2304
|
+
})
|
|
1955
2305
|
)
|
|
1956
2306
|
);
|
|
1957
2307
|
}
|
|
@@ -1959,7 +2309,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
1959
2309
|
inputAttrs.push(
|
|
1960
2310
|
attrString(
|
|
1961
2311
|
"ai.prompt.toolChoice",
|
|
1962
|
-
|
|
2312
|
+
safeJsonWithUint8(event.stepToolChoice)
|
|
1963
2313
|
)
|
|
1964
2314
|
);
|
|
1965
2315
|
}
|
|
@@ -2015,7 +2365,9 @@ var RaindropTelemetryIntegration = class {
|
|
|
2015
2365
|
if (chunk.type === "text-delta") {
|
|
2016
2366
|
const delta = (_c = chunk.textDelta) != null ? _c : chunk.delta;
|
|
2017
2367
|
if (typeof delta === "string") {
|
|
2018
|
-
state.accumulatedText
|
|
2368
|
+
if (state.accumulatedText.length <= effectiveMaxTextFieldChars()) {
|
|
2369
|
+
state.accumulatedText += delta;
|
|
2370
|
+
}
|
|
2019
2371
|
this.emitLive(state, "text_delta", delta);
|
|
2020
2372
|
}
|
|
2021
2373
|
} else if (chunk.type === "reasoning" || chunk.type === "reasoning-delta") {
|
|
@@ -2034,7 +2386,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2034
2386
|
if (state.recordOutputs) {
|
|
2035
2387
|
outputAttrs.push(
|
|
2036
2388
|
attrString("ai.response.finishReason", event.finishReason),
|
|
2037
|
-
attrString("ai.response.text", (_a = event.text) != null ? _a : void 0),
|
|
2389
|
+
attrString("ai.response.text", capText2((_a = event.text) != null ? _a : void 0)),
|
|
2038
2390
|
attrString("ai.response.id", (_b = event.response) == null ? void 0 : _b.id),
|
|
2039
2391
|
attrString("ai.response.model", (_c = event.response) == null ? void 0 : _c.modelId),
|
|
2040
2392
|
attrString(
|
|
@@ -2050,7 +2402,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2050
2402
|
outputAttrs.push(
|
|
2051
2403
|
attrString(
|
|
2052
2404
|
"ai.response.toolCalls",
|
|
2053
|
-
|
|
2405
|
+
safeJsonWithUint8(
|
|
2054
2406
|
event.toolCalls.map((tc) => ({
|
|
2055
2407
|
toolCallId: tc.toolCallId,
|
|
2056
2408
|
toolName: tc.toolName,
|
|
@@ -2063,7 +2415,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2063
2415
|
if (((_g = event.reasoning) == null ? void 0 : _g.length) > 0) {
|
|
2064
2416
|
const reasoningText = event.reasoning.filter((part) => "text" in part).map((part) => part.text).join("\n");
|
|
2065
2417
|
if (reasoningText) {
|
|
2066
|
-
outputAttrs.push(attrString("ai.response.reasoning", reasoningText));
|
|
2418
|
+
outputAttrs.push(attrString("ai.response.reasoning", capText2(reasoningText)));
|
|
2067
2419
|
}
|
|
2068
2420
|
}
|
|
2069
2421
|
}
|
|
@@ -2485,7 +2837,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2485
2837
|
if (state.recordOutputs) {
|
|
2486
2838
|
outputAttrs.push(
|
|
2487
2839
|
attrString("ai.response.finishReason", event.finishReason),
|
|
2488
|
-
attrString("ai.response.text", (_a = event.text) != null ? _a : void 0),
|
|
2840
|
+
attrString("ai.response.text", capText2((_a = event.text) != null ? _a : void 0)),
|
|
2489
2841
|
attrString(
|
|
2490
2842
|
"ai.response.providerMetadata",
|
|
2491
2843
|
event.providerMetadata ? safeJsonWithUint8(event.providerMetadata) : void 0
|
|
@@ -2495,7 +2847,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2495
2847
|
outputAttrs.push(
|
|
2496
2848
|
attrString(
|
|
2497
2849
|
"ai.response.toolCalls",
|
|
2498
|
-
|
|
2850
|
+
safeJsonWithUint8(
|
|
2499
2851
|
event.toolCalls.map((tc) => ({
|
|
2500
2852
|
toolCallId: tc.toolCallId,
|
|
2501
2853
|
toolName: tc.toolName,
|
|
@@ -2508,7 +2860,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2508
2860
|
if (((_c = event.reasoning) == null ? void 0 : _c.length) > 0) {
|
|
2509
2861
|
const reasoningText = event.reasoning.filter((part) => "text" in part).map((part) => part.text).join("\n");
|
|
2510
2862
|
if (reasoningText) {
|
|
2511
|
-
outputAttrs.push(attrString("ai.response.reasoning", reasoningText));
|
|
2863
|
+
outputAttrs.push(attrString("ai.response.reasoning", capText2(reasoningText)));
|
|
2512
2864
|
}
|
|
2513
2865
|
}
|
|
2514
2866
|
}
|
|
@@ -2546,7 +2898,8 @@ var RaindropTelemetryIntegration = class {
|
|
|
2546
2898
|
const userId = (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId;
|
|
2547
2899
|
if (!userId) return;
|
|
2548
2900
|
const eventName = (_e = (_d = callMeta.eventName) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.eventName) != null ? _e : state.operationId;
|
|
2549
|
-
const
|
|
2901
|
+
const cappedOutput = capText2(output);
|
|
2902
|
+
const input = capText2(state.inputText);
|
|
2550
2903
|
const properties = {
|
|
2551
2904
|
...(_f = this.defaultContext) == null ? void 0 : _f.properties,
|
|
2552
2905
|
...callMeta.properties
|
|
@@ -2557,7 +2910,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2557
2910
|
userId,
|
|
2558
2911
|
convoId,
|
|
2559
2912
|
input,
|
|
2560
|
-
output,
|
|
2913
|
+
output: cappedOutput,
|
|
2561
2914
|
model,
|
|
2562
2915
|
properties: Object.keys(properties).length > 0 ? properties : void 0,
|
|
2563
2916
|
isPending: false
|
|
@@ -3017,13 +3370,14 @@ function shouldKeepEventPending(params) {
|
|
|
3017
3370
|
return params.finishReason === "tool-calls" || params.finishReason === "tool_calls";
|
|
3018
3371
|
}
|
|
3019
3372
|
function normalizePromptAttr(arg) {
|
|
3373
|
+
var _a, _b;
|
|
3020
3374
|
if (!isRecord(arg)) return arg;
|
|
3021
3375
|
const system = arg["system"];
|
|
3022
3376
|
const prompt = arg["prompt"];
|
|
3023
3377
|
const messages = arg["messages"];
|
|
3024
3378
|
if (Array.isArray(messages)) {
|
|
3025
3379
|
if (system) {
|
|
3026
|
-
const sysContent = typeof system === "string" ? system :
|
|
3380
|
+
const sysContent = typeof system === "string" ? system : (_a = safeJsonWithUint8(system)) != null ? _a : String(system);
|
|
3027
3381
|
return [{ role: "system", content: sysContent }, ...messages];
|
|
3028
3382
|
}
|
|
3029
3383
|
return messages;
|
|
@@ -3031,7 +3385,10 @@ function normalizePromptAttr(arg) {
|
|
|
3031
3385
|
if (typeof prompt === "string") {
|
|
3032
3386
|
const msgs = [];
|
|
3033
3387
|
if (system) {
|
|
3034
|
-
msgs.push({
|
|
3388
|
+
msgs.push({
|
|
3389
|
+
role: "system",
|
|
3390
|
+
content: typeof system === "string" ? system : (_b = safeJsonWithUint8(system)) != null ? _b : String(system)
|
|
3391
|
+
});
|
|
3035
3392
|
}
|
|
3036
3393
|
msgs.push({ role: "user", content: prompt });
|
|
3037
3394
|
return msgs;
|
|
@@ -3200,7 +3557,8 @@ function createFinalize(params) {
|
|
|
3200
3557
|
};
|
|
3201
3558
|
const built = await maybeBuildEvent(options.buildEvent, allMessages);
|
|
3202
3559
|
const patch = mergeBuildEventPatch(defaultPatch, built);
|
|
3203
|
-
const output = patch.output;
|
|
3560
|
+
const output = capText2(patch.output);
|
|
3561
|
+
const input = capText2(patch.input);
|
|
3204
3562
|
const finalModel = (_c = patch.model) != null ? _c : model;
|
|
3205
3563
|
if (setup.rootSpan) {
|
|
3206
3564
|
const spanEndTimeUnixNano = nowUnixNanoString();
|
|
@@ -3244,7 +3602,7 @@ function createFinalize(params) {
|
|
|
3244
3602
|
eventName: patch.eventName,
|
|
3245
3603
|
userId: setup.ctx.userId,
|
|
3246
3604
|
convoId: setup.ctx.convoId,
|
|
3247
|
-
input
|
|
3605
|
+
input,
|
|
3248
3606
|
output,
|
|
3249
3607
|
model: finalModel,
|
|
3250
3608
|
properties: patch.properties,
|
|
@@ -3759,7 +4117,8 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
3759
4117
|
};
|
|
3760
4118
|
const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
|
|
3761
4119
|
const patch = mergeBuildEventPatch(defaultPatch, built);
|
|
3762
|
-
const output = patch.output;
|
|
4120
|
+
const output = capText2(patch.output);
|
|
4121
|
+
const input = capText2(patch.input);
|
|
3763
4122
|
const finalModel = (_c2 = patch.model) != null ? _c2 : model;
|
|
3764
4123
|
if (rootSpan) {
|
|
3765
4124
|
const spanEndTimeUnixNano = nowUnixNanoString();
|
|
@@ -3817,7 +4176,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
3817
4176
|
eventName: patch.eventName,
|
|
3818
4177
|
userId: ctx.userId,
|
|
3819
4178
|
convoId: ctx.convoId,
|
|
3820
|
-
input
|
|
4179
|
+
input,
|
|
3821
4180
|
output,
|
|
3822
4181
|
model: finalModel,
|
|
3823
4182
|
properties: patch.properties,
|
|
@@ -3966,7 +4325,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3966
4325
|
};
|
|
3967
4326
|
const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
|
|
3968
4327
|
const patch = mergeBuildEventPatch(defaultPatch, built);
|
|
3969
|
-
const output = patch.output;
|
|
4328
|
+
const output = capText2(patch.output);
|
|
4329
|
+
const input = capText2(patch.input);
|
|
3970
4330
|
const finalModel = (_c2 = patch.model) != null ? _c2 : model;
|
|
3971
4331
|
if (rootSpan) {
|
|
3972
4332
|
const spanEndTimeUnixNano = nowUnixNanoString();
|
|
@@ -4024,7 +4384,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
4024
4384
|
eventName: patch.eventName,
|
|
4025
4385
|
userId: ctx.userId,
|
|
4026
4386
|
convoId: ctx.convoId,
|
|
4027
|
-
input
|
|
4387
|
+
input,
|
|
4028
4388
|
output,
|
|
4029
4389
|
model: finalModel,
|
|
4030
4390
|
properties: patch.properties,
|
|
@@ -4364,7 +4724,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
4364
4724
|
attributes: [
|
|
4365
4725
|
...((_a = ctx.telemetry) == null ? void 0 : _a.recordOutputs) === false ? [] : [
|
|
4366
4726
|
attrString("ai.response.finishReason", finishReason),
|
|
4367
|
-
attrString("ai.response.text", activeText.length ? activeText : void 0),
|
|
4727
|
+
attrString("ai.response.text", activeText.length ? capText2(activeText) : void 0),
|
|
4368
4728
|
attrString(
|
|
4369
4729
|
"ai.response.toolCalls",
|
|
4370
4730
|
safeJsonWithUint8(toolCallsLocal.length ? toolCallsLocal : void 0)
|
|
@@ -4417,7 +4777,9 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
4417
4777
|
} else if (typeof value["textDelta"] === "string") {
|
|
4418
4778
|
textDelta = value["textDelta"];
|
|
4419
4779
|
}
|
|
4420
|
-
if (typeof textDelta === "string"
|
|
4780
|
+
if (typeof textDelta === "string" && activeText.length <= effectiveMaxTextFieldChars()) {
|
|
4781
|
+
activeText += textDelta;
|
|
4782
|
+
}
|
|
4421
4783
|
}
|
|
4422
4784
|
if (type === "finish") finishReason = extractFinishReason(value);
|
|
4423
4785
|
if (type === "tool-call") toolCallsLocal.push(value);
|
|
@@ -4652,7 +5014,7 @@ function extractNestedTokens(usage, key) {
|
|
|
4652
5014
|
// package.json
|
|
4653
5015
|
var package_default = {
|
|
4654
5016
|
name: "@raindrop-ai/ai-sdk",
|
|
4655
|
-
version: "0.0.
|
|
5017
|
+
version: "0.0.34"};
|
|
4656
5018
|
|
|
4657
5019
|
// src/internal/version.ts
|
|
4658
5020
|
var libraryName = package_default.name;
|
|
@@ -4725,8 +5087,8 @@ function eventMetadataFromChatRequest(options) {
|
|
|
4725
5087
|
});
|
|
4726
5088
|
}
|
|
4727
5089
|
function stringify(v) {
|
|
4728
|
-
if (typeof v === "string") return v;
|
|
4729
|
-
return
|
|
5090
|
+
if (typeof v === "string") return capText2(v);
|
|
5091
|
+
return boundedStringify(v);
|
|
4730
5092
|
}
|
|
4731
5093
|
function userAttrsToOtlp(attrs) {
|
|
4732
5094
|
if (!attrs) return [];
|
|
@@ -4744,6 +5106,7 @@ function createRaindropAISDK(opts) {
|
|
|
4744
5106
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
4745
5107
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
4746
5108
|
const envDebug = envDebugEnabled();
|
|
5109
|
+
setMaxTextFieldChars(opts.maxTextFieldChars);
|
|
4747
5110
|
const localWorkshopInput = opts.localWorkshopUrl === false ? null : opts.localWorkshopUrl;
|
|
4748
5111
|
const resolvedLocalDebuggerUrl = resolveLocalDebuggerBaseUrl(localWorkshopInput);
|
|
4749
5112
|
const localDebuggerUrl = localWorkshopInput === null ? null : resolvedLocalDebuggerUrl != null ? resolvedLocalDebuggerUrl : void 0;
|
|
@@ -4930,4 +5293,4 @@ function raindrop(options = {}) {
|
|
|
4930
5293
|
return client.createTelemetryIntegration({ context, subagentWrapping });
|
|
4931
5294
|
}
|
|
4932
5295
|
|
|
4933
|
-
export { DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent };
|
|
5296
|
+
export { DEFAULT_MAX_TEXT_FIELD_CHARS2 as DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, TRUNCATION_MARKER2 as TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText2 as capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent };
|