@raindrop-ai/deep-agents 0.1.1 → 0.1.2
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 +28 -0
- package/dist/index.d.mts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +796 -83
- package/dist/index.mjs +796 -83
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -90,7 +90,459 @@ function evalScopeAttributes() {
|
|
|
90
90
|
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// ../core/dist/chunk-
|
|
93
|
+
// ../core/dist/chunk-WJOR6M7H.js
|
|
94
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
95
|
+
function state() {
|
|
96
|
+
const holder = globalThis;
|
|
97
|
+
let current = holder[STATE_KEY];
|
|
98
|
+
if (!current) {
|
|
99
|
+
let storage = null;
|
|
100
|
+
try {
|
|
101
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
102
|
+
if (Ctor) storage = new Ctor();
|
|
103
|
+
} catch (e) {
|
|
104
|
+
storage = null;
|
|
105
|
+
}
|
|
106
|
+
current = {
|
|
107
|
+
storage,
|
|
108
|
+
syncDestination: void 0,
|
|
109
|
+
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
110
|
+
};
|
|
111
|
+
holder[STATE_KEY] = current;
|
|
112
|
+
}
|
|
113
|
+
return current;
|
|
114
|
+
}
|
|
115
|
+
function currentReplayTraceDestination() {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
const routing = state();
|
|
118
|
+
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
119
|
+
}
|
|
120
|
+
function rememberReplayTraceDestination(span) {
|
|
121
|
+
const destination = currentReplayTraceDestination();
|
|
122
|
+
if (destination) state().spanDestinations.set(span, destination);
|
|
123
|
+
}
|
|
124
|
+
function copyReplayTraceDestination(source, target) {
|
|
125
|
+
const destination = state().spanDestinations.get(source);
|
|
126
|
+
if (destination) state().spanDestinations.set(target, destination);
|
|
127
|
+
}
|
|
128
|
+
function replayTraceDestinationFor(value) {
|
|
129
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
return state().spanDestinations.get(value);
|
|
133
|
+
}
|
|
134
|
+
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
if (!destination || !spanId || !traceId) return;
|
|
137
|
+
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
138
|
+
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
139
|
+
}
|
|
140
|
+
function replayTraceUrl(baseUrl) {
|
|
141
|
+
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
142
|
+
}
|
|
143
|
+
function getAsyncLocalStorageCtor() {
|
|
144
|
+
return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
145
|
+
}
|
|
146
|
+
var MAX_BINDING_STACK = 128;
|
|
147
|
+
var EMPTY_STACK = [];
|
|
148
|
+
var ContextStackStorage = class {
|
|
149
|
+
/** Emitted once when this runtime cannot support an ambient push. */
|
|
150
|
+
constructor(noAmbientBindWarning) {
|
|
151
|
+
this.noAmbientBindWarning = noAmbientBindWarning;
|
|
152
|
+
this._als = null;
|
|
153
|
+
this._enterWithUsable = false;
|
|
154
|
+
this._syncStack = EMPTY_STACK;
|
|
155
|
+
this._adoptionChecked = false;
|
|
156
|
+
this._warnedNoAmbientBind = false;
|
|
157
|
+
}
|
|
158
|
+
maybeAdoptAsyncLocalStorage() {
|
|
159
|
+
if (this._adoptionChecked) return;
|
|
160
|
+
this._adoptionChecked = true;
|
|
161
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
162
|
+
if (!Ctor) return;
|
|
163
|
+
const als = new Ctor();
|
|
164
|
+
try {
|
|
165
|
+
als.run(EMPTY_STACK, () => {
|
|
166
|
+
});
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this._als = als;
|
|
171
|
+
if (typeof als.enterWith === "function") {
|
|
172
|
+
try {
|
|
173
|
+
als.enterWith(EMPTY_STACK);
|
|
174
|
+
this._enterWithUsable = true;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
this._enterWithUsable = false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
getStack() {
|
|
181
|
+
var _a;
|
|
182
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
183
|
+
if (this._als) return (_a = this._als.getStore()) != null ? _a : this._syncStack;
|
|
184
|
+
return this._syncStack;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Persist an ambient stack mutation. Returns false when an ALS is adopted but
|
|
188
|
+
* `enterWith` is unusable (workerd): callers must NOT fall back to the
|
|
189
|
+
* process-shared sync stack, since concurrent isolates would cross-stamp.
|
|
190
|
+
*/
|
|
191
|
+
setAmbientStack(stack) {
|
|
192
|
+
if (this._als) {
|
|
193
|
+
if (!this._enterWithUsable) return false;
|
|
194
|
+
this._als.enterWith(stack);
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
this._syncStack = stack;
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
push(binding) {
|
|
201
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
202
|
+
if (this._als && !this._enterWithUsable) {
|
|
203
|
+
this.warnNoAmbientBindOnce();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
let stack = this.getStack();
|
|
207
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
208
|
+
stack = stack.filter((b) => b.isLive());
|
|
209
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
210
|
+
stack = stack.slice(stack.length - (MAX_BINDING_STACK - 1));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this.setAmbientStack([...stack, binding]);
|
|
214
|
+
}
|
|
215
|
+
remove(binding) {
|
|
216
|
+
binding.markDead();
|
|
217
|
+
const stack = this.getStack();
|
|
218
|
+
const pruned = stack.filter((b) => b !== binding && b.isLive());
|
|
219
|
+
if (pruned.length !== stack.length) {
|
|
220
|
+
this.setAmbientStack(pruned);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
runWith(binding, callback) {
|
|
224
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
225
|
+
if (this._als) {
|
|
226
|
+
return this._als.run([...this.getStack(), binding], callback);
|
|
227
|
+
}
|
|
228
|
+
const previous = this._syncStack;
|
|
229
|
+
this._syncStack = [...previous, binding];
|
|
230
|
+
try {
|
|
231
|
+
return callback();
|
|
232
|
+
} finally {
|
|
233
|
+
this._syncStack = previous;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
current() {
|
|
237
|
+
const stack = this.getStack();
|
|
238
|
+
if (stack.length === 0) return void 0;
|
|
239
|
+
const top = stack[stack.length - 1];
|
|
240
|
+
if (top.isLive()) return top;
|
|
241
|
+
const pruned = stack.filter((b) => b.isLive());
|
|
242
|
+
this.setAmbientStack(pruned);
|
|
243
|
+
return pruned.length > 0 ? pruned[pruned.length - 1] : void 0;
|
|
244
|
+
}
|
|
245
|
+
warnNoAmbientBindOnce() {
|
|
246
|
+
if (this._warnedNoAmbientBind) return;
|
|
247
|
+
this._warnedNoAmbientBind = true;
|
|
248
|
+
console.warn(this.noAmbientBindWarning);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
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.";
|
|
252
|
+
var ROUTING_STORAGE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.routingContextStorage");
|
|
253
|
+
function routingStorage() {
|
|
254
|
+
const holder = globalThis;
|
|
255
|
+
let storage = holder[ROUTING_STORAGE_KEY];
|
|
256
|
+
if (!storage) {
|
|
257
|
+
storage = new ContextStackStorage(NO_AMBIENT_ROUTING_BIND_WARNING);
|
|
258
|
+
holder[ROUTING_STORAGE_KEY] = storage;
|
|
259
|
+
}
|
|
260
|
+
return storage;
|
|
261
|
+
}
|
|
262
|
+
function currentRoutingBinding() {
|
|
263
|
+
const bound = routingStorage().current();
|
|
264
|
+
if (!bound) return void 0;
|
|
265
|
+
return {
|
|
266
|
+
projectId: bound.projectId,
|
|
267
|
+
authHint: bound.authHint,
|
|
268
|
+
...bound.appGit ? { appGit: bound.appGit } : {},
|
|
269
|
+
...bound.appGitSource ? { appGitSource: bound.appGitSource } : {}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
var APP_COMMIT_SHA = "raindrop.app.commit_sha";
|
|
273
|
+
var APP_COMMIT_DIRTY = "raindrop.app.commit_dirty";
|
|
274
|
+
var APP_BRANCH = "raindrop.app.branch";
|
|
275
|
+
var APP_GIT_KEYS = [APP_COMMIT_SHA, APP_COMMIT_DIRTY, APP_BRANCH];
|
|
276
|
+
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
277
|
+
function appGitExplicitKeys(properties) {
|
|
278
|
+
const keys = /* @__PURE__ */ new Set();
|
|
279
|
+
if (!properties) return keys;
|
|
280
|
+
for (const key of APP_GIT_KEYS) {
|
|
281
|
+
if (own(properties, key)) keys.add(key);
|
|
282
|
+
}
|
|
283
|
+
return keys;
|
|
284
|
+
}
|
|
285
|
+
function mergeAppGitSnapshot(base, properties, explicitKeys = /* @__PURE__ */ new Set()) {
|
|
286
|
+
try {
|
|
287
|
+
const result = { ...base };
|
|
288
|
+
if (properties && own(properties, APP_COMMIT_SHA) && properties[APP_COMMIT_SHA] !== result[APP_COMMIT_SHA]) {
|
|
289
|
+
if (!explicitKeys.has(APP_COMMIT_DIRTY) && !own(properties, APP_COMMIT_DIRTY)) {
|
|
290
|
+
delete result[APP_COMMIT_DIRTY];
|
|
291
|
+
}
|
|
292
|
+
if (!explicitKeys.has(APP_BRANCH) && !own(properties, APP_BRANCH)) {
|
|
293
|
+
delete result[APP_BRANCH];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
for (const key of APP_GIT_KEYS) {
|
|
297
|
+
if (properties && own(properties, key)) result[key] = properties[key];
|
|
298
|
+
}
|
|
299
|
+
return Object.freeze(result);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
return Object.freeze({});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function validAppCommitSha(value) {
|
|
305
|
+
if (typeof value !== "string" || value.length > 128) return void 0;
|
|
306
|
+
const cleaned = value.trim();
|
|
307
|
+
return /^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(cleaned) ? cleaned.toLowerCase() : void 0;
|
|
308
|
+
}
|
|
309
|
+
function shortString(value) {
|
|
310
|
+
if (typeof value !== "string" || value.length > 1024) return void 0;
|
|
311
|
+
const cleaned = value.trim();
|
|
312
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
313
|
+
}
|
|
314
|
+
function flag(value) {
|
|
315
|
+
if (value === true || value === "true" || value === "1") return true;
|
|
316
|
+
if (value === false || value === "false" || value === "0") return false;
|
|
317
|
+
return void 0;
|
|
318
|
+
}
|
|
319
|
+
function environment() {
|
|
320
|
+
try {
|
|
321
|
+
return typeof process === "undefined" ? {} : process.env;
|
|
322
|
+
} catch (e) {
|
|
323
|
+
return {};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
var DEPLOYMENTS = [
|
|
327
|
+
["VERCEL", "VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF"],
|
|
328
|
+
["NETLIFY", "COMMIT_REF", "BRANCH"],
|
|
329
|
+
["RAILWAY_ENVIRONMENT_NAME", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
330
|
+
["RAILWAY_ENVIRONMENT", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
331
|
+
["RENDER", "RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH"],
|
|
332
|
+
["DYNO", "HEROKU_BUILD_COMMIT", ""],
|
|
333
|
+
["DYNO", "HEROKU_SLUG_COMMIT", ""],
|
|
334
|
+
["AWS_APP_ID", "AWS_COMMIT_ID", "AWS_BRANCH"],
|
|
335
|
+
["WORKERS_CI", "WORKERS_CI_COMMIT_SHA", "WORKERS_CI_BRANCH"]
|
|
336
|
+
];
|
|
337
|
+
var CI_SOURCES = [
|
|
338
|
+
["GITHUB_ACTIONS", "GITHUB_SHA", "GITHUB_REF_NAME"],
|
|
339
|
+
["GITLAB_CI", "CI_COMMIT_SHA", "CI_COMMIT_REF_NAME"],
|
|
340
|
+
["CIRCLECI", "CIRCLE_SHA1", "CIRCLE_BRANCH"]
|
|
341
|
+
];
|
|
342
|
+
function detectedSource(env, table, detectBranch) {
|
|
343
|
+
for (const row of table) {
|
|
344
|
+
const [marker, shaKey, branchKey] = row;
|
|
345
|
+
if (!marker || !shaKey || !shortString(env[marker]) || flag(env[marker]) === false) continue;
|
|
346
|
+
const commitSha = validAppCommitSha(env[shaKey]);
|
|
347
|
+
if (commitSha)
|
|
348
|
+
return {
|
|
349
|
+
commitSha,
|
|
350
|
+
...detectBranch && branchKey ? { branch: shortString(env[branchKey]) } : {}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return {};
|
|
354
|
+
}
|
|
355
|
+
var AppGitContextImpl = class {
|
|
356
|
+
constructor(options, runtime = {}) {
|
|
357
|
+
this.defaults = {};
|
|
358
|
+
this.explicit = {};
|
|
359
|
+
this.explicitKeys = /* @__PURE__ */ new Set();
|
|
360
|
+
this.disposed = false;
|
|
361
|
+
this.operations = /* @__PURE__ */ new Map();
|
|
362
|
+
this.operationOverflow = false;
|
|
363
|
+
this.detectBranch = false;
|
|
364
|
+
this.disabled = false;
|
|
365
|
+
var _a, _b, _c, _d, _e, _f;
|
|
366
|
+
try {
|
|
367
|
+
if (options === false) {
|
|
368
|
+
this.disabled = true;
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const opts = options != null ? options : {};
|
|
372
|
+
const env = (_a = runtime.env) != null ? _a : environment();
|
|
373
|
+
const detectBranch = (_c = (_b = flag(opts.detectBranch)) != null ? _b : flag(env.RAINDROP_GIT_DETECT_BRANCH)) != null ? _c : false;
|
|
374
|
+
this.detectBranch = detectBranch;
|
|
375
|
+
const collectBranch = detectBranch || runtime.captureLegacyReplayBranch === true;
|
|
376
|
+
const autoDetect = runtime.allowDiscovery === false ? false : (_e = (_d = flag(opts.autoDetect)) != null ? _d : flag(env.RAINDROP_GIT_AUTO_DETECT)) != null ? _e : true;
|
|
377
|
+
const configuredSha = opts.commitSha;
|
|
378
|
+
const explicitSha = configuredSha === void 0 ? env.RAINDROP_COMMIT_SHA : configuredSha;
|
|
379
|
+
if (explicitSha === null) this.explicit[APP_COMMIT_SHA] = null;
|
|
380
|
+
else if (typeof explicitSha === "string" && validAppCommitSha(explicitSha))
|
|
381
|
+
this.explicit[APP_COMMIT_SHA] = explicitSha;
|
|
382
|
+
const configuredDirty = opts.commitDirty;
|
|
383
|
+
const explicitDirty = configuredDirty === void 0 ? flag(env.RAINDROP_COMMIT_DIRTY) : configuredDirty;
|
|
384
|
+
if (explicitDirty === null || typeof explicitDirty === "boolean")
|
|
385
|
+
this.explicit[APP_COMMIT_DIRTY] = explicitDirty;
|
|
386
|
+
const configuredBranch = opts.branch;
|
|
387
|
+
const explicitBranch = configuredBranch === void 0 ? env.RAINDROP_BRANCH : configuredBranch;
|
|
388
|
+
if (explicitBranch === null) this.explicit[APP_BRANCH] = null;
|
|
389
|
+
else if (typeof explicitBranch === "string" && explicitBranch.length <= 1024)
|
|
390
|
+
this.explicit[APP_BRANCH] = explicitBranch;
|
|
391
|
+
this.explicitKeys = appGitExplicitKeys(this.explicit);
|
|
392
|
+
this.defaults = { ...this.explicit };
|
|
393
|
+
if (!autoDetect || explicitSha !== void 0) return;
|
|
394
|
+
const sourceDirectory = (_f = shortString(opts.sourceDirectory)) != null ? _f : shortString(env.RAINDROP_GIT_SOURCE_DIRECTORY);
|
|
395
|
+
if (runtime.allowLocalGit === false && !sourceDirectory) return;
|
|
396
|
+
const deploy = sourceDirectory ? {} : detectedSource(env, DEPLOYMENTS, collectBranch);
|
|
397
|
+
if (deploy.commitSha) {
|
|
398
|
+
this.accept(deploy);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const fallback = sourceDirectory ? {} : detectedSource(env, CI_SOURCES, collectBranch);
|
|
402
|
+
if (runtime.resolveLocal && (runtime.allowLocalGit !== false || sourceDirectory)) {
|
|
403
|
+
this.cancel = runtime.resolveLocal(sourceDirectory, collectBranch, (result) => {
|
|
404
|
+
try {
|
|
405
|
+
if (!this.disposed) this.accept(result.commitSha ? result : fallback);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
} else this.accept(fallback);
|
|
410
|
+
} catch (e) {
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
accept(result) {
|
|
414
|
+
const sha = validAppCommitSha(result.commitSha);
|
|
415
|
+
if (!sha) return;
|
|
416
|
+
this.replayBranch = shortString(result.branch);
|
|
417
|
+
this.defaults = {
|
|
418
|
+
[APP_COMMIT_SHA]: sha,
|
|
419
|
+
...typeof result.commitDirty === "boolean" ? { [APP_COMMIT_DIRTY]: result.commitDirty } : {},
|
|
420
|
+
...this.detectBranch && this.replayBranch ? { [APP_BRANCH]: this.replayBranch } : {},
|
|
421
|
+
...this.explicit
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
snapshot(properties) {
|
|
425
|
+
var _a;
|
|
426
|
+
try {
|
|
427
|
+
const binding = currentRoutingBinding();
|
|
428
|
+
const base = this.disabled && (binding == null ? void 0 : binding.appGitSource) !== "replay-override" ? {} : (_a = binding == null ? void 0 : binding.appGit) != null ? _a : this.defaults;
|
|
429
|
+
return this.mergeSnapshot(base, properties);
|
|
430
|
+
} catch (e) {
|
|
431
|
+
return Object.freeze({});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/** Safe defaults when no operation/span start was observed; never infer identity. */
|
|
435
|
+
snapshotExplicit(properties, eventId) {
|
|
436
|
+
try {
|
|
437
|
+
const base = { ...this.explicit };
|
|
438
|
+
const operation = eventId ? this.operations.get(eventId) : void 0;
|
|
439
|
+
if (operation) {
|
|
440
|
+
for (const key of operation.explicitKeys) base[key] = operation.snapshot[key];
|
|
441
|
+
}
|
|
442
|
+
return this.mergeSnapshot(base, properties, new Set(Object.keys(base)));
|
|
443
|
+
} catch (e) {
|
|
444
|
+
return mergeAppGitSnapshot({}, properties);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/** Existing replay branch reporting stays separate from opt-in event properties. */
|
|
448
|
+
snapshotForReplay() {
|
|
449
|
+
const snapshot = this.snapshot();
|
|
450
|
+
if (this.replayBranch && !own(snapshot, APP_BRANCH) && snapshot[APP_COMMIT_SHA] === this.defaults[APP_COMMIT_SHA]) {
|
|
451
|
+
return Object.freeze({ ...snapshot, [APP_BRANCH]: this.replayBranch });
|
|
452
|
+
}
|
|
453
|
+
return snapshot;
|
|
454
|
+
}
|
|
455
|
+
/** Merge a frozen span snapshot without losing client-authored provenance. */
|
|
456
|
+
mergeSnapshot(base, properties, explicitKeys = this.explicitKeys) {
|
|
457
|
+
return mergeAppGitSnapshot(base, properties, /* @__PURE__ */ new Set([...this.explicitKeys, ...explicitKeys]));
|
|
458
|
+
}
|
|
459
|
+
/** Shippers belonging to one client share this bounded operation registry. */
|
|
460
|
+
forOperation(eventId, properties, owner) {
|
|
461
|
+
if (!eventId) return this.snapshot(properties);
|
|
462
|
+
let operation = this.operations.get(eventId);
|
|
463
|
+
if (!operation) {
|
|
464
|
+
if (this.operations.size >= 1e4) this.operationOverflow = true;
|
|
465
|
+
if (this.operationOverflow) return this.mergeSnapshot({}, properties);
|
|
466
|
+
operation = {
|
|
467
|
+
snapshot: this.snapshot(properties),
|
|
468
|
+
owners: /* @__PURE__ */ new Set(),
|
|
469
|
+
unowned: owner === void 0,
|
|
470
|
+
explicitKeys: appGitExplicitKeys(properties)
|
|
471
|
+
};
|
|
472
|
+
this.operations.set(eventId, operation);
|
|
473
|
+
} else if (properties && APP_GIT_KEYS.some((key) => own(properties, key))) {
|
|
474
|
+
const explicitKeys = /* @__PURE__ */ new Set([...this.explicitKeys, ...operation.explicitKeys]);
|
|
475
|
+
operation.snapshot = this.mergeSnapshot(operation.snapshot, properties, explicitKeys);
|
|
476
|
+
for (const key of appGitExplicitKeys(properties)) operation.explicitKeys.add(key);
|
|
477
|
+
}
|
|
478
|
+
if (!owner) operation.unowned = true;
|
|
479
|
+
if (owner) operation.owners.add(owner);
|
|
480
|
+
return operation.snapshot;
|
|
481
|
+
}
|
|
482
|
+
releaseOperation(eventId, owner) {
|
|
483
|
+
const operation = this.operations.get(eventId);
|
|
484
|
+
if (!operation) return;
|
|
485
|
+
operation.owners.delete(owner);
|
|
486
|
+
if (operation.owners.size === 0 && !operation.unowned) this.operations.delete(eventId);
|
|
487
|
+
}
|
|
488
|
+
finishOperation(eventId) {
|
|
489
|
+
this.operations.delete(eventId);
|
|
490
|
+
}
|
|
491
|
+
dispose() {
|
|
492
|
+
var _a;
|
|
493
|
+
this.disposed = true;
|
|
494
|
+
try {
|
|
495
|
+
(_a = this.cancel) == null ? void 0 : _a.call(this);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
var AppGitContext = AppGitContextImpl;
|
|
501
|
+
function createAppGitContext(options, runtime = {}) {
|
|
502
|
+
return new AppGitContext(options, runtime);
|
|
503
|
+
}
|
|
504
|
+
function withAppGitProperties(properties, snapshot) {
|
|
505
|
+
try {
|
|
506
|
+
const merged = { ...properties };
|
|
507
|
+
for (const key of APP_GIT_KEYS)
|
|
508
|
+
if (!own(merged, key) && own(snapshot, key)) merged[key] = snapshot[key];
|
|
509
|
+
return merged;
|
|
510
|
+
} catch (e) {
|
|
511
|
+
return properties != null ? properties : {};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function withAppGitAttributes(attributes, snapshot) {
|
|
515
|
+
try {
|
|
516
|
+
const present = new Set(attributes.flatMap((attr) => attr ? [attr.key] : []));
|
|
517
|
+
const added = [];
|
|
518
|
+
for (const key of APP_GIT_KEYS) {
|
|
519
|
+
if (present.has(key) || present.has(`ai.telemetry.metadata.${key}`) || present.has(`traceloop.association.properties.${key}`))
|
|
520
|
+
continue;
|
|
521
|
+
const value = snapshot[key];
|
|
522
|
+
if (typeof value === "string") added.push({ key, value: { stringValue: value } });
|
|
523
|
+
else if (typeof value === "boolean") added.push({ key, value: { boolValue: value } });
|
|
524
|
+
}
|
|
525
|
+
return added.length ? [...attributes, ...added] : attributes;
|
|
526
|
+
} catch (e) {
|
|
527
|
+
return attributes;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function appGitPropertiesFromAttributes(attributes) {
|
|
531
|
+
var _a, _b, _c;
|
|
532
|
+
const properties = {};
|
|
533
|
+
try {
|
|
534
|
+
for (const attr of attributes) {
|
|
535
|
+
if (!attr) continue;
|
|
536
|
+
for (const key of APP_GIT_KEYS) {
|
|
537
|
+
if (attr.key === key || attr.key === `ai.telemetry.metadata.${key}` || attr.key === `traceloop.association.properties.${key}`) {
|
|
538
|
+
properties[key] = (_c = (_b = (_a = attr.value.stringValue) != null ? _a : attr.value.boolValue) != null ? _b : attr.value.intValue) != null ? _c : null;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
} catch (e) {
|
|
543
|
+
}
|
|
544
|
+
return properties;
|
|
545
|
+
}
|
|
94
546
|
function getCrypto() {
|
|
95
547
|
const c = globalThis.crypto;
|
|
96
548
|
return c;
|
|
@@ -195,7 +647,7 @@ function runWithTracingSuppressed(fn) {
|
|
|
195
647
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
196
648
|
var MAX_RETRY_DELAY_MS = 3e4;
|
|
197
649
|
function wait(ms) {
|
|
198
|
-
return new Promise((
|
|
650
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
199
651
|
}
|
|
200
652
|
function formatEndpoint(endpoint) {
|
|
201
653
|
if (!endpoint) return void 0;
|
|
@@ -232,9 +684,9 @@ async function raceWithTimeout(promise, timeoutMs) {
|
|
|
232
684
|
() => true,
|
|
233
685
|
() => true
|
|
234
686
|
),
|
|
235
|
-
new Promise((
|
|
687
|
+
new Promise((resolve2) => {
|
|
236
688
|
var _a;
|
|
237
|
-
timer = setTimeout(() =>
|
|
689
|
+
timer = setTimeout(() => resolve2(false), Math.max(0, timeoutMs));
|
|
238
690
|
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
239
691
|
})
|
|
240
692
|
]);
|
|
@@ -407,55 +859,6 @@ function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", se
|
|
|
407
859
|
]
|
|
408
860
|
};
|
|
409
861
|
}
|
|
410
|
-
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
411
|
-
function state() {
|
|
412
|
-
const holder = globalThis;
|
|
413
|
-
let current = holder[STATE_KEY];
|
|
414
|
-
if (!current) {
|
|
415
|
-
let storage = null;
|
|
416
|
-
try {
|
|
417
|
-
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
418
|
-
if (Ctor) storage = new Ctor();
|
|
419
|
-
} catch (e) {
|
|
420
|
-
storage = null;
|
|
421
|
-
}
|
|
422
|
-
current = {
|
|
423
|
-
storage,
|
|
424
|
-
syncDestination: void 0,
|
|
425
|
-
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
426
|
-
};
|
|
427
|
-
holder[STATE_KEY] = current;
|
|
428
|
-
}
|
|
429
|
-
return current;
|
|
430
|
-
}
|
|
431
|
-
function currentReplayTraceDestination() {
|
|
432
|
-
var _a, _b;
|
|
433
|
-
const routing = state();
|
|
434
|
-
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
435
|
-
}
|
|
436
|
-
function rememberReplayTraceDestination(span) {
|
|
437
|
-
const destination = currentReplayTraceDestination();
|
|
438
|
-
if (destination) state().spanDestinations.set(span, destination);
|
|
439
|
-
}
|
|
440
|
-
function copyReplayTraceDestination(source, target) {
|
|
441
|
-
const destination = state().spanDestinations.get(source);
|
|
442
|
-
if (destination) state().spanDestinations.set(target, destination);
|
|
443
|
-
}
|
|
444
|
-
function replayTraceDestinationFor(value) {
|
|
445
|
-
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
446
|
-
return void 0;
|
|
447
|
-
}
|
|
448
|
-
return state().spanDestinations.get(value);
|
|
449
|
-
}
|
|
450
|
-
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
451
|
-
var _a, _b;
|
|
452
|
-
if (!destination || !spanId || !traceId) return;
|
|
453
|
-
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
454
|
-
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
455
|
-
}
|
|
456
|
-
function replayTraceUrl(baseUrl) {
|
|
457
|
-
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
458
|
-
}
|
|
459
862
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
460
863
|
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
461
864
|
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
@@ -565,6 +968,13 @@ function projectIdHeaders(projectId) {
|
|
|
565
968
|
}
|
|
566
969
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
567
970
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
971
|
+
function appGitOwnerId(prefix) {
|
|
972
|
+
try {
|
|
973
|
+
return `${prefix}:${randomUUID()}`;
|
|
974
|
+
} catch (e) {
|
|
975
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
568
978
|
function mergePatches(target, source) {
|
|
569
979
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
570
980
|
const out = { ...target, ...source };
|
|
@@ -614,22 +1024,25 @@ function eventTelemetryProperties(patch) {
|
|
|
614
1024
|
}
|
|
615
1025
|
var EventShipper = class {
|
|
616
1026
|
constructor(opts) {
|
|
1027
|
+
this.appGitOwner = appGitOwnerId("event");
|
|
617
1028
|
this.buffers = /* @__PURE__ */ new Map();
|
|
618
1029
|
this.sticky = /* @__PURE__ */ new Map();
|
|
619
1030
|
this.timers = /* @__PURE__ */ new Map();
|
|
620
1031
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
621
1032
|
this.hasShutdown = false;
|
|
622
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
623
|
-
this.
|
|
624
|
-
this.
|
|
1033
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1034
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1035
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1036
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1037
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
625
1038
|
this.enabled = opts.enabled !== false;
|
|
626
1039
|
this.debug = opts.debug;
|
|
627
|
-
this.partialFlushMs = (
|
|
628
|
-
this.sdkName = (
|
|
1040
|
+
this.partialFlushMs = (_d = opts.partialFlushMs) != null ? _d : 1e3;
|
|
1041
|
+
this.sdkName = (_e = opts.sdkName) != null ? _e : "core";
|
|
629
1042
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
630
|
-
this.defaultEventName = (
|
|
1043
|
+
this.defaultEventName = (_f = opts.defaultEventName) != null ? _f : "ai_generation";
|
|
631
1044
|
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
632
|
-
this.localDebuggerUrl = (
|
|
1045
|
+
this.localDebuggerUrl = (_g = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _g : void 0;
|
|
633
1046
|
if (this.debug && this.localDebuggerUrl) {
|
|
634
1047
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
635
1048
|
}
|
|
@@ -640,8 +1053,8 @@ var EventShipper = class {
|
|
|
640
1053
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
641
1054
|
this.context = {
|
|
642
1055
|
library: {
|
|
643
|
-
name: (
|
|
644
|
-
version: (
|
|
1056
|
+
name: (_h = opts.libraryName) != null ? _h : "@raindrop-ai/core",
|
|
1057
|
+
version: (_i = opts.libraryVersion) != null ? _i : "0.0.0"
|
|
645
1058
|
},
|
|
646
1059
|
metadata: {
|
|
647
1060
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -649,6 +1062,9 @@ var EventShipper = class {
|
|
|
649
1062
|
}
|
|
650
1063
|
};
|
|
651
1064
|
}
|
|
1065
|
+
ownAppGitContextForShutdown() {
|
|
1066
|
+
this.ownsAppGitContext = true;
|
|
1067
|
+
}
|
|
652
1068
|
isDebugEnabled() {
|
|
653
1069
|
return this.debug;
|
|
654
1070
|
}
|
|
@@ -727,6 +1143,13 @@ var EventShipper = class {
|
|
|
727
1143
|
}
|
|
728
1144
|
const sticky = (_c = this.sticky.get(eventId)) != null ? _c : {};
|
|
729
1145
|
const existing = (_d = this.buffers.get(eventId)) != null ? _d : {};
|
|
1146
|
+
patch = {
|
|
1147
|
+
...patch,
|
|
1148
|
+
properties: withAppGitProperties(
|
|
1149
|
+
patch.properties,
|
|
1150
|
+
this.appGitContext.forOperation(eventId, patch.properties, this.appGitOwner)
|
|
1151
|
+
)
|
|
1152
|
+
};
|
|
730
1153
|
const merged = mergePatches(existing, patch);
|
|
731
1154
|
merged.isPending = (_g = (_f = (_e = patch.isPending) != null ? _e : existing.isPending) != null ? _f : sticky.isPending) != null ? _g : true;
|
|
732
1155
|
this.buffers.set(eventId, merged);
|
|
@@ -740,6 +1163,8 @@ var EventShipper = class {
|
|
|
740
1163
|
if (t) clearTimeout(t);
|
|
741
1164
|
if (merged.isPending === false) {
|
|
742
1165
|
await this.flushOne(eventId);
|
|
1166
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1167
|
+
else this.appGitContext.finishOperation(eventId);
|
|
743
1168
|
return;
|
|
744
1169
|
}
|
|
745
1170
|
const timeout = setTimeout(() => {
|
|
@@ -771,6 +1196,7 @@ var EventShipper = class {
|
|
|
771
1196
|
if (!settled) this.warnShutdownDrop("in-flight request(s) at shutdown");
|
|
772
1197
|
} finally {
|
|
773
1198
|
this.shutdownDeadlineAt = void 0;
|
|
1199
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
774
1200
|
}
|
|
775
1201
|
}
|
|
776
1202
|
async trackSignal(signal) {
|
|
@@ -1198,6 +1624,13 @@ function redactJsonAttributeValue(key, value) {
|
|
|
1198
1624
|
if (scrubbedJson === json) return void 0;
|
|
1199
1625
|
return { stringValue: scrubbedJson };
|
|
1200
1626
|
}
|
|
1627
|
+
function appGitOwnerId2(prefix) {
|
|
1628
|
+
try {
|
|
1629
|
+
return `${prefix}:${randomUUID()}`;
|
|
1630
|
+
} catch (e) {
|
|
1631
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1201
1634
|
function identityAttrs(args) {
|
|
1202
1635
|
return [
|
|
1203
1636
|
attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
|
|
@@ -1220,23 +1653,30 @@ function applyOtelSpanAttributeLimit(limit) {
|
|
|
1220
1653
|
}
|
|
1221
1654
|
var TraceShipper = class {
|
|
1222
1655
|
constructor(opts) {
|
|
1656
|
+
this.appGitOwner = appGitOwnerId2("trace");
|
|
1657
|
+
this.appGitEventIds = /* @__PURE__ */ new WeakMap();
|
|
1658
|
+
this.appGitActiveSpans = /* @__PURE__ */ new Map();
|
|
1659
|
+
this.appGitCaptured = /* @__PURE__ */ new WeakSet();
|
|
1660
|
+
this.appGitAdded = /* @__PURE__ */ new WeakMap();
|
|
1223
1661
|
this.queue = [];
|
|
1224
1662
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
1225
1663
|
this.hasShutdown = false;
|
|
1226
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1227
|
-
this.
|
|
1228
|
-
this.
|
|
1664
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1665
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1666
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1667
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1668
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
1229
1669
|
this.enabled = opts.enabled !== false;
|
|
1230
1670
|
this.debug = opts.debug;
|
|
1231
1671
|
this.debugSpans = opts.debugSpans === true;
|
|
1232
|
-
this.flushIntervalMs = (
|
|
1233
|
-
this.maxBatchSize = (
|
|
1234
|
-
this.maxQueueSize = (
|
|
1235
|
-
this.sdkName = (
|
|
1672
|
+
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
1673
|
+
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
1674
|
+
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
1675
|
+
this.sdkName = (_g = opts.sdkName) != null ? _g : "core";
|
|
1236
1676
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
1237
|
-
this.serviceName = (
|
|
1238
|
-
this.serviceVersion = (
|
|
1239
|
-
this.localDebuggerUrl = (
|
|
1677
|
+
this.serviceName = (_h = opts.serviceName) != null ? _h : "raindrop.core";
|
|
1678
|
+
this.serviceVersion = (_i = opts.serviceVersion) != null ? _i : "0.0.0";
|
|
1679
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _j : void 0;
|
|
1240
1680
|
if (this.debug && this.localDebuggerUrl) {
|
|
1241
1681
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
1242
1682
|
}
|
|
@@ -1337,7 +1777,7 @@ var TraceShipper = class {
|
|
|
1337
1777
|
return { ...this.authHeaders(), ...projectIdHeaders(this.projectId) };
|
|
1338
1778
|
}
|
|
1339
1779
|
startSpan(args) {
|
|
1340
|
-
var _a, _b;
|
|
1780
|
+
var _a, _b, _c;
|
|
1341
1781
|
const ids = createSpanIds(args.parent);
|
|
1342
1782
|
const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1343
1783
|
const attrs = [
|
|
@@ -1347,13 +1787,24 @@ var TraceShipper = class {
|
|
|
1347
1787
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1348
1788
|
];
|
|
1349
1789
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
1790
|
+
const tracksAppGit = this.appGitActiveSpans.has(args.eventId) || this.appGitActiveSpans.size < 1e4;
|
|
1791
|
+
const appGitOverrides = appGitPropertiesFromAttributes(attrs);
|
|
1350
1792
|
const span = {
|
|
1351
1793
|
ids,
|
|
1352
1794
|
name: args.name,
|
|
1353
1795
|
startTimeUnixNano: started,
|
|
1354
|
-
attributes:
|
|
1796
|
+
attributes: withAppGitAttributes(
|
|
1797
|
+
attrs,
|
|
1798
|
+
this.appGitContext.forOperation(args.eventId, appGitOverrides, this.appGitOwner)
|
|
1799
|
+
)
|
|
1355
1800
|
};
|
|
1356
1801
|
rememberReplayTraceDestination(span);
|
|
1802
|
+
this.appGitCaptured.add(span);
|
|
1803
|
+
this.appGitEventIds.set(span, args.eventId);
|
|
1804
|
+
if (tracksAppGit) {
|
|
1805
|
+
this.appGitActiveSpans.set(args.eventId, ((_c = this.appGitActiveSpans.get(args.eventId)) != null ? _c : 0) + 1);
|
|
1806
|
+
}
|
|
1807
|
+
this.appGitAdded.set(span, new Set(span.attributes.filter((attr) => !attrs.includes(attr))));
|
|
1357
1808
|
const openSpan = buildOtlpSpan({
|
|
1358
1809
|
ids: span.ids,
|
|
1359
1810
|
name: span.name,
|
|
@@ -1393,11 +1844,17 @@ var TraceShipper = class {
|
|
|
1393
1844
|
});
|
|
1394
1845
|
}
|
|
1395
1846
|
endSpan(span, extra) {
|
|
1396
|
-
var _a, _b;
|
|
1847
|
+
var _a, _b, _c;
|
|
1397
1848
|
if (span.endTimeUnixNano) return;
|
|
1398
1849
|
span.endTimeUnixNano = (_a = extra == null ? void 0 : extra.endTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1399
1850
|
if ((_b = extra == null ? void 0 : extra.attributes) == null ? void 0 : _b.length) {
|
|
1851
|
+
const overrides = appGitPropertiesFromAttributes(extra.attributes);
|
|
1852
|
+
const eventId2 = this.appGitEventIds.get(span);
|
|
1853
|
+
const snapshot = eventId2 ? this.appGitContext.forOperation(eventId2, overrides, this.appGitOwner) : overrides;
|
|
1854
|
+
const added = this.appGitAdded.get(span);
|
|
1855
|
+
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));
|
|
1400
1856
|
span.attributes.push(...extra.attributes);
|
|
1857
|
+
span.attributes = withAppGitAttributes(span.attributes, snapshot);
|
|
1401
1858
|
}
|
|
1402
1859
|
let status = extra == null ? void 0 : extra.status;
|
|
1403
1860
|
if (!status && (extra == null ? void 0 : extra.error) !== void 0) {
|
|
@@ -1413,8 +1870,19 @@ var TraceShipper = class {
|
|
|
1413
1870
|
status
|
|
1414
1871
|
});
|
|
1415
1872
|
copyReplayTraceDestination(span, otlp);
|
|
1873
|
+
this.appGitCaptured.add(otlp);
|
|
1416
1874
|
this.enqueue(otlp);
|
|
1417
1875
|
this.mirrorToLocalDebugger(otlp, true);
|
|
1876
|
+
const eventId = this.appGitEventIds.get(span);
|
|
1877
|
+
if (eventId && this.appGitActiveSpans.has(eventId)) {
|
|
1878
|
+
const remaining = ((_c = this.appGitActiveSpans.get(eventId)) != null ? _c : 1) - 1;
|
|
1879
|
+
if (remaining > 0) this.appGitActiveSpans.set(eventId, remaining);
|
|
1880
|
+
else {
|
|
1881
|
+
this.appGitActiveSpans.delete(eventId);
|
|
1882
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1883
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(eventId);
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1418
1886
|
}
|
|
1419
1887
|
createSpan(args) {
|
|
1420
1888
|
var _a;
|
|
@@ -1425,20 +1893,41 @@ var TraceShipper = class {
|
|
|
1425
1893
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1426
1894
|
];
|
|
1427
1895
|
if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
|
|
1896
|
+
const tracksAppGit = !this.appGitActiveSpans.has(args.eventId);
|
|
1428
1897
|
const otlp = buildOtlpSpan({
|
|
1429
1898
|
ids,
|
|
1430
1899
|
name: args.name,
|
|
1431
1900
|
startTimeUnixNano: args.startTimeUnixNano,
|
|
1432
1901
|
endTimeUnixNano: args.endTimeUnixNano,
|
|
1433
|
-
attributes:
|
|
1902
|
+
attributes: withAppGitAttributes(
|
|
1903
|
+
attrs,
|
|
1904
|
+
this.appGitContext.forOperation(
|
|
1905
|
+
args.eventId,
|
|
1906
|
+
appGitPropertiesFromAttributes(attrs),
|
|
1907
|
+
this.appGitOwner
|
|
1908
|
+
)
|
|
1909
|
+
),
|
|
1434
1910
|
status: args.status
|
|
1435
1911
|
});
|
|
1436
1912
|
rememberReplayTraceDestination(otlp);
|
|
1913
|
+
this.appGitCaptured.add(otlp);
|
|
1914
|
+
if (tracksAppGit) {
|
|
1915
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(args.eventId, this.appGitOwner);
|
|
1916
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(args.eventId);
|
|
1917
|
+
}
|
|
1437
1918
|
this.enqueue(otlp);
|
|
1438
1919
|
this.mirrorToLocalDebugger(otlp, true);
|
|
1439
1920
|
}
|
|
1440
1921
|
enqueue(span) {
|
|
1922
|
+
var _a;
|
|
1441
1923
|
if (!this.enabled) return;
|
|
1924
|
+
const attributes = (_a = span.attributes) != null ? _a : [];
|
|
1925
|
+
const enriched = this.appGitCaptured.has(span) ? attributes : withAppGitAttributes(attributes, this.appGitContext.snapshot(appGitPropertiesFromAttributes(attributes)));
|
|
1926
|
+
if (enriched !== attributes) {
|
|
1927
|
+
const original = span;
|
|
1928
|
+
span = { ...span, attributes: enriched.filter((attr) => attr !== void 0) };
|
|
1929
|
+
copyReplayTraceDestination(original, span);
|
|
1930
|
+
}
|
|
1442
1931
|
if (this.debugSpans) {
|
|
1443
1932
|
const short = (s) => s ? s.slice(-8) : "none";
|
|
1444
1933
|
console.log(
|
|
@@ -1584,12 +2073,158 @@ var TraceShipper = class {
|
|
|
1584
2073
|
}
|
|
1585
2074
|
} finally {
|
|
1586
2075
|
this.shutdownDeadlineAt = void 0;
|
|
2076
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1587
2077
|
}
|
|
1588
2078
|
}
|
|
1589
2079
|
};
|
|
1590
2080
|
|
|
1591
2081
|
// ../core/dist/index.node.js
|
|
1592
2082
|
var import_async_hooks = require("async_hooks");
|
|
2083
|
+
var import_child_process = require("child_process");
|
|
2084
|
+
var import_path = require("path");
|
|
2085
|
+
var resolveLocal = (sourceDirectory, detectBranch, completed) => {
|
|
2086
|
+
const cwd = sourceDirectory ? (0, import_path.resolve)(sourceDirectory) : process.cwd();
|
|
2087
|
+
let cancelled = false;
|
|
2088
|
+
let active;
|
|
2089
|
+
let deadlineTimer;
|
|
2090
|
+
const deadline = Date.now() + 1e3;
|
|
2091
|
+
const run = (args, done) => {
|
|
2092
|
+
if (cancelled) return;
|
|
2093
|
+
const remaining = deadline - Date.now();
|
|
2094
|
+
if (remaining <= 0) {
|
|
2095
|
+
done(void 0);
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
try {
|
|
2099
|
+
active = (0, import_child_process.execFile)(
|
|
2100
|
+
"git",
|
|
2101
|
+
args,
|
|
2102
|
+
{
|
|
2103
|
+
cwd,
|
|
2104
|
+
encoding: "utf8",
|
|
2105
|
+
maxBuffer: 4096,
|
|
2106
|
+
windowsHide: true,
|
|
2107
|
+
env: {
|
|
2108
|
+
...process.env,
|
|
2109
|
+
// The selected application cwd, not the invoking shell's Git plumbing, owns identity.
|
|
2110
|
+
GIT_DIR: void 0,
|
|
2111
|
+
GIT_WORK_TREE: void 0,
|
|
2112
|
+
GIT_COMMON_DIR: void 0,
|
|
2113
|
+
GIT_NAMESPACE: void 0,
|
|
2114
|
+
GIT_INDEX_FILE: void 0,
|
|
2115
|
+
GIT_OBJECT_DIRECTORY: void 0,
|
|
2116
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: void 0,
|
|
2117
|
+
GIT_CONFIG_PARAMETERS: void 0,
|
|
2118
|
+
GIT_CONFIG_COUNT: "0",
|
|
2119
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
2120
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
2121
|
+
}
|
|
2122
|
+
},
|
|
2123
|
+
(error, stdout) => {
|
|
2124
|
+
clearTimeout(deadlineTimer);
|
|
2125
|
+
deadlineTimer = void 0;
|
|
2126
|
+
active = void 0;
|
|
2127
|
+
if (!cancelled) {
|
|
2128
|
+
try {
|
|
2129
|
+
done(error ? void 0 : stdout.trim());
|
|
2130
|
+
} catch (e) {
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
);
|
|
2135
|
+
active.unref();
|
|
2136
|
+
if (active.stdout && "unref" in active.stdout && typeof active.stdout.unref === "function")
|
|
2137
|
+
active.stdout.unref();
|
|
2138
|
+
if (active.stderr && "unref" in active.stderr && typeof active.stderr.unref === "function")
|
|
2139
|
+
active.stderr.unref();
|
|
2140
|
+
deadlineTimer = setTimeout(() => {
|
|
2141
|
+
try {
|
|
2142
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2143
|
+
} catch (e) {
|
|
2144
|
+
}
|
|
2145
|
+
}, remaining);
|
|
2146
|
+
deadlineTimer.unref();
|
|
2147
|
+
} catch (e) {
|
|
2148
|
+
try {
|
|
2149
|
+
done(void 0);
|
|
2150
|
+
} catch (e2) {
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
const scheduled = setTimeout(() => {
|
|
2155
|
+
try {
|
|
2156
|
+
run(["rev-parse", "HEAD"], (rawSha) => {
|
|
2157
|
+
const commitSha = validAppCommitSha(rawSha);
|
|
2158
|
+
if (!commitSha) {
|
|
2159
|
+
completed({});
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
run(["-c", "core.fsmonitor=false", "status", "--porcelain"], (status) => {
|
|
2163
|
+
const finish = (branch) => {
|
|
2164
|
+
run(["rev-parse", "HEAD"], (finalSha) => {
|
|
2165
|
+
const coherent = validAppCommitSha(finalSha) === commitSha;
|
|
2166
|
+
completed({
|
|
2167
|
+
commitSha,
|
|
2168
|
+
...coherent && status !== void 0 ? { commitDirty: status !== "" } : {},
|
|
2169
|
+
...coherent && branch && branch !== "HEAD" ? { branch } : {}
|
|
2170
|
+
});
|
|
2171
|
+
});
|
|
2172
|
+
};
|
|
2173
|
+
if (detectBranch) run(["symbolic-ref", "--quiet", "--short", "HEAD"], finish);
|
|
2174
|
+
else finish();
|
|
2175
|
+
});
|
|
2176
|
+
});
|
|
2177
|
+
} catch (e) {
|
|
2178
|
+
completed({});
|
|
2179
|
+
}
|
|
2180
|
+
}, 0);
|
|
2181
|
+
scheduled.unref();
|
|
2182
|
+
return () => {
|
|
2183
|
+
cancelled = true;
|
|
2184
|
+
clearTimeout(scheduled);
|
|
2185
|
+
clearTimeout(deadlineTimer);
|
|
2186
|
+
try {
|
|
2187
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2188
|
+
} catch (e) {
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
};
|
|
2192
|
+
function createAppGitContext2(options, runtime = {}) {
|
|
2193
|
+
return new AppGitContext(options, { ...runtime, resolveLocal });
|
|
2194
|
+
}
|
|
2195
|
+
function hasDestination(options) {
|
|
2196
|
+
var _a;
|
|
2197
|
+
if (options.enabled === false) return false;
|
|
2198
|
+
return Boolean(((_a = options.writeKey) == null ? void 0 : _a.trim()) || resolveLocalDebuggerBaseUrl(options.localDebuggerUrl));
|
|
2199
|
+
}
|
|
2200
|
+
var EventShipper2 = class extends EventShipper {
|
|
2201
|
+
constructor(options) {
|
|
2202
|
+
var _a;
|
|
2203
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2204
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2205
|
+
try {
|
|
2206
|
+
super({ ...options, appGitContext });
|
|
2207
|
+
} catch (error) {
|
|
2208
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2209
|
+
throw error;
|
|
2210
|
+
}
|
|
2211
|
+
if (ownsAppGitContext) this.ownAppGitContextForShutdown();
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
2215
|
+
constructor(options) {
|
|
2216
|
+
var _a;
|
|
2217
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2218
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2219
|
+
try {
|
|
2220
|
+
super({ ...options, appGitContext });
|
|
2221
|
+
} catch (error) {
|
|
2222
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2223
|
+
throw error;
|
|
2224
|
+
}
|
|
2225
|
+
this.ownsAppGitContext = ownsAppGitContext;
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
1593
2228
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = import_async_hooks.AsyncLocalStorage;
|
|
1594
2229
|
var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
|
|
1595
2230
|
"OpenTelemetry SDK Context Key SUPPRESS_TRACING"
|
|
@@ -2138,9 +2773,77 @@ function asNumber(val) {
|
|
|
2138
2773
|
return Number.isFinite(n) ? n : void 0;
|
|
2139
2774
|
}
|
|
2140
2775
|
|
|
2776
|
+
// package.json
|
|
2777
|
+
var package_default = {
|
|
2778
|
+
name: "@raindrop-ai/deep-agents",
|
|
2779
|
+
version: "0.1.2",
|
|
2780
|
+
description: "Raindrop integration for LangChain Deep Agents",
|
|
2781
|
+
main: "dist/index.js",
|
|
2782
|
+
module: "dist/index.mjs",
|
|
2783
|
+
types: "dist/index.d.ts",
|
|
2784
|
+
license: "MIT",
|
|
2785
|
+
homepage: "https://www.raindrop.ai/docs/integrations/deepagents/",
|
|
2786
|
+
bugs: {
|
|
2787
|
+
url: "https://www.raindrop.ai/docs/support/"
|
|
2788
|
+
},
|
|
2789
|
+
exports: {
|
|
2790
|
+
".": {
|
|
2791
|
+
types: "./dist/index.d.ts",
|
|
2792
|
+
import: "./dist/index.mjs",
|
|
2793
|
+
require: "./dist/index.js"
|
|
2794
|
+
}
|
|
2795
|
+
},
|
|
2796
|
+
sideEffects: false,
|
|
2797
|
+
files: [
|
|
2798
|
+
"dist/**"
|
|
2799
|
+
],
|
|
2800
|
+
scripts: {
|
|
2801
|
+
build: "tsup",
|
|
2802
|
+
dev: "tsup --watch",
|
|
2803
|
+
clean: "rm -rf dist",
|
|
2804
|
+
test: "vitest run"
|
|
2805
|
+
},
|
|
2806
|
+
peerDependencies: {
|
|
2807
|
+
"@langchain/core": ">=0.3.0",
|
|
2808
|
+
deepagents: ">=0.5.0"
|
|
2809
|
+
},
|
|
2810
|
+
devDependencies: {
|
|
2811
|
+
"@langchain/anthropic": "~0.3.34",
|
|
2812
|
+
"@langchain/core": ">=0.3.0",
|
|
2813
|
+
"@langchain/openai": "~0.3.17",
|
|
2814
|
+
"@raindrop-ai/core": "workspace:*",
|
|
2815
|
+
"@types/node": "^20.11.17",
|
|
2816
|
+
deepagents: "1.0.0",
|
|
2817
|
+
msw: "^2.12.7",
|
|
2818
|
+
tsup: "^8.4.0",
|
|
2819
|
+
typescript: "^5.3.3",
|
|
2820
|
+
vitest: "^2.1.9",
|
|
2821
|
+
zod: "^3.23.0"
|
|
2822
|
+
},
|
|
2823
|
+
tsup: {
|
|
2824
|
+
entry: [
|
|
2825
|
+
"src/index.ts"
|
|
2826
|
+
],
|
|
2827
|
+
format: [
|
|
2828
|
+
"cjs",
|
|
2829
|
+
"esm"
|
|
2830
|
+
],
|
|
2831
|
+
dts: {
|
|
2832
|
+
resolve: true
|
|
2833
|
+
},
|
|
2834
|
+
clean: true,
|
|
2835
|
+
noExternal: [
|
|
2836
|
+
"@raindrop-ai/core"
|
|
2837
|
+
]
|
|
2838
|
+
},
|
|
2839
|
+
publishConfig: {
|
|
2840
|
+
access: "public"
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
|
|
2141
2844
|
// src/version.ts
|
|
2142
|
-
var libraryName =
|
|
2143
|
-
var libraryVersion =
|
|
2845
|
+
var libraryName = package_default.name;
|
|
2846
|
+
var libraryVersion = package_default.version;
|
|
2144
2847
|
|
|
2145
2848
|
// src/index.ts
|
|
2146
2849
|
function createRaindropDeepAgents(opts) {
|
|
@@ -2151,7 +2854,8 @@ function createRaindropDeepAgents(opts) {
|
|
|
2151
2854
|
"[raindrop-ai/deep-agents] writeKey not provided; telemetry shipping is disabled"
|
|
2152
2855
|
);
|
|
2153
2856
|
}
|
|
2154
|
-
const
|
|
2857
|
+
const appGitContext = createAppGitContext2(writeKey?.trim() ? opts.appGit : false, { allowLocalGit: true });
|
|
2858
|
+
const eventShipper = new EventShipper2({
|
|
2155
2859
|
writeKey,
|
|
2156
2860
|
endpoint: opts.endpoint,
|
|
2157
2861
|
enabled,
|
|
@@ -2159,9 +2863,10 @@ function createRaindropDeepAgents(opts) {
|
|
|
2159
2863
|
projectId: opts.projectId,
|
|
2160
2864
|
sdkName: "deep-agents",
|
|
2161
2865
|
libraryName,
|
|
2162
|
-
libraryVersion
|
|
2866
|
+
libraryVersion,
|
|
2867
|
+
appGitContext
|
|
2163
2868
|
});
|
|
2164
|
-
const traceShipper = new
|
|
2869
|
+
const traceShipper = new TraceShipper2({
|
|
2165
2870
|
writeKey,
|
|
2166
2871
|
endpoint: opts.endpoint,
|
|
2167
2872
|
enabled,
|
|
@@ -2169,7 +2874,8 @@ function createRaindropDeepAgents(opts) {
|
|
|
2169
2874
|
projectId: opts.projectId,
|
|
2170
2875
|
sdkName: "deep-agents",
|
|
2171
2876
|
serviceName: "raindrop.deep-agents",
|
|
2172
|
-
serviceVersion: libraryVersion
|
|
2877
|
+
serviceVersion: libraryVersion,
|
|
2878
|
+
appGitContext
|
|
2173
2879
|
});
|
|
2174
2880
|
const handler = new RaindropDeepAgentsHandler({
|
|
2175
2881
|
eventShipper,
|
|
@@ -2189,7 +2895,14 @@ function createRaindropDeepAgents(opts) {
|
|
|
2189
2895
|
await Promise.all([eventShipper.flush(), traceShipper.flush()]);
|
|
2190
2896
|
},
|
|
2191
2897
|
async shutdown() {
|
|
2192
|
-
|
|
2898
|
+
try {
|
|
2899
|
+
await Promise.all([eventShipper.shutdown(), traceShipper.shutdown()]);
|
|
2900
|
+
} finally {
|
|
2901
|
+
try {
|
|
2902
|
+
appGitContext.dispose();
|
|
2903
|
+
} catch {
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2193
2906
|
},
|
|
2194
2907
|
events: {
|
|
2195
2908
|
async patch(eventId, patch) {
|