@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.mjs
CHANGED
|
@@ -63,7 +63,459 @@ function evalScopeAttributes() {
|
|
|
63
63
|
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// ../core/dist/chunk-
|
|
66
|
+
// ../core/dist/chunk-WJOR6M7H.js
|
|
67
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
68
|
+
function state() {
|
|
69
|
+
const holder = globalThis;
|
|
70
|
+
let current = holder[STATE_KEY];
|
|
71
|
+
if (!current) {
|
|
72
|
+
let storage = null;
|
|
73
|
+
try {
|
|
74
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
75
|
+
if (Ctor) storage = new Ctor();
|
|
76
|
+
} catch (e) {
|
|
77
|
+
storage = null;
|
|
78
|
+
}
|
|
79
|
+
current = {
|
|
80
|
+
storage,
|
|
81
|
+
syncDestination: void 0,
|
|
82
|
+
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
83
|
+
};
|
|
84
|
+
holder[STATE_KEY] = current;
|
|
85
|
+
}
|
|
86
|
+
return current;
|
|
87
|
+
}
|
|
88
|
+
function currentReplayTraceDestination() {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
const routing = state();
|
|
91
|
+
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
92
|
+
}
|
|
93
|
+
function rememberReplayTraceDestination(span) {
|
|
94
|
+
const destination = currentReplayTraceDestination();
|
|
95
|
+
if (destination) state().spanDestinations.set(span, destination);
|
|
96
|
+
}
|
|
97
|
+
function copyReplayTraceDestination(source, target) {
|
|
98
|
+
const destination = state().spanDestinations.get(source);
|
|
99
|
+
if (destination) state().spanDestinations.set(target, destination);
|
|
100
|
+
}
|
|
101
|
+
function replayTraceDestinationFor(value) {
|
|
102
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
return state().spanDestinations.get(value);
|
|
106
|
+
}
|
|
107
|
+
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
if (!destination || !spanId || !traceId) return;
|
|
110
|
+
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
111
|
+
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
112
|
+
}
|
|
113
|
+
function replayTraceUrl(baseUrl) {
|
|
114
|
+
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
115
|
+
}
|
|
116
|
+
function getAsyncLocalStorageCtor() {
|
|
117
|
+
return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
118
|
+
}
|
|
119
|
+
var MAX_BINDING_STACK = 128;
|
|
120
|
+
var EMPTY_STACK = [];
|
|
121
|
+
var ContextStackStorage = class {
|
|
122
|
+
/** Emitted once when this runtime cannot support an ambient push. */
|
|
123
|
+
constructor(noAmbientBindWarning) {
|
|
124
|
+
this.noAmbientBindWarning = noAmbientBindWarning;
|
|
125
|
+
this._als = null;
|
|
126
|
+
this._enterWithUsable = false;
|
|
127
|
+
this._syncStack = EMPTY_STACK;
|
|
128
|
+
this._adoptionChecked = false;
|
|
129
|
+
this._warnedNoAmbientBind = false;
|
|
130
|
+
}
|
|
131
|
+
maybeAdoptAsyncLocalStorage() {
|
|
132
|
+
if (this._adoptionChecked) return;
|
|
133
|
+
this._adoptionChecked = true;
|
|
134
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
135
|
+
if (!Ctor) return;
|
|
136
|
+
const als = new Ctor();
|
|
137
|
+
try {
|
|
138
|
+
als.run(EMPTY_STACK, () => {
|
|
139
|
+
});
|
|
140
|
+
} catch (e) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this._als = als;
|
|
144
|
+
if (typeof als.enterWith === "function") {
|
|
145
|
+
try {
|
|
146
|
+
als.enterWith(EMPTY_STACK);
|
|
147
|
+
this._enterWithUsable = true;
|
|
148
|
+
} catch (e) {
|
|
149
|
+
this._enterWithUsable = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
getStack() {
|
|
154
|
+
var _a;
|
|
155
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
156
|
+
if (this._als) return (_a = this._als.getStore()) != null ? _a : this._syncStack;
|
|
157
|
+
return this._syncStack;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Persist an ambient stack mutation. Returns false when an ALS is adopted but
|
|
161
|
+
* `enterWith` is unusable (workerd): callers must NOT fall back to the
|
|
162
|
+
* process-shared sync stack, since concurrent isolates would cross-stamp.
|
|
163
|
+
*/
|
|
164
|
+
setAmbientStack(stack) {
|
|
165
|
+
if (this._als) {
|
|
166
|
+
if (!this._enterWithUsable) return false;
|
|
167
|
+
this._als.enterWith(stack);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
this._syncStack = stack;
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
push(binding) {
|
|
174
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
175
|
+
if (this._als && !this._enterWithUsable) {
|
|
176
|
+
this.warnNoAmbientBindOnce();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
let stack = this.getStack();
|
|
180
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
181
|
+
stack = stack.filter((b) => b.isLive());
|
|
182
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
183
|
+
stack = stack.slice(stack.length - (MAX_BINDING_STACK - 1));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
this.setAmbientStack([...stack, binding]);
|
|
187
|
+
}
|
|
188
|
+
remove(binding) {
|
|
189
|
+
binding.markDead();
|
|
190
|
+
const stack = this.getStack();
|
|
191
|
+
const pruned = stack.filter((b) => b !== binding && b.isLive());
|
|
192
|
+
if (pruned.length !== stack.length) {
|
|
193
|
+
this.setAmbientStack(pruned);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
runWith(binding, callback) {
|
|
197
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
198
|
+
if (this._als) {
|
|
199
|
+
return this._als.run([...this.getStack(), binding], callback);
|
|
200
|
+
}
|
|
201
|
+
const previous = this._syncStack;
|
|
202
|
+
this._syncStack = [...previous, binding];
|
|
203
|
+
try {
|
|
204
|
+
return callback();
|
|
205
|
+
} finally {
|
|
206
|
+
this._syncStack = previous;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
current() {
|
|
210
|
+
const stack = this.getStack();
|
|
211
|
+
if (stack.length === 0) return void 0;
|
|
212
|
+
const top = stack[stack.length - 1];
|
|
213
|
+
if (top.isLive()) return top;
|
|
214
|
+
const pruned = stack.filter((b) => b.isLive());
|
|
215
|
+
this.setAmbientStack(pruned);
|
|
216
|
+
return pruned.length > 0 ? pruned[pruned.length - 1] : void 0;
|
|
217
|
+
}
|
|
218
|
+
warnNoAmbientBindOnce() {
|
|
219
|
+
if (this._warnedNoAmbientBind) return;
|
|
220
|
+
this._warnedNoAmbientBind = true;
|
|
221
|
+
console.warn(this.noAmbientBindWarning);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
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.";
|
|
225
|
+
var ROUTING_STORAGE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.routingContextStorage");
|
|
226
|
+
function routingStorage() {
|
|
227
|
+
const holder = globalThis;
|
|
228
|
+
let storage = holder[ROUTING_STORAGE_KEY];
|
|
229
|
+
if (!storage) {
|
|
230
|
+
storage = new ContextStackStorage(NO_AMBIENT_ROUTING_BIND_WARNING);
|
|
231
|
+
holder[ROUTING_STORAGE_KEY] = storage;
|
|
232
|
+
}
|
|
233
|
+
return storage;
|
|
234
|
+
}
|
|
235
|
+
function currentRoutingBinding() {
|
|
236
|
+
const bound = routingStorage().current();
|
|
237
|
+
if (!bound) return void 0;
|
|
238
|
+
return {
|
|
239
|
+
projectId: bound.projectId,
|
|
240
|
+
authHint: bound.authHint,
|
|
241
|
+
...bound.appGit ? { appGit: bound.appGit } : {},
|
|
242
|
+
...bound.appGitSource ? { appGitSource: bound.appGitSource } : {}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
var APP_COMMIT_SHA = "raindrop.app.commit_sha";
|
|
246
|
+
var APP_COMMIT_DIRTY = "raindrop.app.commit_dirty";
|
|
247
|
+
var APP_BRANCH = "raindrop.app.branch";
|
|
248
|
+
var APP_GIT_KEYS = [APP_COMMIT_SHA, APP_COMMIT_DIRTY, APP_BRANCH];
|
|
249
|
+
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
250
|
+
function appGitExplicitKeys(properties) {
|
|
251
|
+
const keys = /* @__PURE__ */ new Set();
|
|
252
|
+
if (!properties) return keys;
|
|
253
|
+
for (const key of APP_GIT_KEYS) {
|
|
254
|
+
if (own(properties, key)) keys.add(key);
|
|
255
|
+
}
|
|
256
|
+
return keys;
|
|
257
|
+
}
|
|
258
|
+
function mergeAppGitSnapshot(base, properties, explicitKeys = /* @__PURE__ */ new Set()) {
|
|
259
|
+
try {
|
|
260
|
+
const result = { ...base };
|
|
261
|
+
if (properties && own(properties, APP_COMMIT_SHA) && properties[APP_COMMIT_SHA] !== result[APP_COMMIT_SHA]) {
|
|
262
|
+
if (!explicitKeys.has(APP_COMMIT_DIRTY) && !own(properties, APP_COMMIT_DIRTY)) {
|
|
263
|
+
delete result[APP_COMMIT_DIRTY];
|
|
264
|
+
}
|
|
265
|
+
if (!explicitKeys.has(APP_BRANCH) && !own(properties, APP_BRANCH)) {
|
|
266
|
+
delete result[APP_BRANCH];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
for (const key of APP_GIT_KEYS) {
|
|
270
|
+
if (properties && own(properties, key)) result[key] = properties[key];
|
|
271
|
+
}
|
|
272
|
+
return Object.freeze(result);
|
|
273
|
+
} catch (e) {
|
|
274
|
+
return Object.freeze({});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function validAppCommitSha(value) {
|
|
278
|
+
if (typeof value !== "string" || value.length > 128) return void 0;
|
|
279
|
+
const cleaned = value.trim();
|
|
280
|
+
return /^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(cleaned) ? cleaned.toLowerCase() : void 0;
|
|
281
|
+
}
|
|
282
|
+
function shortString(value) {
|
|
283
|
+
if (typeof value !== "string" || value.length > 1024) return void 0;
|
|
284
|
+
const cleaned = value.trim();
|
|
285
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
286
|
+
}
|
|
287
|
+
function flag(value) {
|
|
288
|
+
if (value === true || value === "true" || value === "1") return true;
|
|
289
|
+
if (value === false || value === "false" || value === "0") return false;
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
function environment() {
|
|
293
|
+
try {
|
|
294
|
+
return typeof process === "undefined" ? {} : process.env;
|
|
295
|
+
} catch (e) {
|
|
296
|
+
return {};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
var DEPLOYMENTS = [
|
|
300
|
+
["VERCEL", "VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF"],
|
|
301
|
+
["NETLIFY", "COMMIT_REF", "BRANCH"],
|
|
302
|
+
["RAILWAY_ENVIRONMENT_NAME", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
303
|
+
["RAILWAY_ENVIRONMENT", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
304
|
+
["RENDER", "RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH"],
|
|
305
|
+
["DYNO", "HEROKU_BUILD_COMMIT", ""],
|
|
306
|
+
["DYNO", "HEROKU_SLUG_COMMIT", ""],
|
|
307
|
+
["AWS_APP_ID", "AWS_COMMIT_ID", "AWS_BRANCH"],
|
|
308
|
+
["WORKERS_CI", "WORKERS_CI_COMMIT_SHA", "WORKERS_CI_BRANCH"]
|
|
309
|
+
];
|
|
310
|
+
var CI_SOURCES = [
|
|
311
|
+
["GITHUB_ACTIONS", "GITHUB_SHA", "GITHUB_REF_NAME"],
|
|
312
|
+
["GITLAB_CI", "CI_COMMIT_SHA", "CI_COMMIT_REF_NAME"],
|
|
313
|
+
["CIRCLECI", "CIRCLE_SHA1", "CIRCLE_BRANCH"]
|
|
314
|
+
];
|
|
315
|
+
function detectedSource(env, table, detectBranch) {
|
|
316
|
+
for (const row of table) {
|
|
317
|
+
const [marker, shaKey, branchKey] = row;
|
|
318
|
+
if (!marker || !shaKey || !shortString(env[marker]) || flag(env[marker]) === false) continue;
|
|
319
|
+
const commitSha = validAppCommitSha(env[shaKey]);
|
|
320
|
+
if (commitSha)
|
|
321
|
+
return {
|
|
322
|
+
commitSha,
|
|
323
|
+
...detectBranch && branchKey ? { branch: shortString(env[branchKey]) } : {}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
return {};
|
|
327
|
+
}
|
|
328
|
+
var AppGitContextImpl = class {
|
|
329
|
+
constructor(options, runtime = {}) {
|
|
330
|
+
this.defaults = {};
|
|
331
|
+
this.explicit = {};
|
|
332
|
+
this.explicitKeys = /* @__PURE__ */ new Set();
|
|
333
|
+
this.disposed = false;
|
|
334
|
+
this.operations = /* @__PURE__ */ new Map();
|
|
335
|
+
this.operationOverflow = false;
|
|
336
|
+
this.detectBranch = false;
|
|
337
|
+
this.disabled = false;
|
|
338
|
+
var _a, _b, _c, _d, _e, _f;
|
|
339
|
+
try {
|
|
340
|
+
if (options === false) {
|
|
341
|
+
this.disabled = true;
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const opts = options != null ? options : {};
|
|
345
|
+
const env = (_a = runtime.env) != null ? _a : environment();
|
|
346
|
+
const detectBranch = (_c = (_b = flag(opts.detectBranch)) != null ? _b : flag(env.RAINDROP_GIT_DETECT_BRANCH)) != null ? _c : false;
|
|
347
|
+
this.detectBranch = detectBranch;
|
|
348
|
+
const collectBranch = detectBranch || runtime.captureLegacyReplayBranch === true;
|
|
349
|
+
const autoDetect = runtime.allowDiscovery === false ? false : (_e = (_d = flag(opts.autoDetect)) != null ? _d : flag(env.RAINDROP_GIT_AUTO_DETECT)) != null ? _e : true;
|
|
350
|
+
const configuredSha = opts.commitSha;
|
|
351
|
+
const explicitSha = configuredSha === void 0 ? env.RAINDROP_COMMIT_SHA : configuredSha;
|
|
352
|
+
if (explicitSha === null) this.explicit[APP_COMMIT_SHA] = null;
|
|
353
|
+
else if (typeof explicitSha === "string" && validAppCommitSha(explicitSha))
|
|
354
|
+
this.explicit[APP_COMMIT_SHA] = explicitSha;
|
|
355
|
+
const configuredDirty = opts.commitDirty;
|
|
356
|
+
const explicitDirty = configuredDirty === void 0 ? flag(env.RAINDROP_COMMIT_DIRTY) : configuredDirty;
|
|
357
|
+
if (explicitDirty === null || typeof explicitDirty === "boolean")
|
|
358
|
+
this.explicit[APP_COMMIT_DIRTY] = explicitDirty;
|
|
359
|
+
const configuredBranch = opts.branch;
|
|
360
|
+
const explicitBranch = configuredBranch === void 0 ? env.RAINDROP_BRANCH : configuredBranch;
|
|
361
|
+
if (explicitBranch === null) this.explicit[APP_BRANCH] = null;
|
|
362
|
+
else if (typeof explicitBranch === "string" && explicitBranch.length <= 1024)
|
|
363
|
+
this.explicit[APP_BRANCH] = explicitBranch;
|
|
364
|
+
this.explicitKeys = appGitExplicitKeys(this.explicit);
|
|
365
|
+
this.defaults = { ...this.explicit };
|
|
366
|
+
if (!autoDetect || explicitSha !== void 0) return;
|
|
367
|
+
const sourceDirectory = (_f = shortString(opts.sourceDirectory)) != null ? _f : shortString(env.RAINDROP_GIT_SOURCE_DIRECTORY);
|
|
368
|
+
if (runtime.allowLocalGit === false && !sourceDirectory) return;
|
|
369
|
+
const deploy = sourceDirectory ? {} : detectedSource(env, DEPLOYMENTS, collectBranch);
|
|
370
|
+
if (deploy.commitSha) {
|
|
371
|
+
this.accept(deploy);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const fallback = sourceDirectory ? {} : detectedSource(env, CI_SOURCES, collectBranch);
|
|
375
|
+
if (runtime.resolveLocal && (runtime.allowLocalGit !== false || sourceDirectory)) {
|
|
376
|
+
this.cancel = runtime.resolveLocal(sourceDirectory, collectBranch, (result) => {
|
|
377
|
+
try {
|
|
378
|
+
if (!this.disposed) this.accept(result.commitSha ? result : fallback);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
} else this.accept(fallback);
|
|
383
|
+
} catch (e) {
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
accept(result) {
|
|
387
|
+
const sha = validAppCommitSha(result.commitSha);
|
|
388
|
+
if (!sha) return;
|
|
389
|
+
this.replayBranch = shortString(result.branch);
|
|
390
|
+
this.defaults = {
|
|
391
|
+
[APP_COMMIT_SHA]: sha,
|
|
392
|
+
...typeof result.commitDirty === "boolean" ? { [APP_COMMIT_DIRTY]: result.commitDirty } : {},
|
|
393
|
+
...this.detectBranch && this.replayBranch ? { [APP_BRANCH]: this.replayBranch } : {},
|
|
394
|
+
...this.explicit
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
snapshot(properties) {
|
|
398
|
+
var _a;
|
|
399
|
+
try {
|
|
400
|
+
const binding = currentRoutingBinding();
|
|
401
|
+
const base = this.disabled && (binding == null ? void 0 : binding.appGitSource) !== "replay-override" ? {} : (_a = binding == null ? void 0 : binding.appGit) != null ? _a : this.defaults;
|
|
402
|
+
return this.mergeSnapshot(base, properties);
|
|
403
|
+
} catch (e) {
|
|
404
|
+
return Object.freeze({});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/** Safe defaults when no operation/span start was observed; never infer identity. */
|
|
408
|
+
snapshotExplicit(properties, eventId) {
|
|
409
|
+
try {
|
|
410
|
+
const base = { ...this.explicit };
|
|
411
|
+
const operation = eventId ? this.operations.get(eventId) : void 0;
|
|
412
|
+
if (operation) {
|
|
413
|
+
for (const key of operation.explicitKeys) base[key] = operation.snapshot[key];
|
|
414
|
+
}
|
|
415
|
+
return this.mergeSnapshot(base, properties, new Set(Object.keys(base)));
|
|
416
|
+
} catch (e) {
|
|
417
|
+
return mergeAppGitSnapshot({}, properties);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/** Existing replay branch reporting stays separate from opt-in event properties. */
|
|
421
|
+
snapshotForReplay() {
|
|
422
|
+
const snapshot = this.snapshot();
|
|
423
|
+
if (this.replayBranch && !own(snapshot, APP_BRANCH) && snapshot[APP_COMMIT_SHA] === this.defaults[APP_COMMIT_SHA]) {
|
|
424
|
+
return Object.freeze({ ...snapshot, [APP_BRANCH]: this.replayBranch });
|
|
425
|
+
}
|
|
426
|
+
return snapshot;
|
|
427
|
+
}
|
|
428
|
+
/** Merge a frozen span snapshot without losing client-authored provenance. */
|
|
429
|
+
mergeSnapshot(base, properties, explicitKeys = this.explicitKeys) {
|
|
430
|
+
return mergeAppGitSnapshot(base, properties, /* @__PURE__ */ new Set([...this.explicitKeys, ...explicitKeys]));
|
|
431
|
+
}
|
|
432
|
+
/** Shippers belonging to one client share this bounded operation registry. */
|
|
433
|
+
forOperation(eventId, properties, owner) {
|
|
434
|
+
if (!eventId) return this.snapshot(properties);
|
|
435
|
+
let operation = this.operations.get(eventId);
|
|
436
|
+
if (!operation) {
|
|
437
|
+
if (this.operations.size >= 1e4) this.operationOverflow = true;
|
|
438
|
+
if (this.operationOverflow) return this.mergeSnapshot({}, properties);
|
|
439
|
+
operation = {
|
|
440
|
+
snapshot: this.snapshot(properties),
|
|
441
|
+
owners: /* @__PURE__ */ new Set(),
|
|
442
|
+
unowned: owner === void 0,
|
|
443
|
+
explicitKeys: appGitExplicitKeys(properties)
|
|
444
|
+
};
|
|
445
|
+
this.operations.set(eventId, operation);
|
|
446
|
+
} else if (properties && APP_GIT_KEYS.some((key) => own(properties, key))) {
|
|
447
|
+
const explicitKeys = /* @__PURE__ */ new Set([...this.explicitKeys, ...operation.explicitKeys]);
|
|
448
|
+
operation.snapshot = this.mergeSnapshot(operation.snapshot, properties, explicitKeys);
|
|
449
|
+
for (const key of appGitExplicitKeys(properties)) operation.explicitKeys.add(key);
|
|
450
|
+
}
|
|
451
|
+
if (!owner) operation.unowned = true;
|
|
452
|
+
if (owner) operation.owners.add(owner);
|
|
453
|
+
return operation.snapshot;
|
|
454
|
+
}
|
|
455
|
+
releaseOperation(eventId, owner) {
|
|
456
|
+
const operation = this.operations.get(eventId);
|
|
457
|
+
if (!operation) return;
|
|
458
|
+
operation.owners.delete(owner);
|
|
459
|
+
if (operation.owners.size === 0 && !operation.unowned) this.operations.delete(eventId);
|
|
460
|
+
}
|
|
461
|
+
finishOperation(eventId) {
|
|
462
|
+
this.operations.delete(eventId);
|
|
463
|
+
}
|
|
464
|
+
dispose() {
|
|
465
|
+
var _a;
|
|
466
|
+
this.disposed = true;
|
|
467
|
+
try {
|
|
468
|
+
(_a = this.cancel) == null ? void 0 : _a.call(this);
|
|
469
|
+
} catch (e) {
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
var AppGitContext = AppGitContextImpl;
|
|
474
|
+
function createAppGitContext(options, runtime = {}) {
|
|
475
|
+
return new AppGitContext(options, runtime);
|
|
476
|
+
}
|
|
477
|
+
function withAppGitProperties(properties, snapshot) {
|
|
478
|
+
try {
|
|
479
|
+
const merged = { ...properties };
|
|
480
|
+
for (const key of APP_GIT_KEYS)
|
|
481
|
+
if (!own(merged, key) && own(snapshot, key)) merged[key] = snapshot[key];
|
|
482
|
+
return merged;
|
|
483
|
+
} catch (e) {
|
|
484
|
+
return properties != null ? properties : {};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
function withAppGitAttributes(attributes, snapshot) {
|
|
488
|
+
try {
|
|
489
|
+
const present = new Set(attributes.flatMap((attr) => attr ? [attr.key] : []));
|
|
490
|
+
const added = [];
|
|
491
|
+
for (const key of APP_GIT_KEYS) {
|
|
492
|
+
if (present.has(key) || present.has(`ai.telemetry.metadata.${key}`) || present.has(`traceloop.association.properties.${key}`))
|
|
493
|
+
continue;
|
|
494
|
+
const value = snapshot[key];
|
|
495
|
+
if (typeof value === "string") added.push({ key, value: { stringValue: value } });
|
|
496
|
+
else if (typeof value === "boolean") added.push({ key, value: { boolValue: value } });
|
|
497
|
+
}
|
|
498
|
+
return added.length ? [...attributes, ...added] : attributes;
|
|
499
|
+
} catch (e) {
|
|
500
|
+
return attributes;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function appGitPropertiesFromAttributes(attributes) {
|
|
504
|
+
var _a, _b, _c;
|
|
505
|
+
const properties = {};
|
|
506
|
+
try {
|
|
507
|
+
for (const attr of attributes) {
|
|
508
|
+
if (!attr) continue;
|
|
509
|
+
for (const key of APP_GIT_KEYS) {
|
|
510
|
+
if (attr.key === key || attr.key === `ai.telemetry.metadata.${key}` || attr.key === `traceloop.association.properties.${key}`) {
|
|
511
|
+
properties[key] = (_c = (_b = (_a = attr.value.stringValue) != null ? _a : attr.value.boolValue) != null ? _b : attr.value.intValue) != null ? _c : null;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
} catch (e) {
|
|
516
|
+
}
|
|
517
|
+
return properties;
|
|
518
|
+
}
|
|
67
519
|
function getCrypto() {
|
|
68
520
|
const c = globalThis.crypto;
|
|
69
521
|
return c;
|
|
@@ -168,7 +620,7 @@ function runWithTracingSuppressed(fn) {
|
|
|
168
620
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
169
621
|
var MAX_RETRY_DELAY_MS = 3e4;
|
|
170
622
|
function wait(ms) {
|
|
171
|
-
return new Promise((
|
|
623
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
172
624
|
}
|
|
173
625
|
function formatEndpoint(endpoint) {
|
|
174
626
|
if (!endpoint) return void 0;
|
|
@@ -205,9 +657,9 @@ async function raceWithTimeout(promise, timeoutMs) {
|
|
|
205
657
|
() => true,
|
|
206
658
|
() => true
|
|
207
659
|
),
|
|
208
|
-
new Promise((
|
|
660
|
+
new Promise((resolve2) => {
|
|
209
661
|
var _a;
|
|
210
|
-
timer = setTimeout(() =>
|
|
662
|
+
timer = setTimeout(() => resolve2(false), Math.max(0, timeoutMs));
|
|
211
663
|
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
212
664
|
})
|
|
213
665
|
]);
|
|
@@ -380,55 +832,6 @@ function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", se
|
|
|
380
832
|
]
|
|
381
833
|
};
|
|
382
834
|
}
|
|
383
|
-
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
384
|
-
function state() {
|
|
385
|
-
const holder = globalThis;
|
|
386
|
-
let current = holder[STATE_KEY];
|
|
387
|
-
if (!current) {
|
|
388
|
-
let storage = null;
|
|
389
|
-
try {
|
|
390
|
-
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
391
|
-
if (Ctor) storage = new Ctor();
|
|
392
|
-
} catch (e) {
|
|
393
|
-
storage = null;
|
|
394
|
-
}
|
|
395
|
-
current = {
|
|
396
|
-
storage,
|
|
397
|
-
syncDestination: void 0,
|
|
398
|
-
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
399
|
-
};
|
|
400
|
-
holder[STATE_KEY] = current;
|
|
401
|
-
}
|
|
402
|
-
return current;
|
|
403
|
-
}
|
|
404
|
-
function currentReplayTraceDestination() {
|
|
405
|
-
var _a, _b;
|
|
406
|
-
const routing = state();
|
|
407
|
-
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
408
|
-
}
|
|
409
|
-
function rememberReplayTraceDestination(span) {
|
|
410
|
-
const destination = currentReplayTraceDestination();
|
|
411
|
-
if (destination) state().spanDestinations.set(span, destination);
|
|
412
|
-
}
|
|
413
|
-
function copyReplayTraceDestination(source, target) {
|
|
414
|
-
const destination = state().spanDestinations.get(source);
|
|
415
|
-
if (destination) state().spanDestinations.set(target, destination);
|
|
416
|
-
}
|
|
417
|
-
function replayTraceDestinationFor(value) {
|
|
418
|
-
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
419
|
-
return void 0;
|
|
420
|
-
}
|
|
421
|
-
return state().spanDestinations.get(value);
|
|
422
|
-
}
|
|
423
|
-
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
424
|
-
var _a, _b;
|
|
425
|
-
if (!destination || !spanId || !traceId) return;
|
|
426
|
-
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
427
|
-
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
428
|
-
}
|
|
429
|
-
function replayTraceUrl(baseUrl) {
|
|
430
|
-
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
431
|
-
}
|
|
432
835
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
433
836
|
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
434
837
|
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
@@ -538,6 +941,13 @@ function projectIdHeaders(projectId) {
|
|
|
538
941
|
}
|
|
539
942
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
540
943
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
944
|
+
function appGitOwnerId(prefix) {
|
|
945
|
+
try {
|
|
946
|
+
return `${prefix}:${randomUUID()}`;
|
|
947
|
+
} catch (e) {
|
|
948
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
541
951
|
function mergePatches(target, source) {
|
|
542
952
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
543
953
|
const out = { ...target, ...source };
|
|
@@ -587,22 +997,25 @@ function eventTelemetryProperties(patch) {
|
|
|
587
997
|
}
|
|
588
998
|
var EventShipper = class {
|
|
589
999
|
constructor(opts) {
|
|
1000
|
+
this.appGitOwner = appGitOwnerId("event");
|
|
590
1001
|
this.buffers = /* @__PURE__ */ new Map();
|
|
591
1002
|
this.sticky = /* @__PURE__ */ new Map();
|
|
592
1003
|
this.timers = /* @__PURE__ */ new Map();
|
|
593
1004
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
594
1005
|
this.hasShutdown = false;
|
|
595
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
596
|
-
this.
|
|
597
|
-
this.
|
|
1006
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1007
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1008
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1009
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1010
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
598
1011
|
this.enabled = opts.enabled !== false;
|
|
599
1012
|
this.debug = opts.debug;
|
|
600
|
-
this.partialFlushMs = (
|
|
601
|
-
this.sdkName = (
|
|
1013
|
+
this.partialFlushMs = (_d = opts.partialFlushMs) != null ? _d : 1e3;
|
|
1014
|
+
this.sdkName = (_e = opts.sdkName) != null ? _e : "core";
|
|
602
1015
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
603
|
-
this.defaultEventName = (
|
|
1016
|
+
this.defaultEventName = (_f = opts.defaultEventName) != null ? _f : "ai_generation";
|
|
604
1017
|
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
605
|
-
this.localDebuggerUrl = (
|
|
1018
|
+
this.localDebuggerUrl = (_g = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _g : void 0;
|
|
606
1019
|
if (this.debug && this.localDebuggerUrl) {
|
|
607
1020
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
608
1021
|
}
|
|
@@ -613,8 +1026,8 @@ var EventShipper = class {
|
|
|
613
1026
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
614
1027
|
this.context = {
|
|
615
1028
|
library: {
|
|
616
|
-
name: (
|
|
617
|
-
version: (
|
|
1029
|
+
name: (_h = opts.libraryName) != null ? _h : "@raindrop-ai/core",
|
|
1030
|
+
version: (_i = opts.libraryVersion) != null ? _i : "0.0.0"
|
|
618
1031
|
},
|
|
619
1032
|
metadata: {
|
|
620
1033
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -622,6 +1035,9 @@ var EventShipper = class {
|
|
|
622
1035
|
}
|
|
623
1036
|
};
|
|
624
1037
|
}
|
|
1038
|
+
ownAppGitContextForShutdown() {
|
|
1039
|
+
this.ownsAppGitContext = true;
|
|
1040
|
+
}
|
|
625
1041
|
isDebugEnabled() {
|
|
626
1042
|
return this.debug;
|
|
627
1043
|
}
|
|
@@ -700,6 +1116,13 @@ var EventShipper = class {
|
|
|
700
1116
|
}
|
|
701
1117
|
const sticky = (_c = this.sticky.get(eventId)) != null ? _c : {};
|
|
702
1118
|
const existing = (_d = this.buffers.get(eventId)) != null ? _d : {};
|
|
1119
|
+
patch = {
|
|
1120
|
+
...patch,
|
|
1121
|
+
properties: withAppGitProperties(
|
|
1122
|
+
patch.properties,
|
|
1123
|
+
this.appGitContext.forOperation(eventId, patch.properties, this.appGitOwner)
|
|
1124
|
+
)
|
|
1125
|
+
};
|
|
703
1126
|
const merged = mergePatches(existing, patch);
|
|
704
1127
|
merged.isPending = (_g = (_f = (_e = patch.isPending) != null ? _e : existing.isPending) != null ? _f : sticky.isPending) != null ? _g : true;
|
|
705
1128
|
this.buffers.set(eventId, merged);
|
|
@@ -713,6 +1136,8 @@ var EventShipper = class {
|
|
|
713
1136
|
if (t) clearTimeout(t);
|
|
714
1137
|
if (merged.isPending === false) {
|
|
715
1138
|
await this.flushOne(eventId);
|
|
1139
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1140
|
+
else this.appGitContext.finishOperation(eventId);
|
|
716
1141
|
return;
|
|
717
1142
|
}
|
|
718
1143
|
const timeout = setTimeout(() => {
|
|
@@ -744,6 +1169,7 @@ var EventShipper = class {
|
|
|
744
1169
|
if (!settled) this.warnShutdownDrop("in-flight request(s) at shutdown");
|
|
745
1170
|
} finally {
|
|
746
1171
|
this.shutdownDeadlineAt = void 0;
|
|
1172
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
747
1173
|
}
|
|
748
1174
|
}
|
|
749
1175
|
async trackSignal(signal) {
|
|
@@ -1171,6 +1597,13 @@ function redactJsonAttributeValue(key, value) {
|
|
|
1171
1597
|
if (scrubbedJson === json) return void 0;
|
|
1172
1598
|
return { stringValue: scrubbedJson };
|
|
1173
1599
|
}
|
|
1600
|
+
function appGitOwnerId2(prefix) {
|
|
1601
|
+
try {
|
|
1602
|
+
return `${prefix}:${randomUUID()}`;
|
|
1603
|
+
} catch (e) {
|
|
1604
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1174
1607
|
function identityAttrs(args) {
|
|
1175
1608
|
return [
|
|
1176
1609
|
attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
|
|
@@ -1193,23 +1626,30 @@ function applyOtelSpanAttributeLimit(limit) {
|
|
|
1193
1626
|
}
|
|
1194
1627
|
var TraceShipper = class {
|
|
1195
1628
|
constructor(opts) {
|
|
1629
|
+
this.appGitOwner = appGitOwnerId2("trace");
|
|
1630
|
+
this.appGitEventIds = /* @__PURE__ */ new WeakMap();
|
|
1631
|
+
this.appGitActiveSpans = /* @__PURE__ */ new Map();
|
|
1632
|
+
this.appGitCaptured = /* @__PURE__ */ new WeakSet();
|
|
1633
|
+
this.appGitAdded = /* @__PURE__ */ new WeakMap();
|
|
1196
1634
|
this.queue = [];
|
|
1197
1635
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
1198
1636
|
this.hasShutdown = false;
|
|
1199
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1200
|
-
this.
|
|
1201
|
-
this.
|
|
1637
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1638
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1639
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1640
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1641
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
1202
1642
|
this.enabled = opts.enabled !== false;
|
|
1203
1643
|
this.debug = opts.debug;
|
|
1204
1644
|
this.debugSpans = opts.debugSpans === true;
|
|
1205
|
-
this.flushIntervalMs = (
|
|
1206
|
-
this.maxBatchSize = (
|
|
1207
|
-
this.maxQueueSize = (
|
|
1208
|
-
this.sdkName = (
|
|
1645
|
+
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
1646
|
+
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
1647
|
+
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
1648
|
+
this.sdkName = (_g = opts.sdkName) != null ? _g : "core";
|
|
1209
1649
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
1210
|
-
this.serviceName = (
|
|
1211
|
-
this.serviceVersion = (
|
|
1212
|
-
this.localDebuggerUrl = (
|
|
1650
|
+
this.serviceName = (_h = opts.serviceName) != null ? _h : "raindrop.core";
|
|
1651
|
+
this.serviceVersion = (_i = opts.serviceVersion) != null ? _i : "0.0.0";
|
|
1652
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _j : void 0;
|
|
1213
1653
|
if (this.debug && this.localDebuggerUrl) {
|
|
1214
1654
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
1215
1655
|
}
|
|
@@ -1310,7 +1750,7 @@ var TraceShipper = class {
|
|
|
1310
1750
|
return { ...this.authHeaders(), ...projectIdHeaders(this.projectId) };
|
|
1311
1751
|
}
|
|
1312
1752
|
startSpan(args) {
|
|
1313
|
-
var _a, _b;
|
|
1753
|
+
var _a, _b, _c;
|
|
1314
1754
|
const ids = createSpanIds(args.parent);
|
|
1315
1755
|
const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1316
1756
|
const attrs = [
|
|
@@ -1320,13 +1760,24 @@ var TraceShipper = class {
|
|
|
1320
1760
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1321
1761
|
];
|
|
1322
1762
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
1763
|
+
const tracksAppGit = this.appGitActiveSpans.has(args.eventId) || this.appGitActiveSpans.size < 1e4;
|
|
1764
|
+
const appGitOverrides = appGitPropertiesFromAttributes(attrs);
|
|
1323
1765
|
const span = {
|
|
1324
1766
|
ids,
|
|
1325
1767
|
name: args.name,
|
|
1326
1768
|
startTimeUnixNano: started,
|
|
1327
|
-
attributes:
|
|
1769
|
+
attributes: withAppGitAttributes(
|
|
1770
|
+
attrs,
|
|
1771
|
+
this.appGitContext.forOperation(args.eventId, appGitOverrides, this.appGitOwner)
|
|
1772
|
+
)
|
|
1328
1773
|
};
|
|
1329
1774
|
rememberReplayTraceDestination(span);
|
|
1775
|
+
this.appGitCaptured.add(span);
|
|
1776
|
+
this.appGitEventIds.set(span, args.eventId);
|
|
1777
|
+
if (tracksAppGit) {
|
|
1778
|
+
this.appGitActiveSpans.set(args.eventId, ((_c = this.appGitActiveSpans.get(args.eventId)) != null ? _c : 0) + 1);
|
|
1779
|
+
}
|
|
1780
|
+
this.appGitAdded.set(span, new Set(span.attributes.filter((attr) => !attrs.includes(attr))));
|
|
1330
1781
|
const openSpan = buildOtlpSpan({
|
|
1331
1782
|
ids: span.ids,
|
|
1332
1783
|
name: span.name,
|
|
@@ -1366,11 +1817,17 @@ var TraceShipper = class {
|
|
|
1366
1817
|
});
|
|
1367
1818
|
}
|
|
1368
1819
|
endSpan(span, extra) {
|
|
1369
|
-
var _a, _b;
|
|
1820
|
+
var _a, _b, _c;
|
|
1370
1821
|
if (span.endTimeUnixNano) return;
|
|
1371
1822
|
span.endTimeUnixNano = (_a = extra == null ? void 0 : extra.endTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1372
1823
|
if ((_b = extra == null ? void 0 : extra.attributes) == null ? void 0 : _b.length) {
|
|
1824
|
+
const overrides = appGitPropertiesFromAttributes(extra.attributes);
|
|
1825
|
+
const eventId2 = this.appGitEventIds.get(span);
|
|
1826
|
+
const snapshot = eventId2 ? this.appGitContext.forOperation(eventId2, overrides, this.appGitOwner) : overrides;
|
|
1827
|
+
const added = this.appGitAdded.get(span);
|
|
1828
|
+
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));
|
|
1373
1829
|
span.attributes.push(...extra.attributes);
|
|
1830
|
+
span.attributes = withAppGitAttributes(span.attributes, snapshot);
|
|
1374
1831
|
}
|
|
1375
1832
|
let status = extra == null ? void 0 : extra.status;
|
|
1376
1833
|
if (!status && (extra == null ? void 0 : extra.error) !== void 0) {
|
|
@@ -1386,8 +1843,19 @@ var TraceShipper = class {
|
|
|
1386
1843
|
status
|
|
1387
1844
|
});
|
|
1388
1845
|
copyReplayTraceDestination(span, otlp);
|
|
1846
|
+
this.appGitCaptured.add(otlp);
|
|
1389
1847
|
this.enqueue(otlp);
|
|
1390
1848
|
this.mirrorToLocalDebugger(otlp, true);
|
|
1849
|
+
const eventId = this.appGitEventIds.get(span);
|
|
1850
|
+
if (eventId && this.appGitActiveSpans.has(eventId)) {
|
|
1851
|
+
const remaining = ((_c = this.appGitActiveSpans.get(eventId)) != null ? _c : 1) - 1;
|
|
1852
|
+
if (remaining > 0) this.appGitActiveSpans.set(eventId, remaining);
|
|
1853
|
+
else {
|
|
1854
|
+
this.appGitActiveSpans.delete(eventId);
|
|
1855
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1856
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(eventId);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1391
1859
|
}
|
|
1392
1860
|
createSpan(args) {
|
|
1393
1861
|
var _a;
|
|
@@ -1398,20 +1866,41 @@ var TraceShipper = class {
|
|
|
1398
1866
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1399
1867
|
];
|
|
1400
1868
|
if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
|
|
1869
|
+
const tracksAppGit = !this.appGitActiveSpans.has(args.eventId);
|
|
1401
1870
|
const otlp = buildOtlpSpan({
|
|
1402
1871
|
ids,
|
|
1403
1872
|
name: args.name,
|
|
1404
1873
|
startTimeUnixNano: args.startTimeUnixNano,
|
|
1405
1874
|
endTimeUnixNano: args.endTimeUnixNano,
|
|
1406
|
-
attributes:
|
|
1875
|
+
attributes: withAppGitAttributes(
|
|
1876
|
+
attrs,
|
|
1877
|
+
this.appGitContext.forOperation(
|
|
1878
|
+
args.eventId,
|
|
1879
|
+
appGitPropertiesFromAttributes(attrs),
|
|
1880
|
+
this.appGitOwner
|
|
1881
|
+
)
|
|
1882
|
+
),
|
|
1407
1883
|
status: args.status
|
|
1408
1884
|
});
|
|
1409
1885
|
rememberReplayTraceDestination(otlp);
|
|
1886
|
+
this.appGitCaptured.add(otlp);
|
|
1887
|
+
if (tracksAppGit) {
|
|
1888
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(args.eventId, this.appGitOwner);
|
|
1889
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(args.eventId);
|
|
1890
|
+
}
|
|
1410
1891
|
this.enqueue(otlp);
|
|
1411
1892
|
this.mirrorToLocalDebugger(otlp, true);
|
|
1412
1893
|
}
|
|
1413
1894
|
enqueue(span) {
|
|
1895
|
+
var _a;
|
|
1414
1896
|
if (!this.enabled) return;
|
|
1897
|
+
const attributes = (_a = span.attributes) != null ? _a : [];
|
|
1898
|
+
const enriched = this.appGitCaptured.has(span) ? attributes : withAppGitAttributes(attributes, this.appGitContext.snapshot(appGitPropertiesFromAttributes(attributes)));
|
|
1899
|
+
if (enriched !== attributes) {
|
|
1900
|
+
const original = span;
|
|
1901
|
+
span = { ...span, attributes: enriched.filter((attr) => attr !== void 0) };
|
|
1902
|
+
copyReplayTraceDestination(original, span);
|
|
1903
|
+
}
|
|
1415
1904
|
if (this.debugSpans) {
|
|
1416
1905
|
const short = (s) => s ? s.slice(-8) : "none";
|
|
1417
1906
|
console.log(
|
|
@@ -1557,12 +2046,158 @@ var TraceShipper = class {
|
|
|
1557
2046
|
}
|
|
1558
2047
|
} finally {
|
|
1559
2048
|
this.shutdownDeadlineAt = void 0;
|
|
2049
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1560
2050
|
}
|
|
1561
2051
|
}
|
|
1562
2052
|
};
|
|
1563
2053
|
|
|
1564
2054
|
// ../core/dist/index.node.js
|
|
1565
2055
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2056
|
+
import { execFile } from "child_process";
|
|
2057
|
+
import { resolve } from "path";
|
|
2058
|
+
var resolveLocal = (sourceDirectory, detectBranch, completed) => {
|
|
2059
|
+
const cwd = sourceDirectory ? resolve(sourceDirectory) : process.cwd();
|
|
2060
|
+
let cancelled = false;
|
|
2061
|
+
let active;
|
|
2062
|
+
let deadlineTimer;
|
|
2063
|
+
const deadline = Date.now() + 1e3;
|
|
2064
|
+
const run = (args, done) => {
|
|
2065
|
+
if (cancelled) return;
|
|
2066
|
+
const remaining = deadline - Date.now();
|
|
2067
|
+
if (remaining <= 0) {
|
|
2068
|
+
done(void 0);
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
try {
|
|
2072
|
+
active = execFile(
|
|
2073
|
+
"git",
|
|
2074
|
+
args,
|
|
2075
|
+
{
|
|
2076
|
+
cwd,
|
|
2077
|
+
encoding: "utf8",
|
|
2078
|
+
maxBuffer: 4096,
|
|
2079
|
+
windowsHide: true,
|
|
2080
|
+
env: {
|
|
2081
|
+
...process.env,
|
|
2082
|
+
// The selected application cwd, not the invoking shell's Git plumbing, owns identity.
|
|
2083
|
+
GIT_DIR: void 0,
|
|
2084
|
+
GIT_WORK_TREE: void 0,
|
|
2085
|
+
GIT_COMMON_DIR: void 0,
|
|
2086
|
+
GIT_NAMESPACE: void 0,
|
|
2087
|
+
GIT_INDEX_FILE: void 0,
|
|
2088
|
+
GIT_OBJECT_DIRECTORY: void 0,
|
|
2089
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: void 0,
|
|
2090
|
+
GIT_CONFIG_PARAMETERS: void 0,
|
|
2091
|
+
GIT_CONFIG_COUNT: "0",
|
|
2092
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
2093
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
2094
|
+
}
|
|
2095
|
+
},
|
|
2096
|
+
(error, stdout) => {
|
|
2097
|
+
clearTimeout(deadlineTimer);
|
|
2098
|
+
deadlineTimer = void 0;
|
|
2099
|
+
active = void 0;
|
|
2100
|
+
if (!cancelled) {
|
|
2101
|
+
try {
|
|
2102
|
+
done(error ? void 0 : stdout.trim());
|
|
2103
|
+
} catch (e) {
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
);
|
|
2108
|
+
active.unref();
|
|
2109
|
+
if (active.stdout && "unref" in active.stdout && typeof active.stdout.unref === "function")
|
|
2110
|
+
active.stdout.unref();
|
|
2111
|
+
if (active.stderr && "unref" in active.stderr && typeof active.stderr.unref === "function")
|
|
2112
|
+
active.stderr.unref();
|
|
2113
|
+
deadlineTimer = setTimeout(() => {
|
|
2114
|
+
try {
|
|
2115
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2116
|
+
} catch (e) {
|
|
2117
|
+
}
|
|
2118
|
+
}, remaining);
|
|
2119
|
+
deadlineTimer.unref();
|
|
2120
|
+
} catch (e) {
|
|
2121
|
+
try {
|
|
2122
|
+
done(void 0);
|
|
2123
|
+
} catch (e2) {
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
const scheduled = setTimeout(() => {
|
|
2128
|
+
try {
|
|
2129
|
+
run(["rev-parse", "HEAD"], (rawSha) => {
|
|
2130
|
+
const commitSha = validAppCommitSha(rawSha);
|
|
2131
|
+
if (!commitSha) {
|
|
2132
|
+
completed({});
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
run(["-c", "core.fsmonitor=false", "status", "--porcelain"], (status) => {
|
|
2136
|
+
const finish = (branch) => {
|
|
2137
|
+
run(["rev-parse", "HEAD"], (finalSha) => {
|
|
2138
|
+
const coherent = validAppCommitSha(finalSha) === commitSha;
|
|
2139
|
+
completed({
|
|
2140
|
+
commitSha,
|
|
2141
|
+
...coherent && status !== void 0 ? { commitDirty: status !== "" } : {},
|
|
2142
|
+
...coherent && branch && branch !== "HEAD" ? { branch } : {}
|
|
2143
|
+
});
|
|
2144
|
+
});
|
|
2145
|
+
};
|
|
2146
|
+
if (detectBranch) run(["symbolic-ref", "--quiet", "--short", "HEAD"], finish);
|
|
2147
|
+
else finish();
|
|
2148
|
+
});
|
|
2149
|
+
});
|
|
2150
|
+
} catch (e) {
|
|
2151
|
+
completed({});
|
|
2152
|
+
}
|
|
2153
|
+
}, 0);
|
|
2154
|
+
scheduled.unref();
|
|
2155
|
+
return () => {
|
|
2156
|
+
cancelled = true;
|
|
2157
|
+
clearTimeout(scheduled);
|
|
2158
|
+
clearTimeout(deadlineTimer);
|
|
2159
|
+
try {
|
|
2160
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2161
|
+
} catch (e) {
|
|
2162
|
+
}
|
|
2163
|
+
};
|
|
2164
|
+
};
|
|
2165
|
+
function createAppGitContext2(options, runtime = {}) {
|
|
2166
|
+
return new AppGitContext(options, { ...runtime, resolveLocal });
|
|
2167
|
+
}
|
|
2168
|
+
function hasDestination(options) {
|
|
2169
|
+
var _a;
|
|
2170
|
+
if (options.enabled === false) return false;
|
|
2171
|
+
return Boolean(((_a = options.writeKey) == null ? void 0 : _a.trim()) || resolveLocalDebuggerBaseUrl(options.localDebuggerUrl));
|
|
2172
|
+
}
|
|
2173
|
+
var EventShipper2 = class extends EventShipper {
|
|
2174
|
+
constructor(options) {
|
|
2175
|
+
var _a;
|
|
2176
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2177
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2178
|
+
try {
|
|
2179
|
+
super({ ...options, appGitContext });
|
|
2180
|
+
} catch (error) {
|
|
2181
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2182
|
+
throw error;
|
|
2183
|
+
}
|
|
2184
|
+
if (ownsAppGitContext) this.ownAppGitContextForShutdown();
|
|
2185
|
+
}
|
|
2186
|
+
};
|
|
2187
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
2188
|
+
constructor(options) {
|
|
2189
|
+
var _a;
|
|
2190
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2191
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2192
|
+
try {
|
|
2193
|
+
super({ ...options, appGitContext });
|
|
2194
|
+
} catch (error) {
|
|
2195
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2196
|
+
throw error;
|
|
2197
|
+
}
|
|
2198
|
+
this.ownsAppGitContext = ownsAppGitContext;
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
1566
2201
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
1567
2202
|
var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
|
|
1568
2203
|
"OpenTelemetry SDK Context Key SUPPRESS_TRACING"
|
|
@@ -2111,9 +2746,77 @@ function asNumber(val) {
|
|
|
2111
2746
|
return Number.isFinite(n) ? n : void 0;
|
|
2112
2747
|
}
|
|
2113
2748
|
|
|
2749
|
+
// package.json
|
|
2750
|
+
var package_default = {
|
|
2751
|
+
name: "@raindrop-ai/deep-agents",
|
|
2752
|
+
version: "0.1.2",
|
|
2753
|
+
description: "Raindrop integration for LangChain Deep Agents",
|
|
2754
|
+
main: "dist/index.js",
|
|
2755
|
+
module: "dist/index.mjs",
|
|
2756
|
+
types: "dist/index.d.ts",
|
|
2757
|
+
license: "MIT",
|
|
2758
|
+
homepage: "https://www.raindrop.ai/docs/integrations/deepagents/",
|
|
2759
|
+
bugs: {
|
|
2760
|
+
url: "https://www.raindrop.ai/docs/support/"
|
|
2761
|
+
},
|
|
2762
|
+
exports: {
|
|
2763
|
+
".": {
|
|
2764
|
+
types: "./dist/index.d.ts",
|
|
2765
|
+
import: "./dist/index.mjs",
|
|
2766
|
+
require: "./dist/index.js"
|
|
2767
|
+
}
|
|
2768
|
+
},
|
|
2769
|
+
sideEffects: false,
|
|
2770
|
+
files: [
|
|
2771
|
+
"dist/**"
|
|
2772
|
+
],
|
|
2773
|
+
scripts: {
|
|
2774
|
+
build: "tsup",
|
|
2775
|
+
dev: "tsup --watch",
|
|
2776
|
+
clean: "rm -rf dist",
|
|
2777
|
+
test: "vitest run"
|
|
2778
|
+
},
|
|
2779
|
+
peerDependencies: {
|
|
2780
|
+
"@langchain/core": ">=0.3.0",
|
|
2781
|
+
deepagents: ">=0.5.0"
|
|
2782
|
+
},
|
|
2783
|
+
devDependencies: {
|
|
2784
|
+
"@langchain/anthropic": "~0.3.34",
|
|
2785
|
+
"@langchain/core": ">=0.3.0",
|
|
2786
|
+
"@langchain/openai": "~0.3.17",
|
|
2787
|
+
"@raindrop-ai/core": "workspace:*",
|
|
2788
|
+
"@types/node": "^20.11.17",
|
|
2789
|
+
deepagents: "1.0.0",
|
|
2790
|
+
msw: "^2.12.7",
|
|
2791
|
+
tsup: "^8.4.0",
|
|
2792
|
+
typescript: "^5.3.3",
|
|
2793
|
+
vitest: "^2.1.9",
|
|
2794
|
+
zod: "^3.23.0"
|
|
2795
|
+
},
|
|
2796
|
+
tsup: {
|
|
2797
|
+
entry: [
|
|
2798
|
+
"src/index.ts"
|
|
2799
|
+
],
|
|
2800
|
+
format: [
|
|
2801
|
+
"cjs",
|
|
2802
|
+
"esm"
|
|
2803
|
+
],
|
|
2804
|
+
dts: {
|
|
2805
|
+
resolve: true
|
|
2806
|
+
},
|
|
2807
|
+
clean: true,
|
|
2808
|
+
noExternal: [
|
|
2809
|
+
"@raindrop-ai/core"
|
|
2810
|
+
]
|
|
2811
|
+
},
|
|
2812
|
+
publishConfig: {
|
|
2813
|
+
access: "public"
|
|
2814
|
+
}
|
|
2815
|
+
};
|
|
2816
|
+
|
|
2114
2817
|
// src/version.ts
|
|
2115
|
-
var libraryName =
|
|
2116
|
-
var libraryVersion =
|
|
2818
|
+
var libraryName = package_default.name;
|
|
2819
|
+
var libraryVersion = package_default.version;
|
|
2117
2820
|
|
|
2118
2821
|
// src/index.ts
|
|
2119
2822
|
function createRaindropDeepAgents(opts) {
|
|
@@ -2124,7 +2827,8 @@ function createRaindropDeepAgents(opts) {
|
|
|
2124
2827
|
"[raindrop-ai/deep-agents] writeKey not provided; telemetry shipping is disabled"
|
|
2125
2828
|
);
|
|
2126
2829
|
}
|
|
2127
|
-
const
|
|
2830
|
+
const appGitContext = createAppGitContext2(writeKey?.trim() ? opts.appGit : false, { allowLocalGit: true });
|
|
2831
|
+
const eventShipper = new EventShipper2({
|
|
2128
2832
|
writeKey,
|
|
2129
2833
|
endpoint: opts.endpoint,
|
|
2130
2834
|
enabled,
|
|
@@ -2132,9 +2836,10 @@ function createRaindropDeepAgents(opts) {
|
|
|
2132
2836
|
projectId: opts.projectId,
|
|
2133
2837
|
sdkName: "deep-agents",
|
|
2134
2838
|
libraryName,
|
|
2135
|
-
libraryVersion
|
|
2839
|
+
libraryVersion,
|
|
2840
|
+
appGitContext
|
|
2136
2841
|
});
|
|
2137
|
-
const traceShipper = new
|
|
2842
|
+
const traceShipper = new TraceShipper2({
|
|
2138
2843
|
writeKey,
|
|
2139
2844
|
endpoint: opts.endpoint,
|
|
2140
2845
|
enabled,
|
|
@@ -2142,7 +2847,8 @@ function createRaindropDeepAgents(opts) {
|
|
|
2142
2847
|
projectId: opts.projectId,
|
|
2143
2848
|
sdkName: "deep-agents",
|
|
2144
2849
|
serviceName: "raindrop.deep-agents",
|
|
2145
|
-
serviceVersion: libraryVersion
|
|
2850
|
+
serviceVersion: libraryVersion,
|
|
2851
|
+
appGitContext
|
|
2146
2852
|
});
|
|
2147
2853
|
const handler = new RaindropDeepAgentsHandler({
|
|
2148
2854
|
eventShipper,
|
|
@@ -2162,7 +2868,14 @@ function createRaindropDeepAgents(opts) {
|
|
|
2162
2868
|
await Promise.all([eventShipper.flush(), traceShipper.flush()]);
|
|
2163
2869
|
},
|
|
2164
2870
|
async shutdown() {
|
|
2165
|
-
|
|
2871
|
+
try {
|
|
2872
|
+
await Promise.all([eventShipper.shutdown(), traceShipper.shutdown()]);
|
|
2873
|
+
} finally {
|
|
2874
|
+
try {
|
|
2875
|
+
appGitContext.dispose();
|
|
2876
|
+
} catch {
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2166
2879
|
},
|
|
2167
2880
|
events: {
|
|
2168
2881
|
async patch(eventId, patch) {
|