@raindrop-ai/ai-sdk 0.3.1 → 0.3.3
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 +26 -0
- package/dist/{chunk-SGSAYTKI.mjs → chunk-MCRACPKM.mjs} +1274 -422
- package/dist/{index-BqXHiknB.d.mts → index-B_mpeckV.d.mts} +123 -38
- package/dist/{index-BqXHiknB.d.ts → index-B_mpeckV.d.ts} +123 -38
- package/dist/index.browser.d.mts +123 -38
- package/dist/index.browser.d.ts +123 -38
- package/dist/index.browser.js +1131 -424
- package/dist/index.browser.mjs +1131 -424
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +1274 -422
- 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 +1274 -422
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,637 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { execFile } from 'child_process';
|
|
3
|
+
import { resolve } from 'path';
|
|
2
4
|
|
|
3
|
-
// ../core/dist/chunk-
|
|
5
|
+
// ../core/dist/chunk-BYBMRLZM.js
|
|
6
|
+
var EVAL_CORRELATION_ID_ATTRIBUTE = "raindrop.eval_correlation_id";
|
|
7
|
+
var PROBE_SCOPE = { correlationId: "" };
|
|
8
|
+
var EvalScopeStorage = class {
|
|
9
|
+
constructor() {
|
|
10
|
+
this._als = null;
|
|
11
|
+
this._probed = false;
|
|
12
|
+
}
|
|
13
|
+
maybeAdoptAsyncLocalStorage() {
|
|
14
|
+
if (this._probed) return;
|
|
15
|
+
this._probed = true;
|
|
16
|
+
try {
|
|
17
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
18
|
+
if (!Ctor) return;
|
|
19
|
+
const als = new Ctor();
|
|
20
|
+
als.run(PROBE_SCOPE, () => {
|
|
21
|
+
});
|
|
22
|
+
this._als = als;
|
|
23
|
+
} catch (e) {
|
|
24
|
+
this._als = null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
run(scope, callback) {
|
|
28
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
29
|
+
if (this._als) return this._als.run(scope, callback);
|
|
30
|
+
const previous = this._syncScope;
|
|
31
|
+
this._syncScope = scope;
|
|
32
|
+
try {
|
|
33
|
+
return callback();
|
|
34
|
+
} finally {
|
|
35
|
+
this._syncScope = previous;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
current() {
|
|
39
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
40
|
+
if (this._als) return this._als.getStore();
|
|
41
|
+
return this._syncScope;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var EVAL_SCOPE_STORAGE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.evalScopeStorage");
|
|
45
|
+
function evalScopeStorage() {
|
|
46
|
+
const holder = globalThis;
|
|
47
|
+
let storage = holder[EVAL_SCOPE_STORAGE_KEY];
|
|
48
|
+
if (!storage) {
|
|
49
|
+
storage = new EvalScopeStorage();
|
|
50
|
+
holder[EVAL_SCOPE_STORAGE_KEY] = storage;
|
|
51
|
+
}
|
|
52
|
+
return storage;
|
|
53
|
+
}
|
|
54
|
+
function currentEvalScope() {
|
|
55
|
+
try {
|
|
56
|
+
return evalScopeStorage().current();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function evalScopeAttributes() {
|
|
62
|
+
const scope = currentEvalScope();
|
|
63
|
+
if (!scope) return {};
|
|
64
|
+
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ../core/dist/chunk-WJOR6M7H.js
|
|
68
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
69
|
+
function state() {
|
|
70
|
+
const holder = globalThis;
|
|
71
|
+
let current = holder[STATE_KEY];
|
|
72
|
+
if (!current) {
|
|
73
|
+
let storage = null;
|
|
74
|
+
try {
|
|
75
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
76
|
+
if (Ctor) storage = new Ctor();
|
|
77
|
+
} catch (e) {
|
|
78
|
+
storage = null;
|
|
79
|
+
}
|
|
80
|
+
current = {
|
|
81
|
+
storage,
|
|
82
|
+
syncDestination: void 0,
|
|
83
|
+
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
84
|
+
};
|
|
85
|
+
holder[STATE_KEY] = current;
|
|
86
|
+
}
|
|
87
|
+
return current;
|
|
88
|
+
}
|
|
89
|
+
function currentReplayTraceDestination() {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const routing = state();
|
|
92
|
+
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
93
|
+
}
|
|
94
|
+
function rememberReplayTraceDestination(span) {
|
|
95
|
+
const destination = currentReplayTraceDestination();
|
|
96
|
+
if (destination) state().spanDestinations.set(span, destination);
|
|
97
|
+
}
|
|
98
|
+
function copyReplayTraceDestination(source, target) {
|
|
99
|
+
const destination = state().spanDestinations.get(source);
|
|
100
|
+
if (destination) state().spanDestinations.set(target, destination);
|
|
101
|
+
}
|
|
102
|
+
function replayTraceDestinationFor(value) {
|
|
103
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
return state().spanDestinations.get(value);
|
|
107
|
+
}
|
|
108
|
+
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
if (!destination || !spanId || !traceId) return;
|
|
111
|
+
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
112
|
+
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
113
|
+
}
|
|
114
|
+
function replayTraceUrl(baseUrl) {
|
|
115
|
+
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
116
|
+
}
|
|
117
|
+
var NOOP_SPAN = {
|
|
118
|
+
traceIdB64: "",
|
|
119
|
+
spanIdB64: "",
|
|
120
|
+
eventId: "",
|
|
121
|
+
log() {
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function getAsyncLocalStorageCtor() {
|
|
125
|
+
return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
126
|
+
}
|
|
127
|
+
var SynchronousContextStorage = class {
|
|
128
|
+
constructor() {
|
|
129
|
+
this._stack = [];
|
|
130
|
+
}
|
|
131
|
+
isEmpty() {
|
|
132
|
+
return this._stack.length === 0;
|
|
133
|
+
}
|
|
134
|
+
getStore() {
|
|
135
|
+
return this._stack[this._stack.length - 1];
|
|
136
|
+
}
|
|
137
|
+
run(store, callback) {
|
|
138
|
+
this._stack.push(store);
|
|
139
|
+
try {
|
|
140
|
+
return callback();
|
|
141
|
+
} finally {
|
|
142
|
+
this._stack.pop();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var ContextManager = class {
|
|
147
|
+
};
|
|
148
|
+
var RaindropContextManager = class extends ContextManager {
|
|
149
|
+
constructor() {
|
|
150
|
+
super();
|
|
151
|
+
this._fallback = null;
|
|
152
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
153
|
+
if (Ctor) {
|
|
154
|
+
this._storage = new Ctor();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this._fallback = new SynchronousContextStorage();
|
|
158
|
+
this._storage = this._fallback;
|
|
159
|
+
}
|
|
160
|
+
maybeAdoptAsyncLocalStorage() {
|
|
161
|
+
if (!this._fallback || !this._fallback.isEmpty()) return;
|
|
162
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
163
|
+
if (!Ctor) return;
|
|
164
|
+
this._storage = new Ctor();
|
|
165
|
+
this._fallback = null;
|
|
166
|
+
}
|
|
167
|
+
isReady() {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
getParentSpanIds() {
|
|
171
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
172
|
+
const span = this._storage.getStore();
|
|
173
|
+
if (!span || span === NOOP_SPAN) return void 0;
|
|
174
|
+
return {
|
|
175
|
+
traceIdB64: span.traceIdB64,
|
|
176
|
+
spanIdB64: span.spanIdB64,
|
|
177
|
+
eventId: span.eventId
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
runInContext(span, callback) {
|
|
181
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
182
|
+
return this._storage.run(span, callback);
|
|
183
|
+
}
|
|
184
|
+
getCurrentSpan() {
|
|
185
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
186
|
+
return this._storage.getStore();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var _contextManager = null;
|
|
190
|
+
function getContextManager() {
|
|
191
|
+
if (!_contextManager) {
|
|
192
|
+
_contextManager = globalThis.RAINDROP_CONTEXT_MANAGER ? new globalThis.RAINDROP_CONTEXT_MANAGER() : new RaindropContextManager();
|
|
193
|
+
}
|
|
194
|
+
return _contextManager;
|
|
195
|
+
}
|
|
196
|
+
function currentSpan() {
|
|
197
|
+
var _a;
|
|
198
|
+
return (_a = getContextManager().getCurrentSpan()) != null ? _a : NOOP_SPAN;
|
|
199
|
+
}
|
|
200
|
+
function withCurrent(span, callback) {
|
|
201
|
+
return getContextManager().runInContext(span, callback);
|
|
202
|
+
}
|
|
203
|
+
async function getCurrentParentSpanContext() {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
return (_b = getContextManager().getParentSpanIds()) != null ? _b : (_a = currentReplayTraceDestination()) == null ? void 0 : _a.parentSpanContext;
|
|
206
|
+
}
|
|
207
|
+
async function runWithParentSpanContext(ctx, fn) {
|
|
208
|
+
const cm = getContextManager();
|
|
209
|
+
const span = {
|
|
210
|
+
traceIdB64: ctx.traceIdB64,
|
|
211
|
+
spanIdB64: ctx.spanIdB64,
|
|
212
|
+
eventId: ctx.eventId
|
|
213
|
+
};
|
|
214
|
+
return cm.runInContext(span, fn);
|
|
215
|
+
}
|
|
216
|
+
async function* asyncGeneratorWithCurrent(span, gen) {
|
|
217
|
+
let nextValue;
|
|
218
|
+
while (true) {
|
|
219
|
+
const result = await withCurrent(span, async () => {
|
|
220
|
+
try {
|
|
221
|
+
return await gen.next(nextValue);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
return { value: void 0, done: true, error: e };
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
if ("error" in result && result.error !== void 0) {
|
|
227
|
+
throw result.error;
|
|
228
|
+
}
|
|
229
|
+
if (result.done) {
|
|
230
|
+
return result.value;
|
|
231
|
+
}
|
|
232
|
+
nextValue = yield result.value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var MAX_BINDING_STACK = 128;
|
|
236
|
+
var EMPTY_STACK = [];
|
|
237
|
+
var ContextStackStorage = class {
|
|
238
|
+
/** Emitted once when this runtime cannot support an ambient push. */
|
|
239
|
+
constructor(noAmbientBindWarning) {
|
|
240
|
+
this.noAmbientBindWarning = noAmbientBindWarning;
|
|
241
|
+
this._als = null;
|
|
242
|
+
this._enterWithUsable = false;
|
|
243
|
+
this._syncStack = EMPTY_STACK;
|
|
244
|
+
this._adoptionChecked = false;
|
|
245
|
+
this._warnedNoAmbientBind = false;
|
|
246
|
+
}
|
|
247
|
+
maybeAdoptAsyncLocalStorage() {
|
|
248
|
+
if (this._adoptionChecked) return;
|
|
249
|
+
this._adoptionChecked = true;
|
|
250
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
251
|
+
if (!Ctor) return;
|
|
252
|
+
const als = new Ctor();
|
|
253
|
+
try {
|
|
254
|
+
als.run(EMPTY_STACK, () => {
|
|
255
|
+
});
|
|
256
|
+
} catch (e) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this._als = als;
|
|
260
|
+
if (typeof als.enterWith === "function") {
|
|
261
|
+
try {
|
|
262
|
+
als.enterWith(EMPTY_STACK);
|
|
263
|
+
this._enterWithUsable = true;
|
|
264
|
+
} catch (e) {
|
|
265
|
+
this._enterWithUsable = false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
getStack() {
|
|
270
|
+
var _a;
|
|
271
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
272
|
+
if (this._als) return (_a = this._als.getStore()) != null ? _a : this._syncStack;
|
|
273
|
+
return this._syncStack;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Persist an ambient stack mutation. Returns false when an ALS is adopted but
|
|
277
|
+
* `enterWith` is unusable (workerd): callers must NOT fall back to the
|
|
278
|
+
* process-shared sync stack, since concurrent isolates would cross-stamp.
|
|
279
|
+
*/
|
|
280
|
+
setAmbientStack(stack) {
|
|
281
|
+
if (this._als) {
|
|
282
|
+
if (!this._enterWithUsable) return false;
|
|
283
|
+
this._als.enterWith(stack);
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
this._syncStack = stack;
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
push(binding) {
|
|
290
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
291
|
+
if (this._als && !this._enterWithUsable) {
|
|
292
|
+
this.warnNoAmbientBindOnce();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
let stack = this.getStack();
|
|
296
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
297
|
+
stack = stack.filter((b) => b.isLive());
|
|
298
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
299
|
+
stack = stack.slice(stack.length - (MAX_BINDING_STACK - 1));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
this.setAmbientStack([...stack, binding]);
|
|
303
|
+
}
|
|
304
|
+
remove(binding) {
|
|
305
|
+
binding.markDead();
|
|
306
|
+
const stack = this.getStack();
|
|
307
|
+
const pruned = stack.filter((b) => b !== binding && b.isLive());
|
|
308
|
+
if (pruned.length !== stack.length) {
|
|
309
|
+
this.setAmbientStack(pruned);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
runWith(binding, callback) {
|
|
313
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
314
|
+
if (this._als) {
|
|
315
|
+
return this._als.run([...this.getStack(), binding], callback);
|
|
316
|
+
}
|
|
317
|
+
const previous = this._syncStack;
|
|
318
|
+
this._syncStack = [...previous, binding];
|
|
319
|
+
try {
|
|
320
|
+
return callback();
|
|
321
|
+
} finally {
|
|
322
|
+
this._syncStack = previous;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
current() {
|
|
326
|
+
const stack = this.getStack();
|
|
327
|
+
if (stack.length === 0) return void 0;
|
|
328
|
+
const top = stack[stack.length - 1];
|
|
329
|
+
if (top.isLive()) return top;
|
|
330
|
+
const pruned = stack.filter((b) => b.isLive());
|
|
331
|
+
this.setAmbientStack(pruned);
|
|
332
|
+
return pruned.length > 0 ? pruned[pruned.length - 1] : void 0;
|
|
333
|
+
}
|
|
334
|
+
warnNoAmbientBindOnce() {
|
|
335
|
+
if (this._warnedNoAmbientBind) return;
|
|
336
|
+
this._warnedNoAmbientBind = true;
|
|
337
|
+
console.warn(this.noAmbientBindWarning);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var NO_AMBIENT_ROUTING_BIND_WARNING = "[raindrop] This runtime's AsyncLocalStorage does not implement enterWith (e.g. Cloudflare Workers), so begin()/finish() cannot scope auto-instrumented spans to a project without cross-contaminating concurrent requests. Manual events and explicit span routing are unaffected; use asCurrent()/withSpan (run-based) to route auto-instrumented spans on this runtime.";
|
|
341
|
+
var ROUTING_STORAGE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.routingContextStorage");
|
|
342
|
+
function routingStorage() {
|
|
343
|
+
const holder = globalThis;
|
|
344
|
+
let storage = holder[ROUTING_STORAGE_KEY];
|
|
345
|
+
if (!storage) {
|
|
346
|
+
storage = new ContextStackStorage(NO_AMBIENT_ROUTING_BIND_WARNING);
|
|
347
|
+
holder[ROUTING_STORAGE_KEY] = storage;
|
|
348
|
+
}
|
|
349
|
+
return storage;
|
|
350
|
+
}
|
|
351
|
+
function currentRoutingBinding() {
|
|
352
|
+
const bound = routingStorage().current();
|
|
353
|
+
if (!bound) return void 0;
|
|
354
|
+
return {
|
|
355
|
+
projectId: bound.projectId,
|
|
356
|
+
authHint: bound.authHint,
|
|
357
|
+
...bound.appGit ? { appGit: bound.appGit } : {},
|
|
358
|
+
...bound.appGitSource ? { appGitSource: bound.appGitSource } : {}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
var APP_COMMIT_SHA = "raindrop.app.commit_sha";
|
|
362
|
+
var APP_COMMIT_DIRTY = "raindrop.app.commit_dirty";
|
|
363
|
+
var APP_BRANCH = "raindrop.app.branch";
|
|
364
|
+
var APP_GIT_KEYS = [APP_COMMIT_SHA, APP_COMMIT_DIRTY, APP_BRANCH];
|
|
365
|
+
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
366
|
+
function appGitExplicitKeys(properties) {
|
|
367
|
+
const keys = /* @__PURE__ */ new Set();
|
|
368
|
+
if (!properties) return keys;
|
|
369
|
+
for (const key of APP_GIT_KEYS) {
|
|
370
|
+
if (own(properties, key)) keys.add(key);
|
|
371
|
+
}
|
|
372
|
+
return keys;
|
|
373
|
+
}
|
|
374
|
+
function mergeAppGitSnapshot(base, properties, explicitKeys = /* @__PURE__ */ new Set()) {
|
|
375
|
+
try {
|
|
376
|
+
const result = { ...base };
|
|
377
|
+
if (properties && own(properties, APP_COMMIT_SHA) && properties[APP_COMMIT_SHA] !== result[APP_COMMIT_SHA]) {
|
|
378
|
+
if (!explicitKeys.has(APP_COMMIT_DIRTY) && !own(properties, APP_COMMIT_DIRTY)) {
|
|
379
|
+
delete result[APP_COMMIT_DIRTY];
|
|
380
|
+
}
|
|
381
|
+
if (!explicitKeys.has(APP_BRANCH) && !own(properties, APP_BRANCH)) {
|
|
382
|
+
delete result[APP_BRANCH];
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
for (const key of APP_GIT_KEYS) {
|
|
386
|
+
if (properties && own(properties, key)) result[key] = properties[key];
|
|
387
|
+
}
|
|
388
|
+
return Object.freeze(result);
|
|
389
|
+
} catch (e) {
|
|
390
|
+
return Object.freeze({});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function validAppCommitSha(value) {
|
|
394
|
+
if (typeof value !== "string" || value.length > 128) return void 0;
|
|
395
|
+
const cleaned = value.trim();
|
|
396
|
+
return /^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(cleaned) ? cleaned.toLowerCase() : void 0;
|
|
397
|
+
}
|
|
398
|
+
function shortString(value) {
|
|
399
|
+
if (typeof value !== "string" || value.length > 1024) return void 0;
|
|
400
|
+
const cleaned = value.trim();
|
|
401
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
402
|
+
}
|
|
403
|
+
function flag(value) {
|
|
404
|
+
if (value === true || value === "true" || value === "1") return true;
|
|
405
|
+
if (value === false || value === "false" || value === "0") return false;
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
function environment() {
|
|
409
|
+
try {
|
|
410
|
+
return typeof process === "undefined" ? {} : process.env;
|
|
411
|
+
} catch (e) {
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
var DEPLOYMENTS = [
|
|
416
|
+
["VERCEL", "VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF"],
|
|
417
|
+
["NETLIFY", "COMMIT_REF", "BRANCH"],
|
|
418
|
+
["RAILWAY_ENVIRONMENT_NAME", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
419
|
+
["RAILWAY_ENVIRONMENT", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
420
|
+
["RENDER", "RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH"],
|
|
421
|
+
["DYNO", "HEROKU_BUILD_COMMIT", ""],
|
|
422
|
+
["DYNO", "HEROKU_SLUG_COMMIT", ""],
|
|
423
|
+
["AWS_APP_ID", "AWS_COMMIT_ID", "AWS_BRANCH"],
|
|
424
|
+
["WORKERS_CI", "WORKERS_CI_COMMIT_SHA", "WORKERS_CI_BRANCH"]
|
|
425
|
+
];
|
|
426
|
+
var CI_SOURCES = [
|
|
427
|
+
["GITHUB_ACTIONS", "GITHUB_SHA", "GITHUB_REF_NAME"],
|
|
428
|
+
["GITLAB_CI", "CI_COMMIT_SHA", "CI_COMMIT_REF_NAME"],
|
|
429
|
+
["CIRCLECI", "CIRCLE_SHA1", "CIRCLE_BRANCH"]
|
|
430
|
+
];
|
|
431
|
+
function detectedSource(env, table, detectBranch) {
|
|
432
|
+
for (const row of table) {
|
|
433
|
+
const [marker, shaKey, branchKey] = row;
|
|
434
|
+
if (!marker || !shaKey || !shortString(env[marker]) || flag(env[marker]) === false) continue;
|
|
435
|
+
const commitSha = validAppCommitSha(env[shaKey]);
|
|
436
|
+
if (commitSha)
|
|
437
|
+
return {
|
|
438
|
+
commitSha,
|
|
439
|
+
...detectBranch && branchKey ? { branch: shortString(env[branchKey]) } : {}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
return {};
|
|
443
|
+
}
|
|
444
|
+
var AppGitContextImpl = class {
|
|
445
|
+
constructor(options, runtime = {}) {
|
|
446
|
+
this.defaults = {};
|
|
447
|
+
this.explicit = {};
|
|
448
|
+
this.explicitKeys = /* @__PURE__ */ new Set();
|
|
449
|
+
this.disposed = false;
|
|
450
|
+
this.operations = /* @__PURE__ */ new Map();
|
|
451
|
+
this.operationOverflow = false;
|
|
452
|
+
this.detectBranch = false;
|
|
453
|
+
this.disabled = false;
|
|
454
|
+
var _a, _b, _c, _d, _e, _f;
|
|
455
|
+
try {
|
|
456
|
+
if (options === false) {
|
|
457
|
+
this.disabled = true;
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const opts = options != null ? options : {};
|
|
461
|
+
const env = (_a = runtime.env) != null ? _a : environment();
|
|
462
|
+
const detectBranch = (_c = (_b = flag(opts.detectBranch)) != null ? _b : flag(env.RAINDROP_GIT_DETECT_BRANCH)) != null ? _c : false;
|
|
463
|
+
this.detectBranch = detectBranch;
|
|
464
|
+
const collectBranch = detectBranch || runtime.captureLegacyReplayBranch === true;
|
|
465
|
+
const autoDetect = runtime.allowDiscovery === false ? false : (_e = (_d = flag(opts.autoDetect)) != null ? _d : flag(env.RAINDROP_GIT_AUTO_DETECT)) != null ? _e : true;
|
|
466
|
+
const configuredSha = opts.commitSha;
|
|
467
|
+
const explicitSha = configuredSha === void 0 ? env.RAINDROP_COMMIT_SHA : configuredSha;
|
|
468
|
+
if (explicitSha === null) this.explicit[APP_COMMIT_SHA] = null;
|
|
469
|
+
else if (typeof explicitSha === "string" && validAppCommitSha(explicitSha))
|
|
470
|
+
this.explicit[APP_COMMIT_SHA] = explicitSha;
|
|
471
|
+
const configuredDirty = opts.commitDirty;
|
|
472
|
+
const explicitDirty = configuredDirty === void 0 ? flag(env.RAINDROP_COMMIT_DIRTY) : configuredDirty;
|
|
473
|
+
if (explicitDirty === null || typeof explicitDirty === "boolean")
|
|
474
|
+
this.explicit[APP_COMMIT_DIRTY] = explicitDirty;
|
|
475
|
+
const configuredBranch = opts.branch;
|
|
476
|
+
const explicitBranch = configuredBranch === void 0 ? env.RAINDROP_BRANCH : configuredBranch;
|
|
477
|
+
if (explicitBranch === null) this.explicit[APP_BRANCH] = null;
|
|
478
|
+
else if (typeof explicitBranch === "string" && explicitBranch.length <= 1024)
|
|
479
|
+
this.explicit[APP_BRANCH] = explicitBranch;
|
|
480
|
+
this.explicitKeys = appGitExplicitKeys(this.explicit);
|
|
481
|
+
this.defaults = { ...this.explicit };
|
|
482
|
+
if (!autoDetect || explicitSha !== void 0) return;
|
|
483
|
+
const sourceDirectory = (_f = shortString(opts.sourceDirectory)) != null ? _f : shortString(env.RAINDROP_GIT_SOURCE_DIRECTORY);
|
|
484
|
+
if (runtime.allowLocalGit === false && !sourceDirectory) return;
|
|
485
|
+
const deploy = sourceDirectory ? {} : detectedSource(env, DEPLOYMENTS, collectBranch);
|
|
486
|
+
if (deploy.commitSha) {
|
|
487
|
+
this.accept(deploy);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const fallback = sourceDirectory ? {} : detectedSource(env, CI_SOURCES, collectBranch);
|
|
491
|
+
if (runtime.resolveLocal && (runtime.allowLocalGit !== false || sourceDirectory)) {
|
|
492
|
+
this.cancel = runtime.resolveLocal(sourceDirectory, collectBranch, (result) => {
|
|
493
|
+
try {
|
|
494
|
+
if (!this.disposed) this.accept(result.commitSha ? result : fallback);
|
|
495
|
+
} catch (e) {
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
} else this.accept(fallback);
|
|
499
|
+
} catch (e) {
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
accept(result) {
|
|
503
|
+
const sha = validAppCommitSha(result.commitSha);
|
|
504
|
+
if (!sha) return;
|
|
505
|
+
this.replayBranch = shortString(result.branch);
|
|
506
|
+
this.defaults = {
|
|
507
|
+
[APP_COMMIT_SHA]: sha,
|
|
508
|
+
...typeof result.commitDirty === "boolean" ? { [APP_COMMIT_DIRTY]: result.commitDirty } : {},
|
|
509
|
+
...this.detectBranch && this.replayBranch ? { [APP_BRANCH]: this.replayBranch } : {},
|
|
510
|
+
...this.explicit
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
snapshot(properties) {
|
|
514
|
+
var _a;
|
|
515
|
+
try {
|
|
516
|
+
const binding = currentRoutingBinding();
|
|
517
|
+
const base = this.disabled && (binding == null ? void 0 : binding.appGitSource) !== "replay-override" ? {} : (_a = binding == null ? void 0 : binding.appGit) != null ? _a : this.defaults;
|
|
518
|
+
return this.mergeSnapshot(base, properties);
|
|
519
|
+
} catch (e) {
|
|
520
|
+
return Object.freeze({});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/** Safe defaults when no operation/span start was observed; never infer identity. */
|
|
524
|
+
snapshotExplicit(properties, eventId) {
|
|
525
|
+
try {
|
|
526
|
+
const base = { ...this.explicit };
|
|
527
|
+
const operation = eventId ? this.operations.get(eventId) : void 0;
|
|
528
|
+
if (operation) {
|
|
529
|
+
for (const key of operation.explicitKeys) base[key] = operation.snapshot[key];
|
|
530
|
+
}
|
|
531
|
+
return this.mergeSnapshot(base, properties, new Set(Object.keys(base)));
|
|
532
|
+
} catch (e) {
|
|
533
|
+
return mergeAppGitSnapshot({}, properties);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/** Existing replay branch reporting stays separate from opt-in event properties. */
|
|
537
|
+
snapshotForReplay() {
|
|
538
|
+
const snapshot = this.snapshot();
|
|
539
|
+
if (this.replayBranch && !own(snapshot, APP_BRANCH) && snapshot[APP_COMMIT_SHA] === this.defaults[APP_COMMIT_SHA]) {
|
|
540
|
+
return Object.freeze({ ...snapshot, [APP_BRANCH]: this.replayBranch });
|
|
541
|
+
}
|
|
542
|
+
return snapshot;
|
|
543
|
+
}
|
|
544
|
+
/** Merge a frozen span snapshot without losing client-authored provenance. */
|
|
545
|
+
mergeSnapshot(base, properties, explicitKeys = this.explicitKeys) {
|
|
546
|
+
return mergeAppGitSnapshot(base, properties, /* @__PURE__ */ new Set([...this.explicitKeys, ...explicitKeys]));
|
|
547
|
+
}
|
|
548
|
+
/** Shippers belonging to one client share this bounded operation registry. */
|
|
549
|
+
forOperation(eventId, properties, owner) {
|
|
550
|
+
if (!eventId) return this.snapshot(properties);
|
|
551
|
+
let operation = this.operations.get(eventId);
|
|
552
|
+
if (!operation) {
|
|
553
|
+
if (this.operations.size >= 1e4) this.operationOverflow = true;
|
|
554
|
+
if (this.operationOverflow) return this.mergeSnapshot({}, properties);
|
|
555
|
+
operation = {
|
|
556
|
+
snapshot: this.snapshot(properties),
|
|
557
|
+
owners: /* @__PURE__ */ new Set(),
|
|
558
|
+
unowned: owner === void 0,
|
|
559
|
+
explicitKeys: appGitExplicitKeys(properties)
|
|
560
|
+
};
|
|
561
|
+
this.operations.set(eventId, operation);
|
|
562
|
+
} else if (properties && APP_GIT_KEYS.some((key) => own(properties, key))) {
|
|
563
|
+
const explicitKeys = /* @__PURE__ */ new Set([...this.explicitKeys, ...operation.explicitKeys]);
|
|
564
|
+
operation.snapshot = this.mergeSnapshot(operation.snapshot, properties, explicitKeys);
|
|
565
|
+
for (const key of appGitExplicitKeys(properties)) operation.explicitKeys.add(key);
|
|
566
|
+
}
|
|
567
|
+
if (!owner) operation.unowned = true;
|
|
568
|
+
if (owner) operation.owners.add(owner);
|
|
569
|
+
return operation.snapshot;
|
|
570
|
+
}
|
|
571
|
+
releaseOperation(eventId, owner) {
|
|
572
|
+
const operation = this.operations.get(eventId);
|
|
573
|
+
if (!operation) return;
|
|
574
|
+
operation.owners.delete(owner);
|
|
575
|
+
if (operation.owners.size === 0 && !operation.unowned) this.operations.delete(eventId);
|
|
576
|
+
}
|
|
577
|
+
finishOperation(eventId) {
|
|
578
|
+
this.operations.delete(eventId);
|
|
579
|
+
}
|
|
580
|
+
dispose() {
|
|
581
|
+
var _a;
|
|
582
|
+
this.disposed = true;
|
|
583
|
+
try {
|
|
584
|
+
(_a = this.cancel) == null ? void 0 : _a.call(this);
|
|
585
|
+
} catch (e) {
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
var AppGitContext = AppGitContextImpl;
|
|
590
|
+
function createAppGitContext(options, runtime = {}) {
|
|
591
|
+
return new AppGitContext(options, runtime);
|
|
592
|
+
}
|
|
593
|
+
function withAppGitProperties(properties, snapshot) {
|
|
594
|
+
try {
|
|
595
|
+
const merged = { ...properties };
|
|
596
|
+
for (const key of APP_GIT_KEYS)
|
|
597
|
+
if (!own(merged, key) && own(snapshot, key)) merged[key] = snapshot[key];
|
|
598
|
+
return merged;
|
|
599
|
+
} catch (e) {
|
|
600
|
+
return properties != null ? properties : {};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function withAppGitAttributes(attributes, snapshot) {
|
|
604
|
+
try {
|
|
605
|
+
const present = new Set(attributes.flatMap((attr) => attr ? [attr.key] : []));
|
|
606
|
+
const added = [];
|
|
607
|
+
for (const key of APP_GIT_KEYS) {
|
|
608
|
+
if (present.has(key) || present.has(`ai.telemetry.metadata.${key}`) || present.has(`traceloop.association.properties.${key}`))
|
|
609
|
+
continue;
|
|
610
|
+
const value = snapshot[key];
|
|
611
|
+
if (typeof value === "string") added.push({ key, value: { stringValue: value } });
|
|
612
|
+
else if (typeof value === "boolean") added.push({ key, value: { boolValue: value } });
|
|
613
|
+
}
|
|
614
|
+
return added.length ? [...attributes, ...added] : attributes;
|
|
615
|
+
} catch (e) {
|
|
616
|
+
return attributes;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function appGitPropertiesFromAttributes(attributes) {
|
|
620
|
+
var _a, _b, _c;
|
|
621
|
+
const properties = {};
|
|
622
|
+
try {
|
|
623
|
+
for (const attr of attributes) {
|
|
624
|
+
if (!attr) continue;
|
|
625
|
+
for (const key of APP_GIT_KEYS) {
|
|
626
|
+
if (attr.key === key || attr.key === `ai.telemetry.metadata.${key}` || attr.key === `traceloop.association.properties.${key}`) {
|
|
627
|
+
properties[key] = (_c = (_b = (_a = attr.value.stringValue) != null ? _a : attr.value.boolValue) != null ? _b : attr.value.intValue) != null ? _c : null;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
} catch (e) {
|
|
632
|
+
}
|
|
633
|
+
return properties;
|
|
634
|
+
}
|
|
4
635
|
function normalizeFeatureFlags(input) {
|
|
5
636
|
if (Array.isArray(input)) {
|
|
6
637
|
return Object.fromEntries(input.map((name) => [name, "true"]));
|
|
@@ -385,7 +1016,7 @@ function runWithTracingSuppressed(fn) {
|
|
|
385
1016
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
386
1017
|
var MAX_RETRY_DELAY_MS = 3e4;
|
|
387
1018
|
function wait(ms) {
|
|
388
|
-
return new Promise((
|
|
1019
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
389
1020
|
}
|
|
390
1021
|
function formatEndpoint(endpoint) {
|
|
391
1022
|
if (!endpoint) return void 0;
|
|
@@ -422,9 +1053,9 @@ async function raceWithTimeout(promise, timeoutMs) {
|
|
|
422
1053
|
() => true,
|
|
423
1054
|
() => true
|
|
424
1055
|
),
|
|
425
|
-
new Promise((
|
|
1056
|
+
new Promise((resolve2) => {
|
|
426
1057
|
var _a;
|
|
427
|
-
timer = setTimeout(() =>
|
|
1058
|
+
timer = setTimeout(() => resolve2(false), Math.max(0, timeoutMs));
|
|
428
1059
|
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
429
1060
|
})
|
|
430
1061
|
]);
|
|
@@ -495,6 +1126,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
495
1126
|
const resp = await runWithTracingSuppressed(
|
|
496
1127
|
() => fetch(url, {
|
|
497
1128
|
method: "POST",
|
|
1129
|
+
redirect: headers["X-Raindrop-Replay-Id"] !== void 0 ? "error" : "follow",
|
|
498
1130
|
headers: {
|
|
499
1131
|
"Content-Type": "application/json",
|
|
500
1132
|
...headers
|
|
@@ -683,31 +1315,36 @@ function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
|
683
1315
|
function localDebuggerEnabled(baseUrl) {
|
|
684
1316
|
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
685
1317
|
}
|
|
1318
|
+
var LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS = 2e3;
|
|
686
1319
|
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
687
1320
|
var _a;
|
|
688
1321
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
689
|
-
if (!baseUrl) return;
|
|
690
|
-
|
|
1322
|
+
if (!baseUrl) return Promise.resolve();
|
|
1323
|
+
return postJson(`${baseUrl}traces`, body, {}, {
|
|
691
1324
|
maxAttempts: 1,
|
|
692
1325
|
debug: (_a = options.debug) != null ? _a : false,
|
|
693
|
-
sdkName: options.sdkName
|
|
1326
|
+
sdkName: options.sdkName,
|
|
1327
|
+
timeoutMs: LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS
|
|
694
1328
|
}).catch(() => {
|
|
695
1329
|
});
|
|
696
1330
|
}
|
|
697
1331
|
function mirrorPartialEventToLocalDebugger(event, options = {}) {
|
|
698
1332
|
var _a;
|
|
699
1333
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
700
|
-
if (!baseUrl) return;
|
|
1334
|
+
if (!baseUrl) return Promise.resolve();
|
|
701
1335
|
const headers = options.writeKey ? { Authorization: `Bearer ${options.writeKey}` } : {};
|
|
702
|
-
|
|
1336
|
+
return postJson(`${baseUrl}events/track_partial`, event, headers, {
|
|
703
1337
|
maxAttempts: 1,
|
|
704
1338
|
debug: (_a = options.debug) != null ? _a : false,
|
|
705
|
-
sdkName: options.sdkName
|
|
1339
|
+
sdkName: options.sdkName,
|
|
1340
|
+
timeoutMs: LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS
|
|
706
1341
|
}).catch(() => {
|
|
707
1342
|
});
|
|
708
1343
|
}
|
|
709
1344
|
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
710
1345
|
var _a, _b;
|
|
1346
|
+
const destination = currentReplayTraceDestination();
|
|
1347
|
+
if (destination && destination.kind !== "workshop") return;
|
|
711
1348
|
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
712
1349
|
if (!baseUrl) return;
|
|
713
1350
|
void postJson(
|
|
@@ -747,6 +1384,13 @@ function projectIdHeaders(projectId) {
|
|
|
747
1384
|
}
|
|
748
1385
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
749
1386
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
1387
|
+
function appGitOwnerId(prefix) {
|
|
1388
|
+
try {
|
|
1389
|
+
return `${prefix}:${randomUUID()}`;
|
|
1390
|
+
} catch (e) {
|
|
1391
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
750
1394
|
function mergePatches(target, source) {
|
|
751
1395
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
752
1396
|
const out = { ...target, ...source };
|
|
@@ -796,22 +1440,25 @@ function eventTelemetryProperties(patch) {
|
|
|
796
1440
|
}
|
|
797
1441
|
var EventShipper = class {
|
|
798
1442
|
constructor(opts) {
|
|
1443
|
+
this.appGitOwner = appGitOwnerId("event");
|
|
799
1444
|
this.buffers = /* @__PURE__ */ new Map();
|
|
800
1445
|
this.sticky = /* @__PURE__ */ new Map();
|
|
801
1446
|
this.timers = /* @__PURE__ */ new Map();
|
|
802
1447
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
803
1448
|
this.hasShutdown = false;
|
|
804
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
805
|
-
this.
|
|
806
|
-
this.
|
|
1449
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1450
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1451
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1452
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1453
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
807
1454
|
this.enabled = opts.enabled !== false;
|
|
808
1455
|
this.debug = opts.debug;
|
|
809
|
-
this.partialFlushMs = (
|
|
810
|
-
this.sdkName = (
|
|
1456
|
+
this.partialFlushMs = (_d = opts.partialFlushMs) != null ? _d : 1e3;
|
|
1457
|
+
this.sdkName = (_e = opts.sdkName) != null ? _e : "core";
|
|
811
1458
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
812
|
-
this.defaultEventName = (
|
|
1459
|
+
this.defaultEventName = (_f = opts.defaultEventName) != null ? _f : "ai_generation";
|
|
813
1460
|
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
814
|
-
this.localDebuggerUrl = (
|
|
1461
|
+
this.localDebuggerUrl = (_g = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _g : void 0;
|
|
815
1462
|
if (this.debug && this.localDebuggerUrl) {
|
|
816
1463
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
817
1464
|
}
|
|
@@ -822,8 +1469,8 @@ var EventShipper = class {
|
|
|
822
1469
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
823
1470
|
this.context = {
|
|
824
1471
|
library: {
|
|
825
|
-
name: (
|
|
826
|
-
version: (
|
|
1472
|
+
name: (_h = opts.libraryName) != null ? _h : "@raindrop-ai/core",
|
|
1473
|
+
version: (_i = opts.libraryVersion) != null ? _i : "0.0.0"
|
|
827
1474
|
},
|
|
828
1475
|
metadata: {
|
|
829
1476
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -831,6 +1478,9 @@ var EventShipper = class {
|
|
|
831
1478
|
}
|
|
832
1479
|
};
|
|
833
1480
|
}
|
|
1481
|
+
ownAppGitContextForShutdown() {
|
|
1482
|
+
this.ownsAppGitContext = true;
|
|
1483
|
+
}
|
|
834
1484
|
isDebugEnabled() {
|
|
835
1485
|
return this.debug;
|
|
836
1486
|
}
|
|
@@ -879,6 +1529,15 @@ var EventShipper = class {
|
|
|
879
1529
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
880
1530
|
if (!this.enabled) return;
|
|
881
1531
|
if (!eventId || !eventId.trim()) return;
|
|
1532
|
+
const capturedSticky = this.sticky.get(eventId);
|
|
1533
|
+
const eventAlreadyKnown = capturedSticky !== void 0 || this.buffers.has(eventId);
|
|
1534
|
+
const destination = currentReplayTraceDestination();
|
|
1535
|
+
const cloudReplay = destination !== void 0 && destination.kind !== "workshop";
|
|
1536
|
+
if ((capturedSticky == null ? void 0 : capturedSticky.replayOnly) === true || !eventAlreadyKnown && cloudReplay) {
|
|
1537
|
+
if (patch.isPending === false) this.sticky.delete(eventId);
|
|
1538
|
+
else this.sticky.set(eventId, { ...capturedSticky, replayOnly: true });
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
882
1541
|
const maxChars = resolveMaxTextFieldChars(this.maxTextFieldCharsOpt);
|
|
883
1542
|
if (typeof patch.input === "string" && patch.input.length > maxChars) {
|
|
884
1543
|
patch = { ...patch, input: capText(patch.input, maxChars) };
|
|
@@ -900,6 +1559,13 @@ var EventShipper = class {
|
|
|
900
1559
|
}
|
|
901
1560
|
const sticky = (_c = this.sticky.get(eventId)) != null ? _c : {};
|
|
902
1561
|
const existing = (_d = this.buffers.get(eventId)) != null ? _d : {};
|
|
1562
|
+
patch = {
|
|
1563
|
+
...patch,
|
|
1564
|
+
properties: withAppGitProperties(
|
|
1565
|
+
patch.properties,
|
|
1566
|
+
this.appGitContext.forOperation(eventId, patch.properties, this.appGitOwner)
|
|
1567
|
+
)
|
|
1568
|
+
};
|
|
903
1569
|
const merged = mergePatches(existing, patch);
|
|
904
1570
|
merged.isPending = (_g = (_f = (_e = patch.isPending) != null ? _e : existing.isPending) != null ? _f : sticky.isPending) != null ? _g : true;
|
|
905
1571
|
this.buffers.set(eventId, merged);
|
|
@@ -913,6 +1579,8 @@ var EventShipper = class {
|
|
|
913
1579
|
if (t) clearTimeout(t);
|
|
914
1580
|
if (merged.isPending === false) {
|
|
915
1581
|
await this.flushOne(eventId);
|
|
1582
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1583
|
+
else this.appGitContext.finishOperation(eventId);
|
|
916
1584
|
return;
|
|
917
1585
|
}
|
|
918
1586
|
const timeout = setTimeout(() => {
|
|
@@ -937,15 +1605,21 @@ var EventShipper = class {
|
|
|
937
1605
|
try {
|
|
938
1606
|
for (const t of this.timers.values()) clearTimeout(t);
|
|
939
1607
|
this.timers.clear();
|
|
1608
|
+
for (const [eventId, sticky] of this.sticky) {
|
|
1609
|
+
if (sticky.replayOnly) this.sticky.delete(eventId);
|
|
1610
|
+
}
|
|
940
1611
|
const settled = await raceWithTimeout(this.flush(), SHUTDOWN_DEADLINE_MS);
|
|
941
1612
|
if (!settled) this.warnShutdownDrop("in-flight request(s) at shutdown");
|
|
942
1613
|
} finally {
|
|
943
1614
|
this.shutdownDeadlineAt = void 0;
|
|
1615
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
944
1616
|
}
|
|
945
1617
|
}
|
|
946
1618
|
async trackSignal(signal) {
|
|
947
1619
|
var _a, _b;
|
|
948
1620
|
if (!this.enabled) return;
|
|
1621
|
+
const destination = currentReplayTraceDestination();
|
|
1622
|
+
if (destination && destination.kind !== "workshop") return;
|
|
949
1623
|
const body = [
|
|
950
1624
|
{
|
|
951
1625
|
event_id: signal.eventId,
|
|
@@ -980,6 +1654,8 @@ var EventShipper = class {
|
|
|
980
1654
|
}
|
|
981
1655
|
async identify(users) {
|
|
982
1656
|
if (!this.enabled) return;
|
|
1657
|
+
const destination = currentReplayTraceDestination();
|
|
1658
|
+
if (destination && destination.kind !== "workshop") return;
|
|
983
1659
|
const list = Array.isArray(users) ? users : [users];
|
|
984
1660
|
const body = list.filter((user) => {
|
|
985
1661
|
if (!(user == null ? void 0 : user.userId) || !user.userId.trim()) {
|
|
@@ -1032,8 +1708,9 @@ var EventShipper = class {
|
|
|
1032
1708
|
this.buffers.delete(eventId);
|
|
1033
1709
|
if (!accumulated) return;
|
|
1034
1710
|
const sticky = (_a = this.sticky.get(eventId)) != null ? _a : {};
|
|
1035
|
-
const
|
|
1036
|
-
const
|
|
1711
|
+
const isPending = (_c = (_b = accumulated.isPending) != null ? _b : sticky.isPending) != null ? _c : true;
|
|
1712
|
+
const eventName = (_e = (_d = accumulated.eventName) != null ? _d : sticky.eventName) != null ? _e : this.defaultEventName;
|
|
1713
|
+
const userId = (_f = accumulated.userId) != null ? _f : sticky.userId;
|
|
1037
1714
|
if (!userId) {
|
|
1038
1715
|
if (this.debug) {
|
|
1039
1716
|
console.warn(`${this.prefix} skipping track_partial for ${eventId}: missing userId`);
|
|
@@ -1041,14 +1718,13 @@ var EventShipper = class {
|
|
|
1041
1718
|
this.sticky.delete(eventId);
|
|
1042
1719
|
return;
|
|
1043
1720
|
}
|
|
1044
|
-
const { wizardSession, ...restProperties } = (
|
|
1721
|
+
const { wizardSession, ...restProperties } = (_g = accumulated.properties) != null ? _g : {};
|
|
1045
1722
|
let telemetryProperties = {};
|
|
1046
1723
|
try {
|
|
1047
1724
|
telemetryProperties = eventTelemetryProperties(accumulated);
|
|
1048
1725
|
} catch (e) {
|
|
1049
1726
|
}
|
|
1050
|
-
const convoId = (
|
|
1051
|
-
const isPending = (_h = (_g = accumulated.isPending) != null ? _g : sticky.isPending) != null ? _h : true;
|
|
1727
|
+
const convoId = (_h = accumulated.convoId) != null ? _h : sticky.convoId;
|
|
1052
1728
|
const payload = {
|
|
1053
1729
|
event_id: eventId,
|
|
1054
1730
|
user_id: userId,
|
|
@@ -1090,29 +1766,30 @@ var EventShipper = class {
|
|
|
1090
1766
|
endpoint: url
|
|
1091
1767
|
});
|
|
1092
1768
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1769
|
+
const mirror = this.localDebuggerUrl ? mirrorPartialEventToLocalDebugger(payload, {
|
|
1770
|
+
baseUrl: this.localDebuggerUrl,
|
|
1771
|
+
writeKey: this.writeKey,
|
|
1772
|
+
debug: this.debug,
|
|
1773
|
+
sdkName: this.sdkName
|
|
1774
|
+
}) : void 0;
|
|
1101
1775
|
if (!this.writeKey) {
|
|
1102
1776
|
if (!isPending) this.sticky.delete(eventId);
|
|
1777
|
+
if (mirror) await mirror;
|
|
1103
1778
|
return;
|
|
1104
1779
|
}
|
|
1105
1780
|
const opts = this.requestOpts();
|
|
1106
1781
|
if (!opts) {
|
|
1107
1782
|
this.warnShutdownDrop(`track_partial ${eventId}`);
|
|
1108
1783
|
if (!isPending) this.sticky.delete(eventId);
|
|
1784
|
+
if (mirror) await mirror;
|
|
1109
1785
|
return;
|
|
1110
1786
|
}
|
|
1111
1787
|
const p = postJson(url, payload, this.requestHeaders(), opts);
|
|
1112
|
-
|
|
1788
|
+
const combined = mirror ? Promise.all([mirror, p]).then(() => void 0) : p;
|
|
1789
|
+
this.inFlight.add(combined);
|
|
1113
1790
|
try {
|
|
1114
1791
|
try {
|
|
1115
|
-
await
|
|
1792
|
+
await combined;
|
|
1116
1793
|
if (this.debug) {
|
|
1117
1794
|
console.log(`${this.prefix} sent track_partial ${eventId} (${eventName})`);
|
|
1118
1795
|
}
|
|
@@ -1124,7 +1801,7 @@ var EventShipper = class {
|
|
|
1124
1801
|
);
|
|
1125
1802
|
}
|
|
1126
1803
|
} finally {
|
|
1127
|
-
this.inFlight.delete(
|
|
1804
|
+
this.inFlight.delete(combined);
|
|
1128
1805
|
}
|
|
1129
1806
|
if (!isPending) {
|
|
1130
1807
|
this.sticky.delete(eventId);
|
|
@@ -1370,6 +2047,13 @@ function redactJsonAttributeValue(key, value) {
|
|
|
1370
2047
|
if (scrubbedJson === json) return void 0;
|
|
1371
2048
|
return { stringValue: scrubbedJson };
|
|
1372
2049
|
}
|
|
2050
|
+
function appGitOwnerId2(prefix) {
|
|
2051
|
+
try {
|
|
2052
|
+
return `${prefix}:${randomUUID()}`;
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
1373
2057
|
function identityAttrs(args) {
|
|
1374
2058
|
return [
|
|
1375
2059
|
attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
|
|
@@ -1392,23 +2076,30 @@ function applyOtelSpanAttributeLimit(limit) {
|
|
|
1392
2076
|
}
|
|
1393
2077
|
var TraceShipper = class {
|
|
1394
2078
|
constructor(opts) {
|
|
2079
|
+
this.appGitOwner = appGitOwnerId2("trace");
|
|
2080
|
+
this.appGitEventIds = /* @__PURE__ */ new WeakMap();
|
|
2081
|
+
this.appGitActiveSpans = /* @__PURE__ */ new Map();
|
|
2082
|
+
this.appGitCaptured = /* @__PURE__ */ new WeakSet();
|
|
2083
|
+
this.appGitAdded = /* @__PURE__ */ new WeakMap();
|
|
1395
2084
|
this.queue = [];
|
|
1396
2085
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
1397
2086
|
this.hasShutdown = false;
|
|
1398
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1399
|
-
this.
|
|
1400
|
-
this.
|
|
2087
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2088
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
2089
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
2090
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
2091
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
1401
2092
|
this.enabled = opts.enabled !== false;
|
|
1402
2093
|
this.debug = opts.debug;
|
|
1403
2094
|
this.debugSpans = opts.debugSpans === true;
|
|
1404
|
-
this.flushIntervalMs = (
|
|
1405
|
-
this.maxBatchSize = (
|
|
1406
|
-
this.maxQueueSize = (
|
|
1407
|
-
this.sdkName = (
|
|
2095
|
+
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
2096
|
+
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
2097
|
+
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
2098
|
+
this.sdkName = (_g = opts.sdkName) != null ? _g : "core";
|
|
1408
2099
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
1409
|
-
this.serviceName = (
|
|
1410
|
-
this.serviceVersion = (
|
|
1411
|
-
this.localDebuggerUrl = (
|
|
2100
|
+
this.serviceName = (_h = opts.serviceName) != null ? _h : "raindrop.core";
|
|
2101
|
+
this.serviceVersion = (_i = opts.serviceVersion) != null ? _i : "0.0.0";
|
|
2102
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _j : void 0;
|
|
1412
2103
|
if (this.debug && this.localDebuggerUrl) {
|
|
1413
2104
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
1414
2105
|
}
|
|
@@ -1472,7 +2163,10 @@ var TraceShipper = class {
|
|
|
1472
2163
|
try {
|
|
1473
2164
|
const result = this.transformSpanHook(current);
|
|
1474
2165
|
if (result === null) return null;
|
|
1475
|
-
if (result !== void 0)
|
|
2166
|
+
if (result !== void 0) {
|
|
2167
|
+
copyReplayTraceDestination(current, result);
|
|
2168
|
+
current = result;
|
|
2169
|
+
}
|
|
1476
2170
|
} catch (err) {
|
|
1477
2171
|
if (this.debug) {
|
|
1478
2172
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -1482,13 +2176,19 @@ var TraceShipper = class {
|
|
|
1482
2176
|
}
|
|
1483
2177
|
}
|
|
1484
2178
|
try {
|
|
1485
|
-
|
|
2179
|
+
const normalized = normalizeModelUsageSpan(current);
|
|
2180
|
+
copyReplayTraceDestination(current, normalized);
|
|
2181
|
+
current = normalized;
|
|
1486
2182
|
} catch (e) {
|
|
1487
2183
|
}
|
|
1488
2184
|
if (!this.disableDefaultRedaction) {
|
|
1489
|
-
|
|
2185
|
+
const redacted = defaultTransformSpan(current);
|
|
2186
|
+
copyReplayTraceDestination(current, redacted);
|
|
2187
|
+
current = redacted;
|
|
1490
2188
|
}
|
|
1491
|
-
|
|
2189
|
+
const capped = this.capSpanAttributes(current);
|
|
2190
|
+
copyReplayTraceDestination(current, capped);
|
|
2191
|
+
return capped;
|
|
1492
2192
|
}
|
|
1493
2193
|
isDebugEnabled() {
|
|
1494
2194
|
return this.debug;
|
|
@@ -1500,46 +2200,84 @@ var TraceShipper = class {
|
|
|
1500
2200
|
return { ...this.authHeaders(), ...projectIdHeaders(this.projectId) };
|
|
1501
2201
|
}
|
|
1502
2202
|
startSpan(args) {
|
|
1503
|
-
var _a, _b;
|
|
2203
|
+
var _a, _b, _c;
|
|
1504
2204
|
const ids = createSpanIds(args.parent);
|
|
1505
2205
|
const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1506
2206
|
const attrs = [
|
|
1507
2207
|
attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId),
|
|
1508
2208
|
...identityAttrs(args),
|
|
1509
|
-
attrString("ai.operationId", args.operationId)
|
|
2209
|
+
attrString("ai.operationId", args.operationId),
|
|
2210
|
+
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1510
2211
|
];
|
|
1511
2212
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
1512
|
-
const
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
);
|
|
2213
|
+
const tracksAppGit = this.appGitActiveSpans.has(args.eventId) || this.appGitActiveSpans.size < 1e4;
|
|
2214
|
+
const appGitOverrides = appGitPropertiesFromAttributes(attrs);
|
|
2215
|
+
const span = {
|
|
2216
|
+
ids,
|
|
2217
|
+
name: args.name,
|
|
2218
|
+
startTimeUnixNano: started,
|
|
2219
|
+
attributes: withAppGitAttributes(
|
|
2220
|
+
attrs,
|
|
2221
|
+
this.appGitContext.forOperation(args.eventId, appGitOverrides, this.appGitOwner)
|
|
2222
|
+
)
|
|
2223
|
+
};
|
|
2224
|
+
rememberReplayTraceDestination(span);
|
|
2225
|
+
this.appGitCaptured.add(span);
|
|
2226
|
+
this.appGitEventIds.set(span, args.eventId);
|
|
2227
|
+
if (tracksAppGit) {
|
|
2228
|
+
this.appGitActiveSpans.set(args.eventId, ((_c = this.appGitActiveSpans.get(args.eventId)) != null ? _c : 0) + 1);
|
|
2229
|
+
}
|
|
2230
|
+
this.appGitAdded.set(span, new Set(span.attributes.filter((attr) => !attrs.includes(attr))));
|
|
2231
|
+
const openSpan = buildOtlpSpan({
|
|
2232
|
+
ids: span.ids,
|
|
2233
|
+
name: span.name,
|
|
2234
|
+
startTimeUnixNano: span.startTimeUnixNano,
|
|
2235
|
+
endTimeUnixNano: span.startTimeUnixNano,
|
|
2236
|
+
// placeholder — will be updated on endSpan
|
|
2237
|
+
attributes: span.attributes,
|
|
2238
|
+
status: { code: SpanStatusCode.UNSET }
|
|
2239
|
+
});
|
|
2240
|
+
copyReplayTraceDestination(span, openSpan);
|
|
2241
|
+
this.mirrorToLocalDebugger(openSpan);
|
|
1524
2242
|
return span;
|
|
1525
2243
|
}
|
|
1526
|
-
mirrorToLocalDebugger(span) {
|
|
1527
|
-
|
|
2244
|
+
mirrorToLocalDebugger(span, completed = false) {
|
|
2245
|
+
const destination = replayTraceDestinationFor(span);
|
|
2246
|
+
if (destination && destination.kind !== "workshop") return;
|
|
2247
|
+
const localDebuggerUrl = (destination == null ? void 0 : destination.kind) === "workshop" ? destination.url : this.localDebuggerUrl;
|
|
2248
|
+
if (!localDebuggerUrl) return;
|
|
1528
2249
|
const redacted = this.redactSpan(span);
|
|
1529
2250
|
if (redacted === null) return;
|
|
2251
|
+
if (completed && (destination == null ? void 0 : destination.kind) === "workshop") {
|
|
2252
|
+
recordReplayExportedSpan(
|
|
2253
|
+
destination,
|
|
2254
|
+
base64ToHex(redacted.spanId),
|
|
2255
|
+
base64ToHex(redacted.traceId)
|
|
2256
|
+
);
|
|
2257
|
+
}
|
|
1530
2258
|
const body = buildExportTraceServiceRequest([redacted], this.serviceName, this.serviceVersion);
|
|
1531
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
1532
|
-
baseUrl:
|
|
2259
|
+
const p = mirrorTraceExportToLocalDebugger(body, {
|
|
2260
|
+
baseUrl: localDebuggerUrl,
|
|
1533
2261
|
debug: false,
|
|
1534
2262
|
sdkName: this.sdkName
|
|
1535
2263
|
});
|
|
2264
|
+
this.inFlight.add(p);
|
|
2265
|
+
void p.finally(() => {
|
|
2266
|
+
this.inFlight.delete(p);
|
|
2267
|
+
});
|
|
1536
2268
|
}
|
|
1537
2269
|
endSpan(span, extra) {
|
|
1538
|
-
var _a, _b;
|
|
2270
|
+
var _a, _b, _c;
|
|
1539
2271
|
if (span.endTimeUnixNano) return;
|
|
1540
2272
|
span.endTimeUnixNano = (_a = extra == null ? void 0 : extra.endTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1541
2273
|
if ((_b = extra == null ? void 0 : extra.attributes) == null ? void 0 : _b.length) {
|
|
2274
|
+
const overrides = appGitPropertiesFromAttributes(extra.attributes);
|
|
2275
|
+
const eventId2 = this.appGitEventIds.get(span);
|
|
2276
|
+
const snapshot = eventId2 ? this.appGitContext.forOperation(eventId2, overrides, this.appGitOwner) : overrides;
|
|
2277
|
+
const added = this.appGitAdded.get(span);
|
|
2278
|
+
span.attributes = span.attributes.filter((attr) => !(added == null ? void 0 : added.has(attr)) || !attr || !Object.prototype.hasOwnProperty.call(overrides, APP_COMMIT_SHA) && !Object.prototype.hasOwnProperty.call(overrides, attr.key));
|
|
1542
2279
|
span.attributes.push(...extra.attributes);
|
|
2280
|
+
span.attributes = withAppGitAttributes(span.attributes, snapshot);
|
|
1543
2281
|
}
|
|
1544
2282
|
let status = extra == null ? void 0 : extra.status;
|
|
1545
2283
|
if (!status && (extra == null ? void 0 : extra.error) !== void 0) {
|
|
@@ -1554,30 +2292,65 @@ var TraceShipper = class {
|
|
|
1554
2292
|
attributes: span.attributes,
|
|
1555
2293
|
status
|
|
1556
2294
|
});
|
|
2295
|
+
copyReplayTraceDestination(span, otlp);
|
|
2296
|
+
this.appGitCaptured.add(otlp);
|
|
1557
2297
|
this.enqueue(otlp);
|
|
1558
|
-
this.mirrorToLocalDebugger(otlp);
|
|
2298
|
+
this.mirrorToLocalDebugger(otlp, true);
|
|
2299
|
+
const eventId = this.appGitEventIds.get(span);
|
|
2300
|
+
if (eventId && this.appGitActiveSpans.has(eventId)) {
|
|
2301
|
+
const remaining = ((_c = this.appGitActiveSpans.get(eventId)) != null ? _c : 1) - 1;
|
|
2302
|
+
if (remaining > 0) this.appGitActiveSpans.set(eventId, remaining);
|
|
2303
|
+
else {
|
|
2304
|
+
this.appGitActiveSpans.delete(eventId);
|
|
2305
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
2306
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(eventId);
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
1559
2309
|
}
|
|
1560
2310
|
createSpan(args) {
|
|
1561
2311
|
var _a;
|
|
1562
2312
|
const ids = createSpanIds(args.parent);
|
|
1563
2313
|
const attrs = [
|
|
1564
2314
|
attrString("ai.telemetry.metadata.raindrop.eventId", args.eventId),
|
|
1565
|
-
...identityAttrs(args)
|
|
2315
|
+
...identityAttrs(args),
|
|
2316
|
+
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1566
2317
|
];
|
|
1567
2318
|
if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
|
|
2319
|
+
const tracksAppGit = !this.appGitActiveSpans.has(args.eventId);
|
|
1568
2320
|
const otlp = buildOtlpSpan({
|
|
1569
2321
|
ids,
|
|
1570
2322
|
name: args.name,
|
|
1571
2323
|
startTimeUnixNano: args.startTimeUnixNano,
|
|
1572
2324
|
endTimeUnixNano: args.endTimeUnixNano,
|
|
1573
|
-
attributes:
|
|
2325
|
+
attributes: withAppGitAttributes(
|
|
2326
|
+
attrs,
|
|
2327
|
+
this.appGitContext.forOperation(
|
|
2328
|
+
args.eventId,
|
|
2329
|
+
appGitPropertiesFromAttributes(attrs),
|
|
2330
|
+
this.appGitOwner
|
|
2331
|
+
)
|
|
2332
|
+
),
|
|
1574
2333
|
status: args.status
|
|
1575
2334
|
});
|
|
2335
|
+
rememberReplayTraceDestination(otlp);
|
|
2336
|
+
this.appGitCaptured.add(otlp);
|
|
2337
|
+
if (tracksAppGit) {
|
|
2338
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(args.eventId, this.appGitOwner);
|
|
2339
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(args.eventId);
|
|
2340
|
+
}
|
|
1576
2341
|
this.enqueue(otlp);
|
|
1577
|
-
this.mirrorToLocalDebugger(otlp);
|
|
2342
|
+
this.mirrorToLocalDebugger(otlp, true);
|
|
1578
2343
|
}
|
|
1579
2344
|
enqueue(span) {
|
|
2345
|
+
var _a;
|
|
1580
2346
|
if (!this.enabled) return;
|
|
2347
|
+
const attributes = (_a = span.attributes) != null ? _a : [];
|
|
2348
|
+
const enriched = this.appGitCaptured.has(span) ? attributes : withAppGitAttributes(attributes, this.appGitContext.snapshot(appGitPropertiesFromAttributes(attributes)));
|
|
2349
|
+
if (enriched !== attributes) {
|
|
2350
|
+
const original = span;
|
|
2351
|
+
span = { ...span, attributes: enriched.filter((attr) => attr !== void 0) };
|
|
2352
|
+
copyReplayTraceDestination(original, span);
|
|
2353
|
+
}
|
|
1581
2354
|
if (this.debugSpans) {
|
|
1582
2355
|
const short = (s) => s ? s.slice(-8) : "none";
|
|
1583
2356
|
console.log(
|
|
@@ -1588,6 +2361,13 @@ var TraceShipper = class {
|
|
|
1588
2361
|
}
|
|
1589
2362
|
const redacted = this.redactSpan(span);
|
|
1590
2363
|
if (redacted === null) return;
|
|
2364
|
+
const destination = replayTraceDestinationFor(redacted);
|
|
2365
|
+
recordReplayExportedSpan(
|
|
2366
|
+
destination,
|
|
2367
|
+
base64ToHex(redacted.spanId),
|
|
2368
|
+
base64ToHex(redacted.traceId)
|
|
2369
|
+
);
|
|
2370
|
+
if ((destination == null ? void 0 : destination.kind) === "workshop") return;
|
|
1591
2371
|
if (this.queue.length >= this.maxQueueSize) {
|
|
1592
2372
|
this.queue.shift();
|
|
1593
2373
|
}
|
|
@@ -1606,47 +2386,67 @@ var TraceShipper = class {
|
|
|
1606
2386
|
}
|
|
1607
2387
|
}
|
|
1608
2388
|
async flush() {
|
|
1609
|
-
|
|
2389
|
+
var _a;
|
|
2390
|
+
if (!this.enabled) {
|
|
2391
|
+
await Promise.all([...this.inFlight].map((p) => p.catch(() => {
|
|
2392
|
+
})));
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
1610
2395
|
if (this.timer) {
|
|
1611
2396
|
clearTimeout(this.timer);
|
|
1612
2397
|
this.timer = void 0;
|
|
1613
2398
|
}
|
|
1614
2399
|
while (this.queue.length > 0) {
|
|
1615
2400
|
const batch = this.queue.splice(0, this.maxBatchSize);
|
|
1616
|
-
|
|
1617
|
-
const
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
`${this.prefix} shutdown flush deadline exceeded; dropping ${batch.length} spans`
|
|
1623
|
-
)
|
|
1624
|
-
);
|
|
1625
|
-
continue;
|
|
2401
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2402
|
+
for (const span of batch) {
|
|
2403
|
+
const destination = replayTraceDestinationFor(span);
|
|
2404
|
+
const spans = groups.get(destination);
|
|
2405
|
+
if (spans) spans.push(span);
|
|
2406
|
+
else groups.set(destination, [span]);
|
|
1626
2407
|
}
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
endpoint: url
|
|
1633
|
-
});
|
|
1634
|
-
}
|
|
1635
|
-
const p = postJson(url, body, this.requestHeaders(), opts);
|
|
1636
|
-
this.inFlight.add(p);
|
|
1637
|
-
try {
|
|
1638
|
-
try {
|
|
1639
|
-
await p;
|
|
1640
|
-
if (this.debug) console.log(`${this.prefix} sent ${batch.length} spans`);
|
|
1641
|
-
} catch (err) {
|
|
1642
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
2408
|
+
for (const [destination, spans] of groups) {
|
|
2409
|
+
if (!destination && !this.writeKey) continue;
|
|
2410
|
+
if ((destination == null ? void 0 : destination.kind) === "workshop") continue;
|
|
2411
|
+
const opts = this.requestOpts();
|
|
2412
|
+
if (!opts) {
|
|
1643
2413
|
rateLimitedLog(
|
|
1644
|
-
`${this.prefix}.
|
|
1645
|
-
() => console.warn(
|
|
2414
|
+
`${this.prefix}.shutdown_deadline`,
|
|
2415
|
+
() => console.warn(
|
|
2416
|
+
`${this.prefix} shutdown flush deadline exceeded; dropping ${spans.length} spans`
|
|
2417
|
+
)
|
|
1646
2418
|
);
|
|
2419
|
+
continue;
|
|
2420
|
+
}
|
|
2421
|
+
const body = buildExportTraceServiceRequest(spans, this.serviceName, this.serviceVersion);
|
|
2422
|
+
const url = destination ? replayTraceUrl(destination.url) : `${this.baseUrl}traces`;
|
|
2423
|
+
const headers = destination ? {
|
|
2424
|
+
Authorization: `Bearer ${destination.apiKey}`,
|
|
2425
|
+
"X-Raindrop-Replay-Id": destination.replayId,
|
|
2426
|
+
"X-Raindrop-Project-Id": (_a = destination.projectId) != null ? _a : "default"
|
|
2427
|
+
} : this.requestHeaders();
|
|
2428
|
+
if (this.debug) {
|
|
2429
|
+
console.log(`${this.prefix} sending traces batch`, {
|
|
2430
|
+
spans: spans.length,
|
|
2431
|
+
endpoint: url
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
const p = postJson(url, body, headers, opts);
|
|
2435
|
+
this.inFlight.add(p);
|
|
2436
|
+
try {
|
|
2437
|
+
try {
|
|
2438
|
+
await p;
|
|
2439
|
+
if (this.debug) console.log(`${this.prefix} sent ${spans.length} spans`);
|
|
2440
|
+
} catch (err) {
|
|
2441
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2442
|
+
rateLimitedLog(
|
|
2443
|
+
`${this.prefix}.send_spans_failed`,
|
|
2444
|
+
() => console.warn(`${this.prefix} failed to send ${spans.length} spans: ${msg}`)
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
} finally {
|
|
2448
|
+
this.inFlight.delete(p);
|
|
1647
2449
|
}
|
|
1648
|
-
} finally {
|
|
1649
|
-
this.inFlight.delete(p);
|
|
1650
2450
|
}
|
|
1651
2451
|
}
|
|
1652
2452
|
}
|
|
@@ -1689,131 +2489,160 @@ var TraceShipper = class {
|
|
|
1689
2489
|
if (!settled) {
|
|
1690
2490
|
rateLimitedLog(
|
|
1691
2491
|
`${this.prefix}.shutdown_deadline`,
|
|
1692
|
-
() => console.warn(
|
|
2492
|
+
() => console.warn(
|
|
2493
|
+
`${this.prefix} shutdown flush deadline exceeded; abandoning in-flight spans`
|
|
2494
|
+
)
|
|
1693
2495
|
);
|
|
1694
2496
|
}
|
|
1695
2497
|
} finally {
|
|
1696
2498
|
this.shutdownDeadlineAt = void 0;
|
|
2499
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1697
2500
|
}
|
|
1698
2501
|
}
|
|
1699
2502
|
};
|
|
1700
|
-
var
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
}
|
|
1714
|
-
isEmpty() {
|
|
1715
|
-
return this._stack.length === 0;
|
|
1716
|
-
}
|
|
1717
|
-
getStore() {
|
|
1718
|
-
return this._stack[this._stack.length - 1];
|
|
1719
|
-
}
|
|
1720
|
-
run(store, callback) {
|
|
1721
|
-
this._stack.push(store);
|
|
2503
|
+
var resolveLocal = (sourceDirectory, detectBranch, completed) => {
|
|
2504
|
+
const cwd = sourceDirectory ? resolve(sourceDirectory) : process.cwd();
|
|
2505
|
+
let cancelled = false;
|
|
2506
|
+
let active;
|
|
2507
|
+
let deadlineTimer;
|
|
2508
|
+
const deadline = Date.now() + 1e3;
|
|
2509
|
+
const run = (args, done) => {
|
|
2510
|
+
if (cancelled) return;
|
|
2511
|
+
const remaining = deadline - Date.now();
|
|
2512
|
+
if (remaining <= 0) {
|
|
2513
|
+
done(void 0);
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
1722
2516
|
try {
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
2517
|
+
active = execFile(
|
|
2518
|
+
"git",
|
|
2519
|
+
args,
|
|
2520
|
+
{
|
|
2521
|
+
cwd,
|
|
2522
|
+
encoding: "utf8",
|
|
2523
|
+
maxBuffer: 4096,
|
|
2524
|
+
windowsHide: true,
|
|
2525
|
+
env: {
|
|
2526
|
+
...process.env,
|
|
2527
|
+
// The selected application cwd, not the invoking shell's Git plumbing, owns identity.
|
|
2528
|
+
GIT_DIR: void 0,
|
|
2529
|
+
GIT_WORK_TREE: void 0,
|
|
2530
|
+
GIT_COMMON_DIR: void 0,
|
|
2531
|
+
GIT_NAMESPACE: void 0,
|
|
2532
|
+
GIT_INDEX_FILE: void 0,
|
|
2533
|
+
GIT_OBJECT_DIRECTORY: void 0,
|
|
2534
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: void 0,
|
|
2535
|
+
GIT_CONFIG_PARAMETERS: void 0,
|
|
2536
|
+
GIT_CONFIG_COUNT: "0",
|
|
2537
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
2538
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
2539
|
+
}
|
|
2540
|
+
},
|
|
2541
|
+
(error, stdout) => {
|
|
2542
|
+
clearTimeout(deadlineTimer);
|
|
2543
|
+
deadlineTimer = void 0;
|
|
2544
|
+
active = void 0;
|
|
2545
|
+
if (!cancelled) {
|
|
2546
|
+
try {
|
|
2547
|
+
done(error ? void 0 : stdout.trim());
|
|
2548
|
+
} catch (e) {
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
);
|
|
2553
|
+
active.unref();
|
|
2554
|
+
if (active.stdout && "unref" in active.stdout && typeof active.stdout.unref === "function")
|
|
2555
|
+
active.stdout.unref();
|
|
2556
|
+
if (active.stderr && "unref" in active.stderr && typeof active.stderr.unref === "function")
|
|
2557
|
+
active.stderr.unref();
|
|
2558
|
+
deadlineTimer = setTimeout(() => {
|
|
2559
|
+
try {
|
|
2560
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2561
|
+
} catch (e) {
|
|
2562
|
+
}
|
|
2563
|
+
}, remaining);
|
|
2564
|
+
deadlineTimer.unref();
|
|
2565
|
+
} catch (e) {
|
|
2566
|
+
try {
|
|
2567
|
+
done(void 0);
|
|
2568
|
+
} catch (e2) {
|
|
2569
|
+
}
|
|
1726
2570
|
}
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
2571
|
+
};
|
|
2572
|
+
const scheduled = setTimeout(() => {
|
|
2573
|
+
try {
|
|
2574
|
+
run(["rev-parse", "HEAD"], (rawSha) => {
|
|
2575
|
+
const commitSha = validAppCommitSha(rawSha);
|
|
2576
|
+
if (!commitSha) {
|
|
2577
|
+
completed({});
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
run(["-c", "core.fsmonitor=false", "status", "--porcelain"], (status) => {
|
|
2581
|
+
const finish = (branch) => {
|
|
2582
|
+
run(["rev-parse", "HEAD"], (finalSha) => {
|
|
2583
|
+
const coherent = validAppCommitSha(finalSha) === commitSha;
|
|
2584
|
+
completed({
|
|
2585
|
+
commitSha,
|
|
2586
|
+
...coherent && status !== void 0 ? { commitDirty: status !== "" } : {},
|
|
2587
|
+
...coherent && branch && branch !== "HEAD" ? { branch } : {}
|
|
2588
|
+
});
|
|
2589
|
+
});
|
|
2590
|
+
};
|
|
2591
|
+
if (detectBranch) run(["symbolic-ref", "--quiet", "--short", "HEAD"], finish);
|
|
2592
|
+
else finish();
|
|
2593
|
+
});
|
|
2594
|
+
});
|
|
2595
|
+
} catch (e) {
|
|
2596
|
+
completed({});
|
|
2597
|
+
}
|
|
2598
|
+
}, 0);
|
|
2599
|
+
scheduled.unref();
|
|
2600
|
+
return () => {
|
|
2601
|
+
cancelled = true;
|
|
2602
|
+
clearTimeout(scheduled);
|
|
2603
|
+
clearTimeout(deadlineTimer);
|
|
2604
|
+
try {
|
|
2605
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2606
|
+
} catch (e) {
|
|
1739
2607
|
}
|
|
1740
|
-
|
|
1741
|
-
this._storage = this._fallback;
|
|
1742
|
-
}
|
|
1743
|
-
maybeAdoptAsyncLocalStorage() {
|
|
1744
|
-
if (!this._fallback || !this._fallback.isEmpty()) return;
|
|
1745
|
-
const Ctor = getAsyncLocalStorageCtor();
|
|
1746
|
-
if (!Ctor) return;
|
|
1747
|
-
this._storage = new Ctor();
|
|
1748
|
-
this._fallback = null;
|
|
1749
|
-
}
|
|
1750
|
-
isReady() {
|
|
1751
|
-
return true;
|
|
1752
|
-
}
|
|
1753
|
-
getParentSpanIds() {
|
|
1754
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1755
|
-
const span = this._storage.getStore();
|
|
1756
|
-
if (!span || span === NOOP_SPAN) return void 0;
|
|
1757
|
-
return {
|
|
1758
|
-
traceIdB64: span.traceIdB64,
|
|
1759
|
-
spanIdB64: span.spanIdB64,
|
|
1760
|
-
eventId: span.eventId
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
runInContext(span, callback) {
|
|
1764
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1765
|
-
return this._storage.run(span, callback);
|
|
1766
|
-
}
|
|
1767
|
-
getCurrentSpan() {
|
|
1768
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1769
|
-
return this._storage.getStore();
|
|
1770
|
-
}
|
|
2608
|
+
};
|
|
1771
2609
|
};
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
if (!_contextManager) {
|
|
1775
|
-
_contextManager = globalThis.RAINDROP_CONTEXT_MANAGER ? new globalThis.RAINDROP_CONTEXT_MANAGER() : new RaindropContextManager();
|
|
1776
|
-
}
|
|
1777
|
-
return _contextManager;
|
|
2610
|
+
function createAppGitContext2(options, runtime = {}) {
|
|
2611
|
+
return new AppGitContext(options, { ...runtime, resolveLocal });
|
|
1778
2612
|
}
|
|
1779
|
-
function
|
|
2613
|
+
function hasDestination(options) {
|
|
1780
2614
|
var _a;
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
function withCurrent(span, callback) {
|
|
1784
|
-
return getContextManager().runInContext(span, callback);
|
|
1785
|
-
}
|
|
1786
|
-
async function getCurrentParentSpanContext() {
|
|
1787
|
-
return getContextManager().getParentSpanIds();
|
|
1788
|
-
}
|
|
1789
|
-
async function runWithParentSpanContext(ctx, fn) {
|
|
1790
|
-
const cm = getContextManager();
|
|
1791
|
-
const span = {
|
|
1792
|
-
traceIdB64: ctx.traceIdB64,
|
|
1793
|
-
spanIdB64: ctx.spanIdB64,
|
|
1794
|
-
eventId: ctx.eventId
|
|
1795
|
-
};
|
|
1796
|
-
return cm.runInContext(span, fn);
|
|
2615
|
+
if (options.enabled === false) return false;
|
|
2616
|
+
return Boolean(((_a = options.writeKey) == null ? void 0 : _a.trim()) || resolveLocalDebuggerBaseUrl(options.localDebuggerUrl));
|
|
1797
2617
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
if ("error" in result && result.error !== void 0) {
|
|
1809
|
-
throw result.error;
|
|
2618
|
+
var EventShipper2 = class extends EventShipper {
|
|
2619
|
+
constructor(options) {
|
|
2620
|
+
var _a;
|
|
2621
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2622
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2623
|
+
try {
|
|
2624
|
+
super({ ...options, appGitContext });
|
|
2625
|
+
} catch (error) {
|
|
2626
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2627
|
+
throw error;
|
|
1810
2628
|
}
|
|
1811
|
-
if (
|
|
1812
|
-
|
|
2629
|
+
if (ownsAppGitContext) this.ownAppGitContextForShutdown();
|
|
2630
|
+
}
|
|
2631
|
+
};
|
|
2632
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
2633
|
+
constructor(options) {
|
|
2634
|
+
var _a;
|
|
2635
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2636
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2637
|
+
try {
|
|
2638
|
+
super({ ...options, appGitContext });
|
|
2639
|
+
} catch (error) {
|
|
2640
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2641
|
+
throw error;
|
|
1813
2642
|
}
|
|
1814
|
-
|
|
2643
|
+
this.ownsAppGitContext = ownsAppGitContext;
|
|
1815
2644
|
}
|
|
1816
|
-
}
|
|
2645
|
+
};
|
|
1817
2646
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
1818
2647
|
var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
|
|
1819
2648
|
"OpenTelemetry SDK Context Key SUPPRESS_TRACING"
|
|
@@ -3348,13 +4177,13 @@ var RaindropTelemetryIntegration = class {
|
|
|
3348
4177
|
};
|
|
3349
4178
|
// ── onStepStart ─────────────────────────────────────────────────────────
|
|
3350
4179
|
this.onStepStart = (event) => {
|
|
3351
|
-
const
|
|
3352
|
-
if (!(
|
|
3353
|
-
const isStream =
|
|
3354
|
-
const stepOperationId = isStream ? `${
|
|
3355
|
-
const { operationName, resourceName } = opName(stepOperationId,
|
|
4180
|
+
const state2 = this.getState(event.callId);
|
|
4181
|
+
if (!(state2 == null ? void 0 : state2.rootSpan) || !state2.rootParent) return;
|
|
4182
|
+
const isStream = state2.operationId === "ai.streamText" || state2.operationId === "ai.streamObject";
|
|
4183
|
+
const stepOperationId = isStream ? `${state2.operationId}.doStream` : `${state2.operationId}.doGenerate`;
|
|
4184
|
+
const { operationName, resourceName } = opName(stepOperationId, state2.functionId);
|
|
3356
4185
|
const inputAttrs = [];
|
|
3357
|
-
if (
|
|
4186
|
+
if (state2.recordInputs) {
|
|
3358
4187
|
if (event.promptMessages) {
|
|
3359
4188
|
inputAttrs.push(attrString("ai.prompt.messages", safeJsonWithUint8(event.promptMessages)));
|
|
3360
4189
|
}
|
|
@@ -3377,25 +4206,25 @@ var RaindropTelemetryIntegration = class {
|
|
|
3377
4206
|
}
|
|
3378
4207
|
const stepSpan = this.traceShipper.startSpan({
|
|
3379
4208
|
name: stepOperationId,
|
|
3380
|
-
parent:
|
|
3381
|
-
eventId:
|
|
3382
|
-
...
|
|
4209
|
+
parent: state2.rootParent,
|
|
4210
|
+
eventId: state2.eventId,
|
|
4211
|
+
...state2.identity,
|
|
3383
4212
|
operationId: stepOperationId,
|
|
3384
4213
|
attributes: [
|
|
3385
4214
|
attrString("operation.name", operationName),
|
|
3386
4215
|
attrString("resource.name", resourceName),
|
|
3387
|
-
attrString("ai.telemetry.functionId",
|
|
4216
|
+
attrString("ai.telemetry.functionId", state2.functionId),
|
|
3388
4217
|
...attrsFromModelProvider(event.provider),
|
|
3389
4218
|
attrString("ai.model.id", event.modelId),
|
|
3390
4219
|
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, event.modelId),
|
|
3391
4220
|
...inputAttrs,
|
|
3392
|
-
...handoffSpanAttrs(
|
|
4221
|
+
...handoffSpanAttrs(state2.handoff)
|
|
3393
4222
|
]
|
|
3394
4223
|
});
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
4224
|
+
state2.stepSpan = stepSpan;
|
|
4225
|
+
state2.stepParent = this.spanParentRef(stepSpan);
|
|
4226
|
+
state2.stepProvider = event.provider;
|
|
4227
|
+
state2.stepModelId = event.modelId;
|
|
3399
4228
|
};
|
|
3400
4229
|
this.onToolExecutionStart = (event) => this.toolExecutionStart(event);
|
|
3401
4230
|
this.onToolExecutionEnd = (event) => this.toolExecutionEnd(event);
|
|
@@ -3422,33 +4251,33 @@ var RaindropTelemetryIntegration = class {
|
|
|
3422
4251
|
var _a, _b, _c, _d, _e;
|
|
3423
4252
|
const callId = (_b = event.callId) != null ? _b : (_a = event.chunk) == null ? void 0 : _a.callId;
|
|
3424
4253
|
if (!callId) return;
|
|
3425
|
-
const
|
|
3426
|
-
if (!
|
|
4254
|
+
const state2 = this.getState(callId);
|
|
4255
|
+
if (!state2) return;
|
|
3427
4256
|
const chunk = event.chunk;
|
|
3428
4257
|
if (!chunk || typeof chunk !== "object") return;
|
|
3429
4258
|
if (chunk.type === "text-delta") {
|
|
3430
4259
|
const delta = (_c = chunk.textDelta) != null ? _c : chunk.delta;
|
|
3431
4260
|
if (typeof delta === "string") {
|
|
3432
|
-
if (
|
|
3433
|
-
|
|
4261
|
+
if (state2.accumulatedText.length <= effectiveMaxTextFieldChars()) {
|
|
4262
|
+
state2.accumulatedText += delta;
|
|
3434
4263
|
}
|
|
3435
|
-
this.emitLive(
|
|
4264
|
+
this.emitLive(state2, "text_delta", delta);
|
|
3436
4265
|
}
|
|
3437
4266
|
} else if (chunk.type === "reasoning" || chunk.type === "reasoning-delta") {
|
|
3438
4267
|
const text = (_e = (_d = chunk.textDelta) != null ? _d : chunk.text) != null ? _e : chunk.delta;
|
|
3439
4268
|
if (typeof text === "string") {
|
|
3440
|
-
this.emitLive(
|
|
4269
|
+
this.emitLive(state2, "reasoning_delta", text);
|
|
3441
4270
|
}
|
|
3442
4271
|
}
|
|
3443
4272
|
};
|
|
3444
4273
|
// ── onStepFinish ────────────────────────────────────────────────────────
|
|
3445
4274
|
this.onStepFinish = (event) => {
|
|
3446
4275
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
3447
|
-
const
|
|
3448
|
-
if (!(
|
|
3449
|
-
const responseModelId = (_b = (_a = event.response) == null ? void 0 : _a.modelId) != null ? _b :
|
|
4276
|
+
const state2 = this.getState(event.callId);
|
|
4277
|
+
if (!(state2 == null ? void 0 : state2.stepSpan)) return;
|
|
4278
|
+
const responseModelId = (_b = (_a = event.response) == null ? void 0 : _a.modelId) != null ? _b : state2.stepModelId;
|
|
3450
4279
|
const outputAttrs = [];
|
|
3451
|
-
if (
|
|
4280
|
+
if (state2.recordOutputs) {
|
|
3452
4281
|
outputAttrs.push(
|
|
3453
4282
|
attrString("ai.response.finishReason", event.finishReason),
|
|
3454
4283
|
attrString("ai.response.text", capText2((_c = event.text) != null ? _c : void 0)),
|
|
@@ -3493,7 +4322,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
3493
4322
|
if (usage) {
|
|
3494
4323
|
const usageMetrics = extractUsageMetricsFromUsage(
|
|
3495
4324
|
usage,
|
|
3496
|
-
|
|
4325
|
+
state2.stepProvider,
|
|
3497
4326
|
event.providerMetadata
|
|
3498
4327
|
);
|
|
3499
4328
|
outputAttrs.push(
|
|
@@ -3506,51 +4335,51 @@ var RaindropTelemetryIntegration = class {
|
|
|
3506
4335
|
...buildRawModelUsageAttributes(usageMetrics)
|
|
3507
4336
|
);
|
|
3508
4337
|
}
|
|
3509
|
-
this.emitProviderExecutedToolSpans(event,
|
|
3510
|
-
this.traceShipper.endSpan(
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
4338
|
+
this.emitProviderExecutedToolSpans(event, state2);
|
|
4339
|
+
this.traceShipper.endSpan(state2.stepSpan, { attributes: outputAttrs });
|
|
4340
|
+
state2.stepSpan = void 0;
|
|
4341
|
+
state2.stepParent = void 0;
|
|
4342
|
+
state2.stepProvider = void 0;
|
|
4343
|
+
state2.stepModelId = void 0;
|
|
3515
4344
|
};
|
|
3516
4345
|
// ── onEmbedStart ────────────────────────────────────────────────────────
|
|
3517
4346
|
this.onEmbedStart = (event) => {
|
|
3518
|
-
const
|
|
3519
|
-
if (!(
|
|
3520
|
-
const { operationName, resourceName } = opName(event.operationId,
|
|
3521
|
-
const inputAttrs =
|
|
4347
|
+
const state2 = this.getState(event.callId);
|
|
4348
|
+
if (!(state2 == null ? void 0 : state2.rootSpan) || !state2.rootParent) return;
|
|
4349
|
+
const { operationName, resourceName } = opName(event.operationId, state2.functionId);
|
|
4350
|
+
const inputAttrs = state2.recordInputs ? [attrString("ai.values", safeJsonWithUint8(event.values))] : [];
|
|
3522
4351
|
const embedSpan = this.traceShipper.startSpan({
|
|
3523
4352
|
name: event.operationId,
|
|
3524
|
-
parent:
|
|
3525
|
-
eventId:
|
|
3526
|
-
...
|
|
4353
|
+
parent: state2.rootParent,
|
|
4354
|
+
eventId: state2.eventId,
|
|
4355
|
+
...state2.identity,
|
|
3527
4356
|
operationId: event.operationId,
|
|
3528
4357
|
attributes: [
|
|
3529
4358
|
attrString("operation.name", operationName),
|
|
3530
4359
|
attrString("resource.name", resourceName),
|
|
3531
|
-
attrString("ai.telemetry.functionId",
|
|
4360
|
+
attrString("ai.telemetry.functionId", state2.functionId),
|
|
3532
4361
|
...inputAttrs,
|
|
3533
|
-
...handoffSpanAttrs(
|
|
4362
|
+
...handoffSpanAttrs(state2.handoff)
|
|
3534
4363
|
]
|
|
3535
4364
|
});
|
|
3536
|
-
|
|
4365
|
+
state2.embedSpans.set(event.embedCallId, embedSpan);
|
|
3537
4366
|
};
|
|
3538
4367
|
// ── onEmbedFinish ───────────────────────────────────────────────────────
|
|
3539
4368
|
this.onEmbedFinish = (event) => {
|
|
3540
4369
|
var _a;
|
|
3541
|
-
const
|
|
3542
|
-
if (!
|
|
3543
|
-
const embedSpan =
|
|
4370
|
+
const state2 = this.getState(event.callId);
|
|
4371
|
+
if (!state2) return;
|
|
4372
|
+
const embedSpan = state2.embedSpans.get(event.embedCallId);
|
|
3544
4373
|
if (!embedSpan) return;
|
|
3545
4374
|
const outputAttrs = [];
|
|
3546
|
-
if (
|
|
4375
|
+
if (state2.recordOutputs) {
|
|
3547
4376
|
outputAttrs.push(attrString("ai.embeddings", safeJsonWithUint8(event.embeddings)));
|
|
3548
4377
|
}
|
|
3549
4378
|
if (((_a = event.usage) == null ? void 0 : _a.tokens) != null) {
|
|
3550
4379
|
outputAttrs.push(attrInt("ai.usage.tokens", event.usage.tokens));
|
|
3551
4380
|
}
|
|
3552
4381
|
this.traceShipper.endSpan(embedSpan, { attributes: outputAttrs });
|
|
3553
|
-
|
|
4382
|
+
state2.embedSpans.delete(event.embedCallId);
|
|
3554
4383
|
};
|
|
3555
4384
|
// v7 canary.159 renamed `onEmbedFinish` -> `onEmbedEnd`. Both names forward
|
|
3556
4385
|
// to the same implementation; the installed SDK only wires up whichever it
|
|
@@ -3558,16 +4387,16 @@ var RaindropTelemetryIntegration = class {
|
|
|
3558
4387
|
this.onEmbedEnd = (event) => this.onEmbedFinish(event);
|
|
3559
4388
|
// ── onFinish ────────────────────────────────────────────────────────────
|
|
3560
4389
|
this.onFinish = (event) => {
|
|
3561
|
-
const
|
|
3562
|
-
if (!
|
|
3563
|
-
const isEmbed =
|
|
4390
|
+
const state2 = this.getState(event.callId);
|
|
4391
|
+
if (!state2) return;
|
|
4392
|
+
const isEmbed = state2.operationId === "ai.embed" || state2.operationId === "ai.embedMany";
|
|
3564
4393
|
if (isEmbed) {
|
|
3565
|
-
this.finishEmbed(event,
|
|
4394
|
+
this.finishEmbed(event, state2);
|
|
3566
4395
|
} else {
|
|
3567
|
-
this.finishGenerate(event,
|
|
4396
|
+
this.finishGenerate(event, state2);
|
|
3568
4397
|
}
|
|
3569
|
-
if (
|
|
3570
|
-
this.traceShipper.endSpan(
|
|
4398
|
+
if (state2.subagentToolCallSpan) {
|
|
4399
|
+
this.traceShipper.endSpan(state2.subagentToolCallSpan);
|
|
3571
4400
|
}
|
|
3572
4401
|
this.cleanup(event.callId);
|
|
3573
4402
|
};
|
|
@@ -3582,42 +4411,42 @@ var RaindropTelemetryIntegration = class {
|
|
|
3582
4411
|
var _a;
|
|
3583
4412
|
const event = error;
|
|
3584
4413
|
if (!(event == null ? void 0 : event.callId)) return;
|
|
3585
|
-
const
|
|
3586
|
-
if (!
|
|
4414
|
+
const state2 = this.getState(event.callId);
|
|
4415
|
+
if (!state2) return;
|
|
3587
4416
|
const actualError = (_a = event.error) != null ? _a : error;
|
|
3588
|
-
if (
|
|
3589
|
-
this.traceShipper.endSpan(
|
|
3590
|
-
|
|
3591
|
-
|
|
4417
|
+
if (state2.stepSpan) {
|
|
4418
|
+
this.traceShipper.endSpan(state2.stepSpan, { error: actualError });
|
|
4419
|
+
state2.stepProvider = void 0;
|
|
4420
|
+
state2.stepModelId = void 0;
|
|
3592
4421
|
}
|
|
3593
|
-
for (const embedSpan of
|
|
4422
|
+
for (const embedSpan of state2.embedSpans.values()) {
|
|
3594
4423
|
this.traceShipper.endSpan(embedSpan, { error: actualError });
|
|
3595
4424
|
}
|
|
3596
|
-
|
|
3597
|
-
for (const toolCallId of
|
|
4425
|
+
state2.embedSpans.clear();
|
|
4426
|
+
for (const toolCallId of state2.parentContextToolCallIds) {
|
|
3598
4427
|
this.priorParentContexts.delete(toolCallId);
|
|
3599
4428
|
}
|
|
3600
|
-
|
|
3601
|
-
for (const toolSpan of
|
|
4429
|
+
state2.parentContextToolCallIds.clear();
|
|
4430
|
+
for (const toolSpan of state2.toolSpans.values()) {
|
|
3602
4431
|
this.traceShipper.endSpan(toolSpan, { error: actualError });
|
|
3603
4432
|
}
|
|
3604
|
-
|
|
4433
|
+
state2.toolSpans.clear();
|
|
3605
4434
|
const abortReason = describeAbortReason(actualError);
|
|
3606
|
-
if (
|
|
3607
|
-
this.traceShipper.endSpan(
|
|
4435
|
+
if (state2.rootSpan) {
|
|
4436
|
+
this.traceShipper.endSpan(state2.rootSpan, {
|
|
3608
4437
|
error: actualError,
|
|
3609
|
-
attributes: this.abortOutcomeAttrs(
|
|
4438
|
+
attributes: this.abortOutcomeAttrs(state2, abortReason, "error")
|
|
3610
4439
|
});
|
|
3611
4440
|
}
|
|
3612
|
-
if (
|
|
3613
|
-
this.traceShipper.endSpan(
|
|
4441
|
+
if (state2.subagentToolCallSpan) {
|
|
4442
|
+
this.traceShipper.endSpan(state2.subagentToolCallSpan, { error: actualError });
|
|
3614
4443
|
}
|
|
3615
|
-
const isEmbed =
|
|
4444
|
+
const isEmbed = state2.operationId === "ai.embed" || state2.operationId === "ai.embedMany";
|
|
3616
4445
|
if (!isEmbed) {
|
|
3617
|
-
const errorIsTheRunsOutcome =
|
|
4446
|
+
const errorIsTheRunsOutcome = state2.handoff !== void 0 && !state2.nestedInEvent;
|
|
3618
4447
|
this.finalizeGenerateEvent(
|
|
3619
|
-
|
|
3620
|
-
|
|
4448
|
+
state2,
|
|
4449
|
+
state2.accumulatedText || void 0,
|
|
3621
4450
|
void 0,
|
|
3622
4451
|
false,
|
|
3623
4452
|
errorIsTheRunsOutcome ? { fallbackOutput: abortReason } : void 0
|
|
@@ -3636,51 +4465,51 @@ var RaindropTelemetryIntegration = class {
|
|
|
3636
4465
|
this.onAbort = (event) => {
|
|
3637
4466
|
const callId = event == null ? void 0 : event.callId;
|
|
3638
4467
|
if (!callId) return;
|
|
3639
|
-
const
|
|
3640
|
-
if (!
|
|
4468
|
+
const state2 = this.getState(callId);
|
|
4469
|
+
if (!state2) return;
|
|
3641
4470
|
const abortedAttr = attrString("ai.response.aborted", "true");
|
|
3642
|
-
if (
|
|
3643
|
-
this.traceShipper.endSpan(
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
4471
|
+
if (state2.stepSpan) {
|
|
4472
|
+
this.traceShipper.endSpan(state2.stepSpan, { attributes: [abortedAttr] });
|
|
4473
|
+
state2.stepSpan = void 0;
|
|
4474
|
+
state2.stepParent = void 0;
|
|
4475
|
+
state2.stepProvider = void 0;
|
|
4476
|
+
state2.stepModelId = void 0;
|
|
3648
4477
|
}
|
|
3649
|
-
for (const embedSpan of
|
|
4478
|
+
for (const embedSpan of state2.embedSpans.values()) {
|
|
3650
4479
|
this.traceShipper.endSpan(embedSpan, { attributes: [abortedAttr] });
|
|
3651
4480
|
}
|
|
3652
|
-
|
|
3653
|
-
for (const toolCallId of
|
|
4481
|
+
state2.embedSpans.clear();
|
|
4482
|
+
for (const toolCallId of state2.parentContextToolCallIds) {
|
|
3654
4483
|
this.priorParentContexts.delete(toolCallId);
|
|
3655
4484
|
}
|
|
3656
|
-
|
|
3657
|
-
for (const toolSpan of
|
|
4485
|
+
state2.parentContextToolCallIds.clear();
|
|
4486
|
+
for (const toolSpan of state2.toolSpans.values()) {
|
|
3658
4487
|
this.traceShipper.endSpan(toolSpan, { attributes: [abortedAttr] });
|
|
3659
4488
|
}
|
|
3660
|
-
|
|
3661
|
-
const abortIsTheRunsOutcome =
|
|
3662
|
-
if (
|
|
3663
|
-
this.traceShipper.endSpan(
|
|
4489
|
+
state2.toolSpans.clear();
|
|
4490
|
+
const abortIsTheRunsOutcome = state2.handoff !== void 0 && !state2.nestedInEvent;
|
|
4491
|
+
if (state2.rootSpan) {
|
|
4492
|
+
this.traceShipper.endSpan(state2.rootSpan, {
|
|
3664
4493
|
attributes: [
|
|
3665
4494
|
abortedAttr,
|
|
3666
|
-
attrInt("ai.toolCall.count",
|
|
4495
|
+
attrInt("ai.toolCall.count", state2.toolCallCount),
|
|
3667
4496
|
// An aborted detached child IS a cancelled sub-agent, and a cancelled
|
|
3668
4497
|
// run is span-for-span identical to a finished one — spans close,
|
|
3669
4498
|
// nothing errors, there is just no answer. So it is the one outcome
|
|
3670
4499
|
// that has to be stated, and the child states it on itself.
|
|
3671
4500
|
...abortIsTheRunsOutcome ? cancelledSpanAttrs() : [],
|
|
3672
|
-
...abortIsTheRunsOutcome ? this.abortOutcomeAttrs(
|
|
4501
|
+
...abortIsTheRunsOutcome ? this.abortOutcomeAttrs(state2, SUBAGENT_CANCELLED_OUTPUT, "stop") : []
|
|
3673
4502
|
]
|
|
3674
4503
|
});
|
|
3675
4504
|
}
|
|
3676
|
-
if (
|
|
3677
|
-
this.traceShipper.endSpan(
|
|
4505
|
+
if (state2.subagentToolCallSpan) {
|
|
4506
|
+
this.traceShipper.endSpan(state2.subagentToolCallSpan, {
|
|
3678
4507
|
attributes: [abortedAttr]
|
|
3679
4508
|
});
|
|
3680
4509
|
}
|
|
3681
4510
|
this.finalizeGenerateEvent(
|
|
3682
|
-
|
|
3683
|
-
|
|
4511
|
+
state2,
|
|
4512
|
+
state2.accumulatedText || void 0,
|
|
3684
4513
|
void 0,
|
|
3685
4514
|
false,
|
|
3686
4515
|
abortIsTheRunsOutcome ? {
|
|
@@ -3688,7 +4517,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
3688
4517
|
properties: { [HANDOFF_TERMINAL_PROPERTY_KEY]: HANDOFF_TERMINAL_CANCELLED }
|
|
3689
4518
|
} : void 0
|
|
3690
4519
|
);
|
|
3691
|
-
if (abortIsTheRunsOutcome) this.subagents.noteSettled(
|
|
4520
|
+
if (abortIsTheRunsOutcome) this.subagents.noteSettled(state2.eventId);
|
|
3692
4521
|
this.cleanup(callId);
|
|
3693
4522
|
};
|
|
3694
4523
|
// ── executeTool ─────────────────────────────────────────────────────────
|
|
@@ -3697,14 +4526,14 @@ var RaindropTelemetryIntegration = class {
|
|
|
3697
4526
|
toolCallId,
|
|
3698
4527
|
execute
|
|
3699
4528
|
}) => {
|
|
3700
|
-
const
|
|
3701
|
-
const toolSpan =
|
|
4529
|
+
const state2 = this.getState(callId);
|
|
4530
|
+
const toolSpan = state2 == null ? void 0 : state2.toolSpans.get(toolCallId);
|
|
3702
4531
|
if (!toolSpan) return execute();
|
|
3703
4532
|
return runWithParentSpanContext(
|
|
3704
4533
|
{
|
|
3705
4534
|
traceIdB64: toolSpan.ids.traceIdB64,
|
|
3706
4535
|
spanIdB64: toolSpan.ids.spanIdB64,
|
|
3707
|
-
eventId:
|
|
4536
|
+
eventId: state2.eventId
|
|
3708
4537
|
},
|
|
3709
4538
|
() => execute()
|
|
3710
4539
|
);
|
|
@@ -3753,35 +4582,35 @@ var RaindropTelemetryIntegration = class {
|
|
|
3753
4582
|
activeDispatch() {
|
|
3754
4583
|
var _a;
|
|
3755
4584
|
const parentTool = getCurrentParentToolContext();
|
|
3756
|
-
let
|
|
4585
|
+
let state2 = parentTool ? this.getState(parentTool.parentCallId) : void 0;
|
|
3757
4586
|
const inheritedEventId = (_a = getContextManager().getParentSpanIds()) == null ? void 0 : _a.eventId;
|
|
3758
|
-
if (!
|
|
4587
|
+
if (!state2 && inheritedEventId) {
|
|
3759
4588
|
for (const candidate of this.callStates.values()) {
|
|
3760
4589
|
if (candidate.eventId === inheritedEventId) {
|
|
3761
|
-
|
|
4590
|
+
state2 = candidate;
|
|
3762
4591
|
break;
|
|
3763
4592
|
}
|
|
3764
4593
|
}
|
|
3765
4594
|
}
|
|
3766
|
-
if (!
|
|
4595
|
+
if (!state2) return void 0;
|
|
3767
4596
|
return {
|
|
3768
|
-
eventId:
|
|
3769
|
-
userId:
|
|
3770
|
-
convoId:
|
|
3771
|
-
dispatchSpan: parentTool ?
|
|
3772
|
-
turnSpans: [
|
|
4597
|
+
eventId: state2.eventId,
|
|
4598
|
+
userId: state2.identity.userId,
|
|
4599
|
+
convoId: state2.identity.convoId,
|
|
4600
|
+
dispatchSpan: parentTool ? state2.toolSpans.get(parentTool.toolCallId) : void 0,
|
|
4601
|
+
turnSpans: [state2.rootSpan, state2.stepSpan].filter(
|
|
3773
4602
|
(span) => span !== void 0
|
|
3774
4603
|
),
|
|
3775
|
-
recordInputs:
|
|
4604
|
+
recordInputs: state2.recordInputs
|
|
3776
4605
|
};
|
|
3777
4606
|
}
|
|
3778
4607
|
/** Spans still open for an event, so a late outcome can still be stated. */
|
|
3779
4608
|
openSpansForEvent(eventId) {
|
|
3780
4609
|
const spans = [];
|
|
3781
|
-
for (const
|
|
3782
|
-
if (
|
|
3783
|
-
if (
|
|
3784
|
-
if (
|
|
4610
|
+
for (const state2 of this.callStates.values()) {
|
|
4611
|
+
if (state2.eventId !== eventId) continue;
|
|
4612
|
+
if (state2.rootSpan) spans.push(state2.rootSpan);
|
|
4613
|
+
if (state2.stepSpan) spans.push(state2.stepSpan);
|
|
3785
4614
|
}
|
|
3786
4615
|
return spans;
|
|
3787
4616
|
}
|
|
@@ -3801,10 +4630,10 @@ var RaindropTelemetryIntegration = class {
|
|
|
3801
4630
|
* created from an LLM span with output, `ai.response.text` here would state
|
|
3802
4631
|
* the run's outcome through the span while the turn is still working.
|
|
3803
4632
|
*/
|
|
3804
|
-
abortOutcomeAttrs(
|
|
3805
|
-
if (!
|
|
4633
|
+
abortOutcomeAttrs(state2, reason, finishReason) {
|
|
4634
|
+
if (!state2.handoff || state2.nestedInEvent) return [];
|
|
3806
4635
|
return [
|
|
3807
|
-
attrString("ai.response.text", capText2(
|
|
4636
|
+
attrString("ai.response.text", capText2(state2.accumulatedText || reason)),
|
|
3808
4637
|
attrString("ai.response.finishReason", finishReason)
|
|
3809
4638
|
];
|
|
3810
4639
|
}
|
|
@@ -3818,19 +4647,19 @@ var RaindropTelemetryIntegration = class {
|
|
|
3818
4647
|
spanParentRef(span) {
|
|
3819
4648
|
return { traceIdB64: span.ids.traceIdB64, spanIdB64: span.ids.spanIdB64 };
|
|
3820
4649
|
}
|
|
3821
|
-
emitLive(
|
|
4650
|
+
emitLive(state2, type, content, extra) {
|
|
3822
4651
|
var _a, _b, _c, _d, _e, _f;
|
|
3823
|
-
if (!localDebuggerEnabled() || !
|
|
3824
|
-
const callMeta = this.extractRaindropMetadata(
|
|
4652
|
+
if (!localDebuggerEnabled() || !state2.rootSpan) return;
|
|
4653
|
+
const callMeta = this.extractRaindropMetadata(state2.metadata);
|
|
3825
4654
|
sendLocalDebuggerLiveEvent({
|
|
3826
|
-
traceId:
|
|
4655
|
+
traceId: state2.rootSpan.ids.traceIdB64,
|
|
3827
4656
|
type,
|
|
3828
4657
|
content,
|
|
3829
4658
|
metadata: {
|
|
3830
4659
|
userId: (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId,
|
|
3831
4660
|
convoId: (_d = callMeta.convoId) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.convoId,
|
|
3832
4661
|
eventName: (_f = callMeta.eventName) != null ? _f : (_e = this.defaultContext) == null ? void 0 : _e.eventName,
|
|
3833
|
-
eventId:
|
|
4662
|
+
eventId: state2.eventId,
|
|
3834
4663
|
...extra
|
|
3835
4664
|
}
|
|
3836
4665
|
});
|
|
@@ -3908,29 +4737,29 @@ var RaindropTelemetryIntegration = class {
|
|
|
3908
4737
|
toolCallId: toolCall.toolCallId,
|
|
3909
4738
|
toolName: toolCall.toolName
|
|
3910
4739
|
});
|
|
3911
|
-
const
|
|
3912
|
-
|
|
3913
|
-
if (!(
|
|
3914
|
-
const { operationName, resourceName } = opName("ai.toolCall",
|
|
3915
|
-
const inputAttrs =
|
|
4740
|
+
const state2 = this.getState(event.callId);
|
|
4741
|
+
state2 == null ? void 0 : state2.parentContextToolCallIds.add(toolCall.toolCallId);
|
|
4742
|
+
if (!(state2 == null ? void 0 : state2.stepParent)) return;
|
|
4743
|
+
const { operationName, resourceName } = opName("ai.toolCall", state2.functionId);
|
|
4744
|
+
const inputAttrs = state2.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(toolCall.input))] : [];
|
|
3916
4745
|
const toolSpan = this.traceShipper.startSpan({
|
|
3917
4746
|
name: "ai.toolCall",
|
|
3918
|
-
parent:
|
|
3919
|
-
eventId:
|
|
3920
|
-
...
|
|
4747
|
+
parent: state2.stepParent,
|
|
4748
|
+
eventId: state2.eventId,
|
|
4749
|
+
...state2.identity,
|
|
3921
4750
|
operationId: "ai.toolCall",
|
|
3922
4751
|
attributes: [
|
|
3923
4752
|
attrString("operation.name", operationName),
|
|
3924
4753
|
attrString("resource.name", resourceName),
|
|
3925
|
-
attrString("ai.telemetry.functionId",
|
|
4754
|
+
attrString("ai.telemetry.functionId", state2.functionId),
|
|
3926
4755
|
attrString("ai.toolCall.name", toolCall.toolName),
|
|
3927
4756
|
attrString("ai.toolCall.id", toolCall.toolCallId),
|
|
3928
4757
|
...inputAttrs,
|
|
3929
|
-
...handoffSpanAttrs(
|
|
4758
|
+
...handoffSpanAttrs(state2.handoff)
|
|
3930
4759
|
]
|
|
3931
4760
|
});
|
|
3932
|
-
|
|
3933
|
-
this.emitLive(
|
|
4761
|
+
state2.toolSpans.set(toolCall.toolCallId, toolSpan);
|
|
4762
|
+
this.emitLive(state2, "tool_start", toolCall.toolName, { args: toolCall.input });
|
|
3934
4763
|
}
|
|
3935
4764
|
toolExecutionEnd(event) {
|
|
3936
4765
|
var _a;
|
|
@@ -3944,20 +4773,20 @@ var RaindropTelemetryIntegration = class {
|
|
|
3944
4773
|
clearParentToolContext();
|
|
3945
4774
|
}
|
|
3946
4775
|
}
|
|
3947
|
-
const
|
|
3948
|
-
if (!
|
|
3949
|
-
const toolSpan =
|
|
4776
|
+
const state2 = this.getState(event.callId);
|
|
4777
|
+
if (!state2) return;
|
|
4778
|
+
const toolSpan = state2.toolSpans.get(event.toolCall.toolCallId);
|
|
3950
4779
|
if (!toolSpan) return;
|
|
3951
|
-
|
|
4780
|
+
state2.toolCallCount += 1;
|
|
3952
4781
|
const outcome = "toolOutput" in event ? event.toolOutput.type === "tool-result" ? { success: true, output: event.toolOutput.output } : { success: false, error: event.toolOutput.error } : event.success ? { success: true, output: event.output } : { success: false, error: event.error };
|
|
3953
4782
|
if (outcome.success) {
|
|
3954
|
-
const outputAttrs =
|
|
4783
|
+
const outputAttrs = state2.recordOutputs ? [attrString("ai.toolCall.result", safeJsonWithUint8(outcome.output))] : [];
|
|
3955
4784
|
this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
|
|
3956
4785
|
} else {
|
|
3957
4786
|
this.traceShipper.endSpan(toolSpan, { error: outcome.error });
|
|
3958
4787
|
}
|
|
3959
|
-
this.emitLive(
|
|
3960
|
-
|
|
4788
|
+
this.emitLive(state2, "tool_result", event.toolCall.toolName);
|
|
4789
|
+
state2.toolSpans.delete(event.toolCall.toolCallId);
|
|
3961
4790
|
}
|
|
3962
4791
|
// ── provider-executed tool calls ─────────────────────────────────────────
|
|
3963
4792
|
//
|
|
@@ -3976,8 +4805,8 @@ var RaindropTelemetryIntegration = class {
|
|
|
3976
4805
|
//
|
|
3977
4806
|
// Client-executed tools are excluded (`providerExecuted` falsy) — they were
|
|
3978
4807
|
// already spanned during execution, so this never double-emits.
|
|
3979
|
-
emitProviderExecutedToolSpans(event,
|
|
3980
|
-
if (!
|
|
4808
|
+
emitProviderExecutedToolSpans(event, state2) {
|
|
4809
|
+
if (!state2.stepParent) return;
|
|
3981
4810
|
const content = Array.isArray(event.content) ? event.content : [];
|
|
3982
4811
|
const providerToolCalls = content.filter(
|
|
3983
4812
|
(part) => (part == null ? void 0 : part.type) === "tool-call" && part.providerExecuted === true
|
|
@@ -3990,42 +4819,42 @@ var RaindropTelemetryIntegration = class {
|
|
|
3990
4819
|
}
|
|
3991
4820
|
}
|
|
3992
4821
|
for (const call of providerToolCalls) {
|
|
3993
|
-
const { operationName, resourceName } = opName("ai.toolCall",
|
|
3994
|
-
const inputAttrs =
|
|
4822
|
+
const { operationName, resourceName } = opName("ai.toolCall", state2.functionId);
|
|
4823
|
+
const inputAttrs = state2.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(call.input))] : [];
|
|
3995
4824
|
const toolSpan = this.traceShipper.startSpan({
|
|
3996
4825
|
name: "ai.toolCall",
|
|
3997
|
-
parent:
|
|
3998
|
-
eventId:
|
|
3999
|
-
...
|
|
4826
|
+
parent: state2.stepParent,
|
|
4827
|
+
eventId: state2.eventId,
|
|
4828
|
+
...state2.identity,
|
|
4000
4829
|
operationId: "ai.toolCall",
|
|
4001
4830
|
attributes: [
|
|
4002
4831
|
attrString("operation.name", operationName),
|
|
4003
4832
|
attrString("resource.name", resourceName),
|
|
4004
|
-
attrString("ai.telemetry.functionId",
|
|
4833
|
+
attrString("ai.telemetry.functionId", state2.functionId),
|
|
4005
4834
|
attrString("ai.toolCall.name", call.toolName),
|
|
4006
4835
|
attrString("ai.toolCall.id", call.toolCallId),
|
|
4007
4836
|
attrString("ai.toolCall.providerExecuted", "true"),
|
|
4008
4837
|
...inputAttrs,
|
|
4009
|
-
...handoffSpanAttrs(
|
|
4838
|
+
...handoffSpanAttrs(state2.handoff)
|
|
4010
4839
|
]
|
|
4011
4840
|
});
|
|
4012
|
-
|
|
4013
|
-
this.emitLive(
|
|
4841
|
+
state2.toolCallCount += 1;
|
|
4842
|
+
this.emitLive(state2, "tool_start", call.toolName, { args: call.input });
|
|
4014
4843
|
const resultPart = resultsByCallId.get(call.toolCallId);
|
|
4015
4844
|
if ((resultPart == null ? void 0 : resultPart.type) === "tool-error") {
|
|
4016
4845
|
this.traceShipper.endSpan(toolSpan, { error: resultPart.error });
|
|
4017
4846
|
} else {
|
|
4018
|
-
const outputAttrs =
|
|
4847
|
+
const outputAttrs = state2.recordOutputs && resultPart && "output" in resultPart ? [attrString("ai.toolCall.result", safeJsonWithUint8(resultPart.output))] : [];
|
|
4019
4848
|
this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
|
|
4020
4849
|
}
|
|
4021
|
-
this.emitLive(
|
|
4850
|
+
this.emitLive(state2, "tool_result", call.toolName);
|
|
4022
4851
|
}
|
|
4023
4852
|
}
|
|
4024
|
-
finishGenerate(event,
|
|
4853
|
+
finishGenerate(event, state2) {
|
|
4025
4854
|
var _a, _b, _c, _d, _e, _f;
|
|
4026
|
-
if (
|
|
4855
|
+
if (state2.rootSpan) {
|
|
4027
4856
|
const outputAttrs = [];
|
|
4028
|
-
if (
|
|
4857
|
+
if (state2.recordOutputs) {
|
|
4029
4858
|
outputAttrs.push(
|
|
4030
4859
|
attrString("ai.response.finishReason", event.finishReason),
|
|
4031
4860
|
attrString("ai.response.text", capText2((_a = event.text) != null ? _a : void 0)),
|
|
@@ -4066,12 +4895,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
4066
4895
|
attrInt("ai.usage.cachedInputTokens", usageMetrics.cachedInputTokens)
|
|
4067
4896
|
);
|
|
4068
4897
|
}
|
|
4069
|
-
outputAttrs.push(attrInt("ai.toolCall.count",
|
|
4070
|
-
this.traceShipper.endSpan(
|
|
4898
|
+
outputAttrs.push(attrInt("ai.toolCall.count", state2.toolCallCount));
|
|
4899
|
+
this.traceShipper.endSpan(state2.rootSpan, { attributes: outputAttrs });
|
|
4071
4900
|
}
|
|
4072
4901
|
this.finalizeGenerateEvent(
|
|
4073
|
-
|
|
4074
|
-
(_e = event.text) != null ? _e :
|
|
4902
|
+
state2,
|
|
4903
|
+
(_e = event.text) != null ? _e : state2.accumulatedText || void 0,
|
|
4075
4904
|
(_f = event.response) == null ? void 0 : _f.modelId,
|
|
4076
4905
|
hasUnresolvedToolApproval(event)
|
|
4077
4906
|
);
|
|
@@ -4087,29 +4916,29 @@ var RaindropTelemetryIntegration = class {
|
|
|
4087
4916
|
* is finalized by that resume — otherwise each execution would finalize the
|
|
4088
4917
|
* same event ID into a separate canonical row.
|
|
4089
4918
|
*/
|
|
4090
|
-
finalizeGenerateEvent(
|
|
4919
|
+
finalizeGenerateEvent(state2, output, model, keepPending = false, detachedOutcome) {
|
|
4091
4920
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4092
|
-
const suppressSubagentEvent =
|
|
4921
|
+
const suppressSubagentEvent = state2.subagentName !== void 0 && state2.subagentToolCallSpan !== void 0;
|
|
4093
4922
|
if (!this.sendEvents || suppressSubagentEvent) return;
|
|
4094
|
-
if (this.subagents.wasSettledExplicitly(
|
|
4095
|
-
const callMeta = this.extractRaindropMetadata(
|
|
4923
|
+
if (this.subagents.wasSettledExplicitly(state2.eventId)) return;
|
|
4924
|
+
const callMeta = this.extractRaindropMetadata(state2.metadata);
|
|
4096
4925
|
const userId = (_b = callMeta.userId) != null ? _b : (_a = this.defaultContext) == null ? void 0 : _a.userId;
|
|
4097
4926
|
if (!userId) return;
|
|
4098
|
-
const eventName = (_e = (_d = callMeta.eventName) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.eventName) != null ? _e :
|
|
4927
|
+
const eventName = (_e = (_d = callMeta.eventName) != null ? _d : (_c = this.defaultContext) == null ? void 0 : _c.eventName) != null ? _e : state2.operationId;
|
|
4099
4928
|
const cappedOutput = capText2(output);
|
|
4100
|
-
const reportedOutput =
|
|
4101
|
-
const input = capText2(
|
|
4929
|
+
const reportedOutput = state2.handoff && detachedOutcome && !(cappedOutput == null ? void 0 : cappedOutput.trim()) ? detachedOutcome.fallbackOutput : cappedOutput;
|
|
4930
|
+
const input = capText2(state2.inputText);
|
|
4102
4931
|
const properties = {
|
|
4103
4932
|
...(_f = this.defaultContext) == null ? void 0 : _f.properties,
|
|
4104
4933
|
...callMeta.properties,
|
|
4105
|
-
...
|
|
4934
|
+
...state2.handoff ? detachedOutcome == null ? void 0 : detachedOutcome.properties : void 0
|
|
4106
4935
|
};
|
|
4107
4936
|
const featureFlags = {
|
|
4108
4937
|
...((_g = this.defaultContext) == null ? void 0 : _g.featureFlags) ? normalizeFeatureFlags(this.defaultContext.featureFlags) : {},
|
|
4109
4938
|
...callMeta.featureFlags
|
|
4110
4939
|
};
|
|
4111
4940
|
const convoId = (_i = callMeta.convoId) != null ? _i : (_h = this.defaultContext) == null ? void 0 : _h.convoId;
|
|
4112
|
-
void this.eventShipper.patch(
|
|
4941
|
+
void this.eventShipper.patch(state2.eventId, {
|
|
4113
4942
|
eventName,
|
|
4114
4943
|
userId,
|
|
4115
4944
|
convoId,
|
|
@@ -4127,12 +4956,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
4127
4956
|
}
|
|
4128
4957
|
});
|
|
4129
4958
|
}
|
|
4130
|
-
finishEmbed(event,
|
|
4959
|
+
finishEmbed(event, state2) {
|
|
4131
4960
|
var _a;
|
|
4132
|
-
if (!
|
|
4961
|
+
if (!state2.rootSpan) return;
|
|
4133
4962
|
const outputAttrs = [];
|
|
4134
|
-
const isMany =
|
|
4135
|
-
if (
|
|
4963
|
+
const isMany = state2.operationId === "ai.embedMany";
|
|
4964
|
+
if (state2.recordOutputs) {
|
|
4136
4965
|
if (isMany) {
|
|
4137
4966
|
outputAttrs.push(attrString("ai.embeddings", safeJsonWithUint8(event.embedding)));
|
|
4138
4967
|
} else {
|
|
@@ -4142,7 +4971,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
4142
4971
|
if (((_a = event.usage) == null ? void 0 : _a.tokens) != null) {
|
|
4143
4972
|
outputAttrs.push(attrInt("ai.usage.tokens", event.usage.tokens));
|
|
4144
4973
|
}
|
|
4145
|
-
this.traceShipper.endSpan(
|
|
4974
|
+
this.traceShipper.endSpan(state2.rootSpan, { attributes: outputAttrs });
|
|
4146
4975
|
}
|
|
4147
4976
|
};
|
|
4148
4977
|
|
|
@@ -6255,14 +7084,14 @@ function mergeAttachments(...groups) {
|
|
|
6255
7084
|
// package.json
|
|
6256
7085
|
var package_default = {
|
|
6257
7086
|
name: "@raindrop-ai/ai-sdk",
|
|
6258
|
-
version: "0.3.
|
|
7087
|
+
version: "0.3.3"};
|
|
6259
7088
|
|
|
6260
7089
|
// src/internal/version.ts
|
|
6261
7090
|
var libraryName = package_default.name;
|
|
6262
7091
|
var libraryVersion = package_default.version;
|
|
6263
7092
|
|
|
6264
7093
|
// src/internal/events.ts
|
|
6265
|
-
var
|
|
7094
|
+
var EventShipper3 = class extends EventShipper2 {
|
|
6266
7095
|
constructor(opts) {
|
|
6267
7096
|
var _a, _b, _c;
|
|
6268
7097
|
super({
|
|
@@ -6275,7 +7104,7 @@ var EventShipper2 = class extends EventShipper {
|
|
|
6275
7104
|
};
|
|
6276
7105
|
|
|
6277
7106
|
// src/internal/traces.ts
|
|
6278
|
-
var
|
|
7107
|
+
var TraceShipper3 = class extends TraceShipper2 {
|
|
6279
7108
|
constructor(opts) {
|
|
6280
7109
|
var _a, _b, _c;
|
|
6281
7110
|
super({
|
|
@@ -6342,11 +7171,11 @@ function userAttrsToOtlp(attrs) {
|
|
|
6342
7171
|
function envDebugEnabled() {
|
|
6343
7172
|
var _a;
|
|
6344
7173
|
if (typeof process === "undefined") return false;
|
|
6345
|
-
const
|
|
6346
|
-
return
|
|
7174
|
+
const flag2 = (_a = process.env) == null ? void 0 : _a.RAINDROP_AI_DEBUG;
|
|
7175
|
+
return flag2 === "1" || flag2 === "true";
|
|
6347
7176
|
}
|
|
6348
7177
|
function createRaindropAISDK(opts) {
|
|
6349
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
7178
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6350
7179
|
const writeKey = opts.writeKey;
|
|
6351
7180
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
6352
7181
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
@@ -6355,37 +7184,53 @@ function createRaindropAISDK(opts) {
|
|
|
6355
7184
|
const localWorkshopInput = opts.localWorkshopUrl === false ? null : opts.localWorkshopUrl;
|
|
6356
7185
|
const resolvedLocalDebuggerUrl = resolveLocalDebuggerBaseUrl(localWorkshopInput);
|
|
6357
7186
|
const localDebuggerUrl = localWorkshopInput === null ? null : resolvedLocalDebuggerUrl != null ? resolvedLocalDebuggerUrl : void 0;
|
|
6358
|
-
const
|
|
6359
|
-
const eventsEnabled = eventsRequested &&
|
|
6360
|
-
const tracesEnabled = tracesRequested &&
|
|
6361
|
-
|
|
7187
|
+
const hasDestination2 = Boolean(writeKey == null ? void 0 : writeKey.trim()) || Boolean(resolvedLocalDebuggerUrl);
|
|
7188
|
+
const eventsEnabled = eventsRequested && hasDestination2;
|
|
7189
|
+
const tracesEnabled = tracesRequested && hasDestination2;
|
|
7190
|
+
const appGitContext = (_c = opts.appGitContext) != null ? _c : createAppGitContext2(
|
|
7191
|
+
eventsEnabled || tracesEnabled ? opts.appGit : false,
|
|
7192
|
+
{ allowLocalGit: true }
|
|
7193
|
+
);
|
|
7194
|
+
if (!hasDestination2 && (eventsRequested || tracesRequested)) {
|
|
6362
7195
|
console.warn(
|
|
6363
7196
|
"[raindrop-ai/ai-sdk] writeKey not provided and no local Workshop reachable; telemetry shipping is disabled"
|
|
6364
7197
|
);
|
|
6365
7198
|
}
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
7199
|
+
let eventShipper;
|
|
7200
|
+
let traceShipper;
|
|
7201
|
+
try {
|
|
7202
|
+
eventShipper = new EventShipper3({
|
|
7203
|
+
writeKey,
|
|
7204
|
+
endpoint: opts.endpoint,
|
|
7205
|
+
enabled: eventsEnabled,
|
|
7206
|
+
debug: ((_d = opts.events) == null ? void 0 : _d.debug) === true || envDebug,
|
|
7207
|
+
partialFlushMs: (_e = opts.events) == null ? void 0 : _e.partialFlushMs,
|
|
7208
|
+
projectId: opts.projectId,
|
|
7209
|
+
localDebuggerUrl,
|
|
7210
|
+
appGitContext
|
|
7211
|
+
});
|
|
7212
|
+
traceShipper = new TraceShipper3({
|
|
7213
|
+
writeKey,
|
|
7214
|
+
endpoint: opts.endpoint,
|
|
7215
|
+
enabled: tracesEnabled,
|
|
7216
|
+
debug: ((_f = opts.traces) == null ? void 0 : _f.debug) === true || envDebug,
|
|
7217
|
+
debugSpans: ((_g = opts.traces) == null ? void 0 : _g.debugSpans) === true || envDebug,
|
|
7218
|
+
flushIntervalMs: (_h = opts.traces) == null ? void 0 : _h.flushIntervalMs,
|
|
7219
|
+
maxBatchSize: (_i = opts.traces) == null ? void 0 : _i.maxBatchSize,
|
|
7220
|
+
maxQueueSize: (_j = opts.traces) == null ? void 0 : _j.maxQueueSize,
|
|
7221
|
+
projectId: opts.projectId,
|
|
7222
|
+
localDebuggerUrl,
|
|
7223
|
+
transformSpan: (_k = opts.traces) == null ? void 0 : _k.transformSpan,
|
|
7224
|
+
disableDefaultRedaction: (_l = opts.traces) == null ? void 0 : _l.disableDefaultRedaction,
|
|
7225
|
+
appGitContext
|
|
7226
|
+
});
|
|
7227
|
+
} catch (error) {
|
|
7228
|
+
try {
|
|
7229
|
+
appGitContext.dispose();
|
|
7230
|
+
} catch (e) {
|
|
7231
|
+
}
|
|
7232
|
+
throw error;
|
|
7233
|
+
}
|
|
6389
7234
|
const settledEventIds = /* @__PURE__ */ new Set();
|
|
6390
7235
|
const subagentApi = new SubagentApi({
|
|
6391
7236
|
traceShipper,
|
|
@@ -6553,7 +7398,14 @@ function createRaindropAISDK(opts) {
|
|
|
6553
7398
|
await Promise.all([eventShipper.flush(), traceShipper.flush()]);
|
|
6554
7399
|
},
|
|
6555
7400
|
async shutdown() {
|
|
6556
|
-
|
|
7401
|
+
try {
|
|
7402
|
+
await Promise.all([eventShipper.shutdown(), traceShipper.shutdown()]);
|
|
7403
|
+
} finally {
|
|
7404
|
+
try {
|
|
7405
|
+
appGitContext.dispose();
|
|
7406
|
+
} catch (e) {
|
|
7407
|
+
}
|
|
7408
|
+
}
|
|
6557
7409
|
}
|
|
6558
7410
|
};
|
|
6559
7411
|
}
|