@raindrop-ai/ai-sdk 0.3.2 → 0.3.4
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 +48 -0
- package/dist/{chunk-VRVBVX6K.mjs → chunk-BS7SHOEE.mjs} +1219 -381
- package/dist/{index-BqXHiknB.d.mts → index-DCYSGvxI.d.mts} +182 -39
- package/dist/{index-BqXHiknB.d.ts → index-DCYSGvxI.d.ts} +182 -39
- package/dist/index.browser.d.mts +182 -39
- package/dist/index.browser.d.ts +182 -39
- package/dist/index.browser.js +1043 -349
- package/dist/index.browser.mjs +1043 -350
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +1219 -380
- package/dist/index.node.mjs +1 -1
- package/dist/index.workers.d.mts +1 -1
- package/dist/index.workers.d.ts +1 -1
- package/dist/index.workers.js +1219 -380
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -2
package/dist/index.workers.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var async_hooks = require('async_hooks');
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var path = require('path');
|
|
4
6
|
|
|
5
7
|
// src/index.workers.ts
|
|
6
8
|
|
|
@@ -66,7 +68,574 @@ function evalScopeAttributes() {
|
|
|
66
68
|
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
// ../core/dist/chunk-
|
|
71
|
+
// ../core/dist/chunk-I6TVJQEC.js
|
|
72
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
73
|
+
function state() {
|
|
74
|
+
const holder = globalThis;
|
|
75
|
+
let current = holder[STATE_KEY];
|
|
76
|
+
if (!current) {
|
|
77
|
+
let storage = null;
|
|
78
|
+
try {
|
|
79
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
80
|
+
if (Ctor) storage = new Ctor();
|
|
81
|
+
} catch (e) {
|
|
82
|
+
storage = null;
|
|
83
|
+
}
|
|
84
|
+
current = {
|
|
85
|
+
storage,
|
|
86
|
+
syncDestination: void 0,
|
|
87
|
+
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
88
|
+
};
|
|
89
|
+
holder[STATE_KEY] = current;
|
|
90
|
+
}
|
|
91
|
+
return current;
|
|
92
|
+
}
|
|
93
|
+
function currentReplayTraceDestination() {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
const routing = state();
|
|
96
|
+
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
97
|
+
}
|
|
98
|
+
function rememberReplayTraceDestination(span) {
|
|
99
|
+
const destination = currentReplayTraceDestination();
|
|
100
|
+
if (destination) state().spanDestinations.set(span, destination);
|
|
101
|
+
}
|
|
102
|
+
function copyReplayTraceDestination(source, target) {
|
|
103
|
+
const destination = state().spanDestinations.get(source);
|
|
104
|
+
if (destination) state().spanDestinations.set(target, destination);
|
|
105
|
+
}
|
|
106
|
+
function replayTraceDestinationFor(value) {
|
|
107
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
return state().spanDestinations.get(value);
|
|
111
|
+
}
|
|
112
|
+
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
if (!destination || !spanId || !traceId) return;
|
|
115
|
+
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
116
|
+
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
117
|
+
}
|
|
118
|
+
function replayTraceUrl(baseUrl) {
|
|
119
|
+
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
120
|
+
}
|
|
121
|
+
var NOOP_SPAN = {
|
|
122
|
+
traceIdB64: "",
|
|
123
|
+
spanIdB64: "",
|
|
124
|
+
eventId: "",
|
|
125
|
+
log() {
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function getAsyncLocalStorageCtor() {
|
|
129
|
+
return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
130
|
+
}
|
|
131
|
+
var SynchronousContextStorage = class {
|
|
132
|
+
constructor() {
|
|
133
|
+
this._stack = [];
|
|
134
|
+
}
|
|
135
|
+
isEmpty() {
|
|
136
|
+
return this._stack.length === 0;
|
|
137
|
+
}
|
|
138
|
+
getStore() {
|
|
139
|
+
return this._stack[this._stack.length - 1];
|
|
140
|
+
}
|
|
141
|
+
run(store, callback) {
|
|
142
|
+
this._stack.push(store);
|
|
143
|
+
try {
|
|
144
|
+
return callback();
|
|
145
|
+
} finally {
|
|
146
|
+
this._stack.pop();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var ContextManager = class {
|
|
151
|
+
};
|
|
152
|
+
var RaindropContextManager = class extends ContextManager {
|
|
153
|
+
constructor() {
|
|
154
|
+
super();
|
|
155
|
+
this._fallback = null;
|
|
156
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
157
|
+
if (Ctor) {
|
|
158
|
+
this._storage = new Ctor();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this._fallback = new SynchronousContextStorage();
|
|
162
|
+
this._storage = this._fallback;
|
|
163
|
+
}
|
|
164
|
+
maybeAdoptAsyncLocalStorage() {
|
|
165
|
+
if (!this._fallback || !this._fallback.isEmpty()) return;
|
|
166
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
167
|
+
if (!Ctor) return;
|
|
168
|
+
this._storage = new Ctor();
|
|
169
|
+
this._fallback = null;
|
|
170
|
+
}
|
|
171
|
+
isReady() {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
getParentSpanIds() {
|
|
175
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
176
|
+
const span = this._storage.getStore();
|
|
177
|
+
if (!span || span === NOOP_SPAN) return void 0;
|
|
178
|
+
return {
|
|
179
|
+
traceIdB64: span.traceIdB64,
|
|
180
|
+
spanIdB64: span.spanIdB64,
|
|
181
|
+
eventId: span.eventId
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
runInContext(span, callback) {
|
|
185
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
186
|
+
return this._storage.run(span, callback);
|
|
187
|
+
}
|
|
188
|
+
getCurrentSpan() {
|
|
189
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
190
|
+
return this._storage.getStore();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var _contextManager = null;
|
|
194
|
+
function getContextManager() {
|
|
195
|
+
if (!_contextManager) {
|
|
196
|
+
_contextManager = globalThis.RAINDROP_CONTEXT_MANAGER ? new globalThis.RAINDROP_CONTEXT_MANAGER() : new RaindropContextManager();
|
|
197
|
+
}
|
|
198
|
+
return _contextManager;
|
|
199
|
+
}
|
|
200
|
+
function currentSpan() {
|
|
201
|
+
var _a;
|
|
202
|
+
return (_a = getContextManager().getCurrentSpan()) != null ? _a : NOOP_SPAN;
|
|
203
|
+
}
|
|
204
|
+
function withCurrent(span, callback) {
|
|
205
|
+
return getContextManager().runInContext(span, callback);
|
|
206
|
+
}
|
|
207
|
+
async function getCurrentParentSpanContext() {
|
|
208
|
+
var _a, _b;
|
|
209
|
+
return (_b = getContextManager().getParentSpanIds()) != null ? _b : (_a = currentReplayTraceDestination()) == null ? void 0 : _a.parentSpanContext;
|
|
210
|
+
}
|
|
211
|
+
async function runWithParentSpanContext(ctx, fn) {
|
|
212
|
+
const cm = getContextManager();
|
|
213
|
+
const span = {
|
|
214
|
+
traceIdB64: ctx.traceIdB64,
|
|
215
|
+
spanIdB64: ctx.spanIdB64,
|
|
216
|
+
eventId: ctx.eventId
|
|
217
|
+
};
|
|
218
|
+
return cm.runInContext(span, fn);
|
|
219
|
+
}
|
|
220
|
+
async function* asyncGeneratorWithCurrent(span, gen) {
|
|
221
|
+
let nextValue;
|
|
222
|
+
while (true) {
|
|
223
|
+
const result = await withCurrent(span, async () => {
|
|
224
|
+
try {
|
|
225
|
+
return await gen.next(nextValue);
|
|
226
|
+
} catch (e) {
|
|
227
|
+
return { value: void 0, done: true, error: e };
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if ("error" in result && result.error !== void 0) {
|
|
231
|
+
throw result.error;
|
|
232
|
+
}
|
|
233
|
+
if (result.done) {
|
|
234
|
+
return result.value;
|
|
235
|
+
}
|
|
236
|
+
nextValue = yield result.value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
var MAX_BINDING_STACK = 128;
|
|
240
|
+
var EMPTY_STACK = [];
|
|
241
|
+
var ContextStackStorage = class {
|
|
242
|
+
/** Emitted once when this runtime cannot support an ambient push. */
|
|
243
|
+
constructor(noAmbientBindWarning) {
|
|
244
|
+
this.noAmbientBindWarning = noAmbientBindWarning;
|
|
245
|
+
this._als = null;
|
|
246
|
+
this._enterWithUsable = false;
|
|
247
|
+
this._syncStack = EMPTY_STACK;
|
|
248
|
+
this._adoptionChecked = false;
|
|
249
|
+
this._warnedNoAmbientBind = false;
|
|
250
|
+
}
|
|
251
|
+
maybeAdoptAsyncLocalStorage() {
|
|
252
|
+
if (this._adoptionChecked) return;
|
|
253
|
+
this._adoptionChecked = true;
|
|
254
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
255
|
+
if (!Ctor) return;
|
|
256
|
+
const als = new Ctor();
|
|
257
|
+
try {
|
|
258
|
+
als.run(EMPTY_STACK, () => {
|
|
259
|
+
});
|
|
260
|
+
} catch (e) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this._als = als;
|
|
264
|
+
if (typeof als.enterWith === "function") {
|
|
265
|
+
try {
|
|
266
|
+
als.enterWith(EMPTY_STACK);
|
|
267
|
+
this._enterWithUsable = true;
|
|
268
|
+
} catch (e) {
|
|
269
|
+
this._enterWithUsable = false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
getStack() {
|
|
274
|
+
var _a;
|
|
275
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
276
|
+
if (this._als) return (_a = this._als.getStore()) != null ? _a : this._syncStack;
|
|
277
|
+
return this._syncStack;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Persist an ambient stack mutation. Returns false when an ALS is adopted but
|
|
281
|
+
* `enterWith` is unusable (workerd): callers must NOT fall back to the
|
|
282
|
+
* process-shared sync stack, since concurrent isolates would cross-stamp.
|
|
283
|
+
*/
|
|
284
|
+
setAmbientStack(stack) {
|
|
285
|
+
if (this._als) {
|
|
286
|
+
if (!this._enterWithUsable) return false;
|
|
287
|
+
this._als.enterWith(stack);
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
this._syncStack = stack;
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
push(binding) {
|
|
294
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
295
|
+
if (this._als && !this._enterWithUsable) {
|
|
296
|
+
this.warnNoAmbientBindOnce();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
let stack = this.getStack();
|
|
300
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
301
|
+
stack = stack.filter((b) => b.isLive());
|
|
302
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
303
|
+
stack = stack.slice(stack.length - (MAX_BINDING_STACK - 1));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
this.setAmbientStack([...stack, binding]);
|
|
307
|
+
}
|
|
308
|
+
remove(binding) {
|
|
309
|
+
binding.markDead();
|
|
310
|
+
const stack = this.getStack();
|
|
311
|
+
const pruned = stack.filter((b) => b !== binding && b.isLive());
|
|
312
|
+
if (pruned.length !== stack.length) {
|
|
313
|
+
this.setAmbientStack(pruned);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
runWith(binding, callback) {
|
|
317
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
318
|
+
if (this._als) {
|
|
319
|
+
return this._als.run([...this.getStack(), binding], callback);
|
|
320
|
+
}
|
|
321
|
+
const previous = this._syncStack;
|
|
322
|
+
this._syncStack = [...previous, binding];
|
|
323
|
+
try {
|
|
324
|
+
return callback();
|
|
325
|
+
} finally {
|
|
326
|
+
this._syncStack = previous;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
current() {
|
|
330
|
+
const stack = this.getStack();
|
|
331
|
+
if (stack.length === 0) return void 0;
|
|
332
|
+
const top = stack[stack.length - 1];
|
|
333
|
+
if (top.isLive()) return top;
|
|
334
|
+
const pruned = stack.filter((b) => b.isLive());
|
|
335
|
+
this.setAmbientStack(pruned);
|
|
336
|
+
return pruned.length > 0 ? pruned[pruned.length - 1] : void 0;
|
|
337
|
+
}
|
|
338
|
+
warnNoAmbientBindOnce() {
|
|
339
|
+
if (this._warnedNoAmbientBind) return;
|
|
340
|
+
this._warnedNoAmbientBind = true;
|
|
341
|
+
console.warn(this.noAmbientBindWarning);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
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.";
|
|
345
|
+
var ROUTING_STORAGE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.routingContextStorage");
|
|
346
|
+
function routingStorage() {
|
|
347
|
+
const holder = globalThis;
|
|
348
|
+
let storage = holder[ROUTING_STORAGE_KEY];
|
|
349
|
+
if (!storage) {
|
|
350
|
+
storage = new ContextStackStorage(NO_AMBIENT_ROUTING_BIND_WARNING);
|
|
351
|
+
holder[ROUTING_STORAGE_KEY] = storage;
|
|
352
|
+
}
|
|
353
|
+
return storage;
|
|
354
|
+
}
|
|
355
|
+
function currentRoutingBinding() {
|
|
356
|
+
const bound = routingStorage().current();
|
|
357
|
+
if (!bound) return void 0;
|
|
358
|
+
return {
|
|
359
|
+
projectId: bound.projectId,
|
|
360
|
+
authHint: bound.authHint,
|
|
361
|
+
...bound.appGit ? { appGit: bound.appGit } : {},
|
|
362
|
+
...bound.appGitSource ? { appGitSource: bound.appGitSource } : {}
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
var APP_COMMIT_SHA = "raindrop.app.commit_sha";
|
|
366
|
+
var APP_COMMIT_DIRTY = "raindrop.app.commit_dirty";
|
|
367
|
+
var APP_BRANCH = "raindrop.app.branch";
|
|
368
|
+
var APP_GIT_KEYS = [APP_COMMIT_SHA, APP_COMMIT_DIRTY, APP_BRANCH];
|
|
369
|
+
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
370
|
+
function appGitExplicitKeys(properties) {
|
|
371
|
+
const keys = /* @__PURE__ */ new Set();
|
|
372
|
+
if (!properties) return keys;
|
|
373
|
+
for (const key of APP_GIT_KEYS) {
|
|
374
|
+
if (own(properties, key)) keys.add(key);
|
|
375
|
+
}
|
|
376
|
+
return keys;
|
|
377
|
+
}
|
|
378
|
+
function mergeAppGitSnapshot(base, properties, explicitKeys = /* @__PURE__ */ new Set()) {
|
|
379
|
+
try {
|
|
380
|
+
const result = { ...base };
|
|
381
|
+
if (properties && own(properties, APP_COMMIT_SHA) && properties[APP_COMMIT_SHA] !== result[APP_COMMIT_SHA]) {
|
|
382
|
+
if (!explicitKeys.has(APP_COMMIT_DIRTY) && !own(properties, APP_COMMIT_DIRTY)) {
|
|
383
|
+
delete result[APP_COMMIT_DIRTY];
|
|
384
|
+
}
|
|
385
|
+
if (!explicitKeys.has(APP_BRANCH) && !own(properties, APP_BRANCH)) {
|
|
386
|
+
delete result[APP_BRANCH];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
for (const key of APP_GIT_KEYS) {
|
|
390
|
+
if (properties && own(properties, key)) result[key] = properties[key];
|
|
391
|
+
}
|
|
392
|
+
return Object.freeze(result);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
return Object.freeze({});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function validAppCommitSha(value) {
|
|
398
|
+
if (typeof value !== "string" || value.length > 128) return void 0;
|
|
399
|
+
const cleaned = value.trim();
|
|
400
|
+
return /^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(cleaned) ? cleaned.toLowerCase() : void 0;
|
|
401
|
+
}
|
|
402
|
+
function shortString(value) {
|
|
403
|
+
if (typeof value !== "string" || value.length > 1024) return void 0;
|
|
404
|
+
const cleaned = value.trim();
|
|
405
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
406
|
+
}
|
|
407
|
+
function flag(value) {
|
|
408
|
+
if (value === true || value === "true" || value === "1") return true;
|
|
409
|
+
if (value === false || value === "false" || value === "0") return false;
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
function environment() {
|
|
413
|
+
try {
|
|
414
|
+
return typeof process === "undefined" ? {} : process.env;
|
|
415
|
+
} catch (e) {
|
|
416
|
+
return {};
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
var DEPLOYMENTS = [
|
|
420
|
+
["VERCEL", "VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF"],
|
|
421
|
+
["NETLIFY", "COMMIT_REF", "BRANCH"],
|
|
422
|
+
["RAILWAY_ENVIRONMENT_NAME", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
423
|
+
["RAILWAY_ENVIRONMENT", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
424
|
+
["RENDER", "RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH"],
|
|
425
|
+
["DYNO", "HEROKU_BUILD_COMMIT", ""],
|
|
426
|
+
["DYNO", "HEROKU_SLUG_COMMIT", ""],
|
|
427
|
+
["AWS_APP_ID", "AWS_COMMIT_ID", "AWS_BRANCH"],
|
|
428
|
+
["WORKERS_CI", "WORKERS_CI_COMMIT_SHA", "WORKERS_CI_BRANCH"]
|
|
429
|
+
];
|
|
430
|
+
var CI_SOURCES = [
|
|
431
|
+
["GITHUB_ACTIONS", "GITHUB_SHA", "GITHUB_REF_NAME"],
|
|
432
|
+
["GITLAB_CI", "CI_COMMIT_SHA", "CI_COMMIT_REF_NAME"],
|
|
433
|
+
["CIRCLECI", "CIRCLE_SHA1", "CIRCLE_BRANCH"]
|
|
434
|
+
];
|
|
435
|
+
function detectedSource(env, table, detectBranch) {
|
|
436
|
+
for (const row of table) {
|
|
437
|
+
const [marker, shaKey, branchKey] = row;
|
|
438
|
+
if (!marker || !shaKey || !shortString(env[marker]) || flag(env[marker]) === false) continue;
|
|
439
|
+
const commitSha = validAppCommitSha(env[shaKey]);
|
|
440
|
+
if (commitSha)
|
|
441
|
+
return {
|
|
442
|
+
commitSha,
|
|
443
|
+
...detectBranch && branchKey ? { branch: shortString(env[branchKey]) } : {}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
return {};
|
|
447
|
+
}
|
|
448
|
+
var AppGitContextImpl = class {
|
|
449
|
+
constructor(options, runtime = {}) {
|
|
450
|
+
this.defaults = {};
|
|
451
|
+
this.explicit = {};
|
|
452
|
+
this.explicitKeys = /* @__PURE__ */ new Set();
|
|
453
|
+
this.disposed = false;
|
|
454
|
+
this.operations = /* @__PURE__ */ new Map();
|
|
455
|
+
this.operationOverflow = false;
|
|
456
|
+
this.detectBranch = false;
|
|
457
|
+
this.disabled = false;
|
|
458
|
+
var _a, _b, _c, _d, _e, _f;
|
|
459
|
+
try {
|
|
460
|
+
if (options === false) {
|
|
461
|
+
this.disabled = true;
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const opts = options != null ? options : {};
|
|
465
|
+
const env = (_a = runtime.env) != null ? _a : environment();
|
|
466
|
+
const detectBranch = (_c = (_b = flag(opts.detectBranch)) != null ? _b : flag(env.RAINDROP_GIT_DETECT_BRANCH)) != null ? _c : false;
|
|
467
|
+
this.detectBranch = detectBranch;
|
|
468
|
+
const collectBranch = detectBranch || runtime.captureLegacyReplayBranch === true;
|
|
469
|
+
const autoDetect = runtime.allowDiscovery === false ? false : (_e = (_d = flag(opts.autoDetect)) != null ? _d : flag(env.RAINDROP_GIT_AUTO_DETECT)) != null ? _e : true;
|
|
470
|
+
const configuredSha = opts.commitSha;
|
|
471
|
+
const explicitSha = configuredSha === void 0 ? env.RAINDROP_COMMIT_SHA : configuredSha;
|
|
472
|
+
if (explicitSha === null) this.explicit[APP_COMMIT_SHA] = null;
|
|
473
|
+
else if (typeof explicitSha === "string" && validAppCommitSha(explicitSha))
|
|
474
|
+
this.explicit[APP_COMMIT_SHA] = explicitSha;
|
|
475
|
+
const configuredDirty = opts.commitDirty;
|
|
476
|
+
const explicitDirty = configuredDirty === void 0 ? flag(env.RAINDROP_COMMIT_DIRTY) : configuredDirty;
|
|
477
|
+
if (explicitDirty === null || typeof explicitDirty === "boolean")
|
|
478
|
+
this.explicit[APP_COMMIT_DIRTY] = explicitDirty;
|
|
479
|
+
const configuredBranch = opts.branch;
|
|
480
|
+
const explicitBranch = configuredBranch === void 0 ? env.RAINDROP_BRANCH : configuredBranch;
|
|
481
|
+
if (explicitBranch === null) this.explicit[APP_BRANCH] = null;
|
|
482
|
+
else if (typeof explicitBranch === "string" && explicitBranch.length <= 1024)
|
|
483
|
+
this.explicit[APP_BRANCH] = explicitBranch;
|
|
484
|
+
this.explicitKeys = appGitExplicitKeys(this.explicit);
|
|
485
|
+
this.defaults = { ...this.explicit };
|
|
486
|
+
if (!autoDetect || explicitSha !== void 0) return;
|
|
487
|
+
const sourceDirectory = (_f = shortString(opts.sourceDirectory)) != null ? _f : shortString(env.RAINDROP_GIT_SOURCE_DIRECTORY);
|
|
488
|
+
if (runtime.allowLocalGit === false && !sourceDirectory) return;
|
|
489
|
+
const deploy = sourceDirectory ? {} : detectedSource(env, DEPLOYMENTS, collectBranch);
|
|
490
|
+
if (deploy.commitSha) {
|
|
491
|
+
this.accept(deploy);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const fallback = sourceDirectory ? {} : detectedSource(env, CI_SOURCES, collectBranch);
|
|
495
|
+
if (runtime.resolveLocal && (runtime.allowLocalGit !== false || sourceDirectory)) {
|
|
496
|
+
this.cancel = runtime.resolveLocal(sourceDirectory, collectBranch, (result) => {
|
|
497
|
+
try {
|
|
498
|
+
if (!this.disposed) this.accept(result.commitSha ? result : fallback);
|
|
499
|
+
} catch (e) {
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
} else this.accept(fallback);
|
|
503
|
+
} catch (e) {
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
accept(result) {
|
|
507
|
+
const sha = validAppCommitSha(result.commitSha);
|
|
508
|
+
if (!sha) return;
|
|
509
|
+
this.replayBranch = shortString(result.branch);
|
|
510
|
+
this.defaults = {
|
|
511
|
+
[APP_COMMIT_SHA]: sha,
|
|
512
|
+
...typeof result.commitDirty === "boolean" ? { [APP_COMMIT_DIRTY]: result.commitDirty } : {},
|
|
513
|
+
...this.detectBranch && this.replayBranch ? { [APP_BRANCH]: this.replayBranch } : {},
|
|
514
|
+
...this.explicit
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
snapshot(properties) {
|
|
518
|
+
var _a;
|
|
519
|
+
try {
|
|
520
|
+
const binding = currentRoutingBinding();
|
|
521
|
+
const base = this.disabled && (binding == null ? void 0 : binding.appGitSource) !== "replay-override" ? {} : (_a = binding == null ? void 0 : binding.appGit) != null ? _a : this.defaults;
|
|
522
|
+
return this.mergeSnapshot(base, properties);
|
|
523
|
+
} catch (e) {
|
|
524
|
+
return Object.freeze({});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/** Safe defaults when no operation/span start was observed; never infer identity. */
|
|
528
|
+
snapshotExplicit(properties, eventId) {
|
|
529
|
+
try {
|
|
530
|
+
const base = { ...this.explicit };
|
|
531
|
+
const operation = eventId ? this.operations.get(eventId) : void 0;
|
|
532
|
+
if (operation) {
|
|
533
|
+
for (const key of operation.explicitKeys) base[key] = operation.snapshot[key];
|
|
534
|
+
}
|
|
535
|
+
return this.mergeSnapshot(base, properties, new Set(Object.keys(base)));
|
|
536
|
+
} catch (e) {
|
|
537
|
+
return mergeAppGitSnapshot({}, properties);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
/** Existing replay branch reporting stays separate from opt-in event properties. */
|
|
541
|
+
snapshotForReplay() {
|
|
542
|
+
const snapshot = this.snapshot();
|
|
543
|
+
if (this.replayBranch && !own(snapshot, APP_BRANCH) && snapshot[APP_COMMIT_SHA] === this.defaults[APP_COMMIT_SHA]) {
|
|
544
|
+
return Object.freeze({ ...snapshot, [APP_BRANCH]: this.replayBranch });
|
|
545
|
+
}
|
|
546
|
+
return snapshot;
|
|
547
|
+
}
|
|
548
|
+
/** Merge a frozen span snapshot without losing client-authored provenance. */
|
|
549
|
+
mergeSnapshot(base, properties, explicitKeys = this.explicitKeys) {
|
|
550
|
+
return mergeAppGitSnapshot(base, properties, /* @__PURE__ */ new Set([...this.explicitKeys, ...explicitKeys]));
|
|
551
|
+
}
|
|
552
|
+
/** Shippers belonging to one client share this bounded operation registry. */
|
|
553
|
+
forOperation(eventId, properties, owner) {
|
|
554
|
+
if (!eventId) return this.snapshot(properties);
|
|
555
|
+
let operation = this.operations.get(eventId);
|
|
556
|
+
if (!operation) {
|
|
557
|
+
if (this.operations.size >= 1e4) this.operationOverflow = true;
|
|
558
|
+
if (this.operationOverflow) return this.mergeSnapshot({}, properties);
|
|
559
|
+
operation = {
|
|
560
|
+
snapshot: this.snapshot(properties),
|
|
561
|
+
owners: /* @__PURE__ */ new Set(),
|
|
562
|
+
unowned: owner === void 0,
|
|
563
|
+
explicitKeys: appGitExplicitKeys(properties)
|
|
564
|
+
};
|
|
565
|
+
this.operations.set(eventId, operation);
|
|
566
|
+
} else if (properties && APP_GIT_KEYS.some((key) => own(properties, key))) {
|
|
567
|
+
const explicitKeys = /* @__PURE__ */ new Set([...this.explicitKeys, ...operation.explicitKeys]);
|
|
568
|
+
operation.snapshot = this.mergeSnapshot(operation.snapshot, properties, explicitKeys);
|
|
569
|
+
for (const key of appGitExplicitKeys(properties)) operation.explicitKeys.add(key);
|
|
570
|
+
}
|
|
571
|
+
if (!owner) operation.unowned = true;
|
|
572
|
+
if (owner) operation.owners.add(owner);
|
|
573
|
+
return operation.snapshot;
|
|
574
|
+
}
|
|
575
|
+
releaseOperation(eventId, owner) {
|
|
576
|
+
const operation = this.operations.get(eventId);
|
|
577
|
+
if (!operation) return;
|
|
578
|
+
operation.owners.delete(owner);
|
|
579
|
+
if (operation.owners.size === 0 && !operation.unowned) this.operations.delete(eventId);
|
|
580
|
+
}
|
|
581
|
+
finishOperation(eventId) {
|
|
582
|
+
this.operations.delete(eventId);
|
|
583
|
+
}
|
|
584
|
+
dispose() {
|
|
585
|
+
var _a;
|
|
586
|
+
this.disposed = true;
|
|
587
|
+
try {
|
|
588
|
+
(_a = this.cancel) == null ? void 0 : _a.call(this);
|
|
589
|
+
} catch (e) {
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
var AppGitContext = AppGitContextImpl;
|
|
594
|
+
function createAppGitContext(options, runtime = {}) {
|
|
595
|
+
return new AppGitContext(options, runtime);
|
|
596
|
+
}
|
|
597
|
+
function withAppGitProperties(properties, snapshot) {
|
|
598
|
+
try {
|
|
599
|
+
const merged = { ...properties };
|
|
600
|
+
for (const key of APP_GIT_KEYS)
|
|
601
|
+
if (!own(merged, key) && own(snapshot, key)) merged[key] = snapshot[key];
|
|
602
|
+
return merged;
|
|
603
|
+
} catch (e) {
|
|
604
|
+
return properties != null ? properties : {};
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function withAppGitAttributes(attributes, snapshot) {
|
|
608
|
+
try {
|
|
609
|
+
const present = new Set(attributes.flatMap((attr) => attr ? [attr.key] : []));
|
|
610
|
+
const added = [];
|
|
611
|
+
for (const key of APP_GIT_KEYS) {
|
|
612
|
+
if (present.has(key) || present.has(`ai.telemetry.metadata.${key}`) || present.has(`traceloop.association.properties.${key}`))
|
|
613
|
+
continue;
|
|
614
|
+
const value = snapshot[key];
|
|
615
|
+
if (typeof value === "string") added.push({ key, value: { stringValue: value } });
|
|
616
|
+
else if (typeof value === "boolean") added.push({ key, value: { boolValue: value } });
|
|
617
|
+
}
|
|
618
|
+
return added.length ? [...attributes, ...added] : attributes;
|
|
619
|
+
} catch (e) {
|
|
620
|
+
return attributes;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function appGitPropertiesFromAttributes(attributes) {
|
|
624
|
+
var _a, _b, _c;
|
|
625
|
+
const properties = {};
|
|
626
|
+
try {
|
|
627
|
+
for (const attr of attributes) {
|
|
628
|
+
if (!attr) continue;
|
|
629
|
+
for (const key of APP_GIT_KEYS) {
|
|
630
|
+
if (attr.key === key || attr.key === `ai.telemetry.metadata.${key}` || attr.key === `traceloop.association.properties.${key}`) {
|
|
631
|
+
properties[key] = (_c = (_b = (_a = attr.value.stringValue) != null ? _a : attr.value.boolValue) != null ? _b : attr.value.intValue) != null ? _c : null;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
} catch (e) {
|
|
636
|
+
}
|
|
637
|
+
return properties;
|
|
638
|
+
}
|
|
70
639
|
function normalizeFeatureFlags(input) {
|
|
71
640
|
if (Array.isArray(input)) {
|
|
72
641
|
return Object.fromEntries(input.map((name) => [name, "true"]));
|
|
@@ -451,7 +1020,7 @@ function runWithTracingSuppressed(fn) {
|
|
|
451
1020
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
452
1021
|
var MAX_RETRY_DELAY_MS = 3e4;
|
|
453
1022
|
function wait(ms) {
|
|
454
|
-
return new Promise((
|
|
1023
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
455
1024
|
}
|
|
456
1025
|
function formatEndpoint(endpoint) {
|
|
457
1026
|
if (!endpoint) return void 0;
|
|
@@ -488,9 +1057,9 @@ async function raceWithTimeout(promise, timeoutMs) {
|
|
|
488
1057
|
() => true,
|
|
489
1058
|
() => true
|
|
490
1059
|
),
|
|
491
|
-
new Promise((
|
|
1060
|
+
new Promise((resolve2) => {
|
|
492
1061
|
var _a;
|
|
493
|
-
timer = setTimeout(() =>
|
|
1062
|
+
timer = setTimeout(() => resolve2(false), Math.max(0, timeoutMs));
|
|
494
1063
|
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
495
1064
|
})
|
|
496
1065
|
]);
|
|
@@ -657,82 +1226,33 @@ function attrStringArray(key, values) {
|
|
|
657
1226
|
function buildOtlpSpan(args) {
|
|
658
1227
|
const attrs = args.attributes.filter((x) => x !== void 0);
|
|
659
1228
|
const span = {
|
|
660
|
-
traceId: args.ids.traceIdB64,
|
|
661
|
-
spanId: args.ids.spanIdB64,
|
|
662
|
-
name: args.name,
|
|
663
|
-
startTimeUnixNano: args.startTimeUnixNano,
|
|
664
|
-
endTimeUnixNano: args.endTimeUnixNano
|
|
665
|
-
};
|
|
666
|
-
if (args.ids.parentSpanIdB64) span.parentSpanId = args.ids.parentSpanIdB64;
|
|
667
|
-
if (attrs.length) span.attributes = attrs;
|
|
668
|
-
if (args.status) span.status = args.status;
|
|
669
|
-
return span;
|
|
670
|
-
}
|
|
671
|
-
function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", serviceVersion = "0.0.0") {
|
|
672
|
-
return {
|
|
673
|
-
resourceSpans: [
|
|
674
|
-
{
|
|
675
|
-
resource: {
|
|
676
|
-
attributes: [{ key: "service.name", value: { stringValue: serviceName } }]
|
|
677
|
-
},
|
|
678
|
-
scopeSpans: [
|
|
679
|
-
{
|
|
680
|
-
scope: { name: serviceName, version: serviceVersion },
|
|
681
|
-
spans
|
|
682
|
-
}
|
|
683
|
-
]
|
|
684
|
-
}
|
|
685
|
-
]
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
689
|
-
function state() {
|
|
690
|
-
const holder = globalThis;
|
|
691
|
-
let current = holder[STATE_KEY];
|
|
692
|
-
if (!current) {
|
|
693
|
-
let storage = null;
|
|
694
|
-
try {
|
|
695
|
-
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
696
|
-
if (Ctor) storage = new Ctor();
|
|
697
|
-
} catch (e) {
|
|
698
|
-
storage = null;
|
|
699
|
-
}
|
|
700
|
-
current = {
|
|
701
|
-
storage,
|
|
702
|
-
syncDestination: void 0,
|
|
703
|
-
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
704
|
-
};
|
|
705
|
-
holder[STATE_KEY] = current;
|
|
706
|
-
}
|
|
707
|
-
return current;
|
|
708
|
-
}
|
|
709
|
-
function currentReplayTraceDestination() {
|
|
710
|
-
var _a, _b;
|
|
711
|
-
const routing = state();
|
|
712
|
-
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
713
|
-
}
|
|
714
|
-
function rememberReplayTraceDestination(span) {
|
|
715
|
-
const destination = currentReplayTraceDestination();
|
|
716
|
-
if (destination) state().spanDestinations.set(span, destination);
|
|
717
|
-
}
|
|
718
|
-
function copyReplayTraceDestination(source, target) {
|
|
719
|
-
const destination = state().spanDestinations.get(source);
|
|
720
|
-
if (destination) state().spanDestinations.set(target, destination);
|
|
721
|
-
}
|
|
722
|
-
function replayTraceDestinationFor(value) {
|
|
723
|
-
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
724
|
-
return void 0;
|
|
725
|
-
}
|
|
726
|
-
return state().spanDestinations.get(value);
|
|
727
|
-
}
|
|
728
|
-
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
729
|
-
var _a, _b;
|
|
730
|
-
if (!destination || !spanId || !traceId) return;
|
|
731
|
-
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
732
|
-
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
1229
|
+
traceId: args.ids.traceIdB64,
|
|
1230
|
+
spanId: args.ids.spanIdB64,
|
|
1231
|
+
name: args.name,
|
|
1232
|
+
startTimeUnixNano: args.startTimeUnixNano,
|
|
1233
|
+
endTimeUnixNano: args.endTimeUnixNano
|
|
1234
|
+
};
|
|
1235
|
+
if (args.ids.parentSpanIdB64) span.parentSpanId = args.ids.parentSpanIdB64;
|
|
1236
|
+
if (attrs.length) span.attributes = attrs;
|
|
1237
|
+
if (args.status) span.status = args.status;
|
|
1238
|
+
return span;
|
|
733
1239
|
}
|
|
734
|
-
function
|
|
735
|
-
return
|
|
1240
|
+
function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", serviceVersion = "0.0.0") {
|
|
1241
|
+
return {
|
|
1242
|
+
resourceSpans: [
|
|
1243
|
+
{
|
|
1244
|
+
resource: {
|
|
1245
|
+
attributes: [{ key: "service.name", value: { stringValue: serviceName } }]
|
|
1246
|
+
},
|
|
1247
|
+
scopeSpans: [
|
|
1248
|
+
{
|
|
1249
|
+
scope: { name: serviceName, version: serviceVersion },
|
|
1250
|
+
spans
|
|
1251
|
+
}
|
|
1252
|
+
]
|
|
1253
|
+
}
|
|
1254
|
+
]
|
|
1255
|
+
};
|
|
736
1256
|
}
|
|
737
1257
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
738
1258
|
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
@@ -868,6 +1388,13 @@ function projectIdHeaders(projectId) {
|
|
|
868
1388
|
}
|
|
869
1389
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
870
1390
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
1391
|
+
function appGitOwnerId(prefix) {
|
|
1392
|
+
try {
|
|
1393
|
+
return `${prefix}:${randomUUID()}`;
|
|
1394
|
+
} catch (e) {
|
|
1395
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
871
1398
|
function mergePatches(target, source) {
|
|
872
1399
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
873
1400
|
const out = { ...target, ...source };
|
|
@@ -917,22 +1444,25 @@ function eventTelemetryProperties(patch) {
|
|
|
917
1444
|
}
|
|
918
1445
|
var EventShipper = class {
|
|
919
1446
|
constructor(opts) {
|
|
1447
|
+
this.appGitOwner = appGitOwnerId("event");
|
|
920
1448
|
this.buffers = /* @__PURE__ */ new Map();
|
|
921
1449
|
this.sticky = /* @__PURE__ */ new Map();
|
|
922
1450
|
this.timers = /* @__PURE__ */ new Map();
|
|
923
1451
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
924
1452
|
this.hasShutdown = false;
|
|
925
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
926
|
-
this.
|
|
927
|
-
this.
|
|
1453
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1454
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1455
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1456
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1457
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
928
1458
|
this.enabled = opts.enabled !== false;
|
|
929
1459
|
this.debug = opts.debug;
|
|
930
|
-
this.partialFlushMs = (
|
|
931
|
-
this.sdkName = (
|
|
1460
|
+
this.partialFlushMs = (_d = opts.partialFlushMs) != null ? _d : 1e3;
|
|
1461
|
+
this.sdkName = (_e = opts.sdkName) != null ? _e : "core";
|
|
932
1462
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
933
|
-
this.defaultEventName = (
|
|
1463
|
+
this.defaultEventName = (_f = opts.defaultEventName) != null ? _f : "ai_generation";
|
|
934
1464
|
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
935
|
-
this.localDebuggerUrl = (
|
|
1465
|
+
this.localDebuggerUrl = (_g = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _g : void 0;
|
|
936
1466
|
if (this.debug && this.localDebuggerUrl) {
|
|
937
1467
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
938
1468
|
}
|
|
@@ -943,8 +1473,8 @@ var EventShipper = class {
|
|
|
943
1473
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
944
1474
|
this.context = {
|
|
945
1475
|
library: {
|
|
946
|
-
name: (
|
|
947
|
-
version: (
|
|
1476
|
+
name: (_h = opts.libraryName) != null ? _h : "@raindrop-ai/core",
|
|
1477
|
+
version: (_i = opts.libraryVersion) != null ? _i : "0.0.0"
|
|
948
1478
|
},
|
|
949
1479
|
metadata: {
|
|
950
1480
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -952,6 +1482,9 @@ var EventShipper = class {
|
|
|
952
1482
|
}
|
|
953
1483
|
};
|
|
954
1484
|
}
|
|
1485
|
+
ownAppGitContextForShutdown() {
|
|
1486
|
+
this.ownsAppGitContext = true;
|
|
1487
|
+
}
|
|
955
1488
|
isDebugEnabled() {
|
|
956
1489
|
return this.debug;
|
|
957
1490
|
}
|
|
@@ -1030,6 +1563,13 @@ var EventShipper = class {
|
|
|
1030
1563
|
}
|
|
1031
1564
|
const sticky = (_c = this.sticky.get(eventId)) != null ? _c : {};
|
|
1032
1565
|
const existing = (_d = this.buffers.get(eventId)) != null ? _d : {};
|
|
1566
|
+
patch = {
|
|
1567
|
+
...patch,
|
|
1568
|
+
properties: withAppGitProperties(
|
|
1569
|
+
patch.properties,
|
|
1570
|
+
this.appGitContext.forOperation(eventId, patch.properties, this.appGitOwner)
|
|
1571
|
+
)
|
|
1572
|
+
};
|
|
1033
1573
|
const merged = mergePatches(existing, patch);
|
|
1034
1574
|
merged.isPending = (_g = (_f = (_e = patch.isPending) != null ? _e : existing.isPending) != null ? _f : sticky.isPending) != null ? _g : true;
|
|
1035
1575
|
this.buffers.set(eventId, merged);
|
|
@@ -1043,6 +1583,8 @@ var EventShipper = class {
|
|
|
1043
1583
|
if (t) clearTimeout(t);
|
|
1044
1584
|
if (merged.isPending === false) {
|
|
1045
1585
|
await this.flushOne(eventId);
|
|
1586
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1587
|
+
else this.appGitContext.finishOperation(eventId);
|
|
1046
1588
|
return;
|
|
1047
1589
|
}
|
|
1048
1590
|
const timeout = setTimeout(() => {
|
|
@@ -1074,6 +1616,7 @@ var EventShipper = class {
|
|
|
1074
1616
|
if (!settled) this.warnShutdownDrop("in-flight request(s) at shutdown");
|
|
1075
1617
|
} finally {
|
|
1076
1618
|
this.shutdownDeadlineAt = void 0;
|
|
1619
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1077
1620
|
}
|
|
1078
1621
|
}
|
|
1079
1622
|
async trackSignal(signal) {
|
|
@@ -1508,6 +2051,13 @@ function redactJsonAttributeValue(key, value) {
|
|
|
1508
2051
|
if (scrubbedJson === json) return void 0;
|
|
1509
2052
|
return { stringValue: scrubbedJson };
|
|
1510
2053
|
}
|
|
2054
|
+
function appGitOwnerId2(prefix) {
|
|
2055
|
+
try {
|
|
2056
|
+
return `${prefix}:${randomUUID()}`;
|
|
2057
|
+
} catch (e) {
|
|
2058
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
1511
2061
|
function identityAttrs(args) {
|
|
1512
2062
|
return [
|
|
1513
2063
|
attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
|
|
@@ -1530,23 +2080,30 @@ function applyOtelSpanAttributeLimit(limit) {
|
|
|
1530
2080
|
}
|
|
1531
2081
|
var TraceShipper = class {
|
|
1532
2082
|
constructor(opts) {
|
|
2083
|
+
this.appGitOwner = appGitOwnerId2("trace");
|
|
2084
|
+
this.appGitEventIds = /* @__PURE__ */ new WeakMap();
|
|
2085
|
+
this.appGitActiveSpans = /* @__PURE__ */ new Map();
|
|
2086
|
+
this.appGitCaptured = /* @__PURE__ */ new WeakSet();
|
|
2087
|
+
this.appGitAdded = /* @__PURE__ */ new WeakMap();
|
|
1533
2088
|
this.queue = [];
|
|
1534
2089
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
1535
2090
|
this.hasShutdown = false;
|
|
1536
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1537
|
-
this.
|
|
1538
|
-
this.
|
|
2091
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2092
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
2093
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
2094
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
2095
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
1539
2096
|
this.enabled = opts.enabled !== false;
|
|
1540
2097
|
this.debug = opts.debug;
|
|
1541
2098
|
this.debugSpans = opts.debugSpans === true;
|
|
1542
|
-
this.flushIntervalMs = (
|
|
1543
|
-
this.maxBatchSize = (
|
|
1544
|
-
this.maxQueueSize = (
|
|
1545
|
-
this.sdkName = (
|
|
2099
|
+
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
2100
|
+
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
2101
|
+
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
2102
|
+
this.sdkName = (_g = opts.sdkName) != null ? _g : "core";
|
|
1546
2103
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
1547
|
-
this.serviceName = (
|
|
1548
|
-
this.serviceVersion = (
|
|
1549
|
-
this.localDebuggerUrl = (
|
|
2104
|
+
this.serviceName = (_h = opts.serviceName) != null ? _h : "raindrop.core";
|
|
2105
|
+
this.serviceVersion = (_i = opts.serviceVersion) != null ? _i : "0.0.0";
|
|
2106
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _j : void 0;
|
|
1550
2107
|
if (this.debug && this.localDebuggerUrl) {
|
|
1551
2108
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
1552
2109
|
}
|
|
@@ -1647,7 +2204,7 @@ var TraceShipper = class {
|
|
|
1647
2204
|
return { ...this.authHeaders(), ...projectIdHeaders(this.projectId) };
|
|
1648
2205
|
}
|
|
1649
2206
|
startSpan(args) {
|
|
1650
|
-
var _a, _b;
|
|
2207
|
+
var _a, _b, _c;
|
|
1651
2208
|
const ids = createSpanIds(args.parent);
|
|
1652
2209
|
const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1653
2210
|
const attrs = [
|
|
@@ -1657,13 +2214,24 @@ var TraceShipper = class {
|
|
|
1657
2214
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1658
2215
|
];
|
|
1659
2216
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
2217
|
+
const tracksAppGit = this.appGitActiveSpans.has(args.eventId) || this.appGitActiveSpans.size < 1e4;
|
|
2218
|
+
const appGitOverrides = appGitPropertiesFromAttributes(attrs);
|
|
1660
2219
|
const span = {
|
|
1661
2220
|
ids,
|
|
1662
2221
|
name: args.name,
|
|
1663
2222
|
startTimeUnixNano: started,
|
|
1664
|
-
attributes:
|
|
2223
|
+
attributes: withAppGitAttributes(
|
|
2224
|
+
attrs,
|
|
2225
|
+
this.appGitContext.forOperation(args.eventId, appGitOverrides, this.appGitOwner)
|
|
2226
|
+
)
|
|
1665
2227
|
};
|
|
1666
2228
|
rememberReplayTraceDestination(span);
|
|
2229
|
+
this.appGitCaptured.add(span);
|
|
2230
|
+
this.appGitEventIds.set(span, args.eventId);
|
|
2231
|
+
if (tracksAppGit) {
|
|
2232
|
+
this.appGitActiveSpans.set(args.eventId, ((_c = this.appGitActiveSpans.get(args.eventId)) != null ? _c : 0) + 1);
|
|
2233
|
+
}
|
|
2234
|
+
this.appGitAdded.set(span, new Set(span.attributes.filter((attr) => !attrs.includes(attr))));
|
|
1667
2235
|
const openSpan = buildOtlpSpan({
|
|
1668
2236
|
ids: span.ids,
|
|
1669
2237
|
name: span.name,
|
|
@@ -1703,11 +2271,17 @@ var TraceShipper = class {
|
|
|
1703
2271
|
});
|
|
1704
2272
|
}
|
|
1705
2273
|
endSpan(span, extra) {
|
|
1706
|
-
var _a, _b;
|
|
2274
|
+
var _a, _b, _c;
|
|
1707
2275
|
if (span.endTimeUnixNano) return;
|
|
1708
2276
|
span.endTimeUnixNano = (_a = extra == null ? void 0 : extra.endTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1709
2277
|
if ((_b = extra == null ? void 0 : extra.attributes) == null ? void 0 : _b.length) {
|
|
2278
|
+
const overrides = appGitPropertiesFromAttributes(extra.attributes);
|
|
2279
|
+
const eventId2 = this.appGitEventIds.get(span);
|
|
2280
|
+
const snapshot = eventId2 ? this.appGitContext.forOperation(eventId2, overrides, this.appGitOwner) : overrides;
|
|
2281
|
+
const added = this.appGitAdded.get(span);
|
|
2282
|
+
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));
|
|
1710
2283
|
span.attributes.push(...extra.attributes);
|
|
2284
|
+
span.attributes = withAppGitAttributes(span.attributes, snapshot);
|
|
1711
2285
|
}
|
|
1712
2286
|
let status = extra == null ? void 0 : extra.status;
|
|
1713
2287
|
if (!status && (extra == null ? void 0 : extra.error) !== void 0) {
|
|
@@ -1723,8 +2297,19 @@ var TraceShipper = class {
|
|
|
1723
2297
|
status
|
|
1724
2298
|
});
|
|
1725
2299
|
copyReplayTraceDestination(span, otlp);
|
|
2300
|
+
this.appGitCaptured.add(otlp);
|
|
1726
2301
|
this.enqueue(otlp);
|
|
1727
2302
|
this.mirrorToLocalDebugger(otlp, true);
|
|
2303
|
+
const eventId = this.appGitEventIds.get(span);
|
|
2304
|
+
if (eventId && this.appGitActiveSpans.has(eventId)) {
|
|
2305
|
+
const remaining = ((_c = this.appGitActiveSpans.get(eventId)) != null ? _c : 1) - 1;
|
|
2306
|
+
if (remaining > 0) this.appGitActiveSpans.set(eventId, remaining);
|
|
2307
|
+
else {
|
|
2308
|
+
this.appGitActiveSpans.delete(eventId);
|
|
2309
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
2310
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(eventId);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
1728
2313
|
}
|
|
1729
2314
|
createSpan(args) {
|
|
1730
2315
|
var _a;
|
|
@@ -1735,20 +2320,41 @@ var TraceShipper = class {
|
|
|
1735
2320
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1736
2321
|
];
|
|
1737
2322
|
if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
|
|
2323
|
+
const tracksAppGit = !this.appGitActiveSpans.has(args.eventId);
|
|
1738
2324
|
const otlp = buildOtlpSpan({
|
|
1739
2325
|
ids,
|
|
1740
2326
|
name: args.name,
|
|
1741
2327
|
startTimeUnixNano: args.startTimeUnixNano,
|
|
1742
2328
|
endTimeUnixNano: args.endTimeUnixNano,
|
|
1743
|
-
attributes:
|
|
2329
|
+
attributes: withAppGitAttributes(
|
|
2330
|
+
attrs,
|
|
2331
|
+
this.appGitContext.forOperation(
|
|
2332
|
+
args.eventId,
|
|
2333
|
+
appGitPropertiesFromAttributes(attrs),
|
|
2334
|
+
this.appGitOwner
|
|
2335
|
+
)
|
|
2336
|
+
),
|
|
1744
2337
|
status: args.status
|
|
1745
2338
|
});
|
|
1746
2339
|
rememberReplayTraceDestination(otlp);
|
|
2340
|
+
this.appGitCaptured.add(otlp);
|
|
2341
|
+
if (tracksAppGit) {
|
|
2342
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(args.eventId, this.appGitOwner);
|
|
2343
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(args.eventId);
|
|
2344
|
+
}
|
|
1747
2345
|
this.enqueue(otlp);
|
|
1748
2346
|
this.mirrorToLocalDebugger(otlp, true);
|
|
1749
2347
|
}
|
|
1750
2348
|
enqueue(span) {
|
|
2349
|
+
var _a;
|
|
1751
2350
|
if (!this.enabled) return;
|
|
2351
|
+
const attributes = (_a = span.attributes) != null ? _a : [];
|
|
2352
|
+
const enriched = this.appGitCaptured.has(span) ? attributes : withAppGitAttributes(attributes, this.appGitContext.snapshot(appGitPropertiesFromAttributes(attributes)));
|
|
2353
|
+
if (enriched !== attributes) {
|
|
2354
|
+
const original = span;
|
|
2355
|
+
span = { ...span, attributes: enriched.filter((attr) => attr !== void 0) };
|
|
2356
|
+
copyReplayTraceDestination(original, span);
|
|
2357
|
+
}
|
|
1752
2358
|
if (this.debugSpans) {
|
|
1753
2359
|
const short = (s) => s ? s.slice(-8) : "none";
|
|
1754
2360
|
console.log(
|
|
@@ -1894,127 +2500,305 @@ var TraceShipper = class {
|
|
|
1894
2500
|
}
|
|
1895
2501
|
} finally {
|
|
1896
2502
|
this.shutdownDeadlineAt = void 0;
|
|
2503
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1897
2504
|
}
|
|
1898
2505
|
}
|
|
1899
2506
|
};
|
|
1900
|
-
var
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2507
|
+
var PROMPT_TOOLS_ATTRIBUTE = "ai.prompt.tools";
|
|
2508
|
+
function isRecord(value) {
|
|
2509
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2510
|
+
}
|
|
2511
|
+
var JSON_SCHEMA_KEYS = [
|
|
2512
|
+
"type",
|
|
2513
|
+
"properties",
|
|
2514
|
+
"$schema",
|
|
2515
|
+
"$ref",
|
|
2516
|
+
"anyOf",
|
|
2517
|
+
"oneOf",
|
|
2518
|
+
"allOf",
|
|
2519
|
+
"enum",
|
|
2520
|
+
"const",
|
|
2521
|
+
"items",
|
|
2522
|
+
"additionalProperties",
|
|
2523
|
+
"required"
|
|
2524
|
+
];
|
|
2525
|
+
function isJsonSchema(value) {
|
|
2526
|
+
if (!isRecord(value)) return false;
|
|
2527
|
+
if (typeof value["~standard"] === "object") return false;
|
|
2528
|
+
if (isRecord(value._def) || isRecord(value._zod)) return false;
|
|
2529
|
+
if (Object.keys(value).length === 0) return true;
|
|
2530
|
+
return JSON_SCHEMA_KEYS.some((key) => key in value);
|
|
2531
|
+
}
|
|
2532
|
+
function toJsonSchema(value, options) {
|
|
2533
|
+
if (value === void 0 || value === null) return void 0;
|
|
2534
|
+
if (isJsonSchema(value)) return value;
|
|
2535
|
+
if (isRecord(value) && isJsonSchema(value.jsonSchema)) return value.jsonSchema;
|
|
2536
|
+
if (isRecord(value) && isJsonSchema(value.json)) return value.json;
|
|
2537
|
+
if (options == null ? void 0 : options.schema) {
|
|
1922
2538
|
try {
|
|
1923
|
-
return
|
|
1924
|
-
}
|
|
1925
|
-
|
|
2539
|
+
return options.schema(value);
|
|
2540
|
+
} catch (e) {
|
|
2541
|
+
return void 0;
|
|
1926
2542
|
}
|
|
1927
2543
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2544
|
+
return void 0;
|
|
2545
|
+
}
|
|
2546
|
+
function pickString(value) {
|
|
2547
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
2548
|
+
}
|
|
2549
|
+
function functionTool(name, description, schema, options) {
|
|
2550
|
+
const tool = { type: "function", name };
|
|
2551
|
+
const desc = pickString(description);
|
|
2552
|
+
if (desc !== void 0) tool.description = desc;
|
|
2553
|
+
const inputSchema = toJsonSchema(schema, options);
|
|
2554
|
+
if (inputSchema !== void 0) tool.inputSchema = inputSchema;
|
|
2555
|
+
return tool;
|
|
2556
|
+
}
|
|
2557
|
+
function normalizeToolDeclaration(tool, options, fallbackName) {
|
|
2558
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2559
|
+
if (!isRecord(tool)) return void 0;
|
|
2560
|
+
if (tool.type === "provider-defined" || tool.type === "provider") {
|
|
2561
|
+
const name2 = (_b = (_a = pickString(tool.name)) != null ? _a : pickString(tool.id)) != null ? _b : fallbackName;
|
|
2562
|
+
if (name2 === void 0) return void 0;
|
|
2563
|
+
const declaration = { type: "provider-defined", name: name2 };
|
|
2564
|
+
const id = pickString(tool.id);
|
|
2565
|
+
if (id !== void 0) declaration.id = id;
|
|
2566
|
+
if (isRecord(tool.args)) declaration.args = tool.args;
|
|
2567
|
+
return declaration;
|
|
2568
|
+
}
|
|
2569
|
+
if (isRecord(tool.toolSpec)) {
|
|
2570
|
+
const spec = tool.toolSpec;
|
|
2571
|
+
const name2 = (_c = pickString(spec.name)) != null ? _c : fallbackName;
|
|
2572
|
+
if (name2 === void 0) return void 0;
|
|
2573
|
+
return functionTool(name2, spec.description, spec.inputSchema, options);
|
|
2574
|
+
}
|
|
2575
|
+
if (isRecord(tool.function)) {
|
|
2576
|
+
const fn = tool.function;
|
|
2577
|
+
const name2 = (_d = pickString(fn.name)) != null ? _d : fallbackName;
|
|
2578
|
+
if (name2 === void 0) return void 0;
|
|
2579
|
+
return functionTool(name2, fn.description, (_e = fn.parameters) != null ? _e : fn.input_schema, options);
|
|
2580
|
+
}
|
|
2581
|
+
const name = (_g = (_f = pickString(tool.name)) != null ? _f : pickString(tool.id)) != null ? _g : fallbackName;
|
|
2582
|
+
if (name === void 0) return void 0;
|
|
2583
|
+
const type = pickString(tool.type);
|
|
2584
|
+
if (type !== void 0 && type !== "function" && type !== "dynamic" && type !== "custom") {
|
|
2585
|
+
if (!("input_schema" in tool) && !("inputSchema" in tool) && !("parameters" in tool)) {
|
|
2586
|
+
return { type: "provider-defined", id: type, name };
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
return functionTool(
|
|
2590
|
+
name,
|
|
2591
|
+
tool.description,
|
|
2592
|
+
(_j = (_i = (_h = tool.inputSchema) != null ? _h : tool.input_schema) != null ? _i : tool.parameters) != null ? _j : tool.schema,
|
|
2593
|
+
options
|
|
2594
|
+
);
|
|
2595
|
+
}
|
|
2596
|
+
var NOT_A_GEMINI_GROUP_KEYS = ["name", "id", "type", "function", "toolSpec", "cachePoint"];
|
|
2597
|
+
function isGeminiToolGroup(tool) {
|
|
2598
|
+
if (Array.isArray(tool.functionDeclarations)) return true;
|
|
2599
|
+
const keys = Object.keys(tool);
|
|
2600
|
+
if (keys.length === 0 || NOT_A_GEMINI_GROUP_KEYS.some((key) => key in tool)) return false;
|
|
2601
|
+
return keys.every((key) => isRecord(tool[key]));
|
|
2602
|
+
}
|
|
2603
|
+
function expandGeminiTool(tool, options) {
|
|
2604
|
+
const declarations = [];
|
|
2605
|
+
for (const [key, value] of Object.entries(tool)) {
|
|
2606
|
+
if (key === "functionDeclarations" && Array.isArray(value)) {
|
|
2607
|
+
for (const declaration of value) {
|
|
2608
|
+
const normalized = normalizeToolDeclaration(declaration, options);
|
|
2609
|
+
if (normalized) declarations.push(normalized);
|
|
2610
|
+
}
|
|
2611
|
+
} else if (isRecord(value)) {
|
|
2612
|
+
declarations.push({ type: "provider-defined", id: key, name: key, args: value });
|
|
1939
2613
|
}
|
|
1940
|
-
this._fallback = new SynchronousContextStorage();
|
|
1941
|
-
this._storage = this._fallback;
|
|
1942
|
-
}
|
|
1943
|
-
maybeAdoptAsyncLocalStorage() {
|
|
1944
|
-
if (!this._fallback || !this._fallback.isEmpty()) return;
|
|
1945
|
-
const Ctor = getAsyncLocalStorageCtor();
|
|
1946
|
-
if (!Ctor) return;
|
|
1947
|
-
this._storage = new Ctor();
|
|
1948
|
-
this._fallback = null;
|
|
1949
|
-
}
|
|
1950
|
-
isReady() {
|
|
1951
|
-
return true;
|
|
1952
|
-
}
|
|
1953
|
-
getParentSpanIds() {
|
|
1954
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1955
|
-
const span = this._storage.getStore();
|
|
1956
|
-
if (!span || span === NOOP_SPAN) return void 0;
|
|
1957
|
-
return {
|
|
1958
|
-
traceIdB64: span.traceIdB64,
|
|
1959
|
-
spanIdB64: span.spanIdB64,
|
|
1960
|
-
eventId: span.eventId
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
runInContext(span, callback) {
|
|
1964
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1965
|
-
return this._storage.run(span, callback);
|
|
1966
2614
|
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2615
|
+
return declarations;
|
|
2616
|
+
}
|
|
2617
|
+
function normalizeToolDeclarations(tools, options) {
|
|
2618
|
+
if (tools === void 0 || tools === null) return void 0;
|
|
2619
|
+
if (Array.isArray(tools)) {
|
|
2620
|
+
return tools.flatMap((tool) => {
|
|
2621
|
+
if (isRecord(tool) && isGeminiToolGroup(tool)) {
|
|
2622
|
+
return expandGeminiTool(tool, options);
|
|
2623
|
+
}
|
|
2624
|
+
const declaration = normalizeToolDeclaration(tool, options);
|
|
2625
|
+
return declaration ? [declaration] : [];
|
|
2626
|
+
});
|
|
1976
2627
|
}
|
|
1977
|
-
return
|
|
2628
|
+
if (!isRecord(tools)) return void 0;
|
|
2629
|
+
return Object.entries(tools).flatMap(([key, tool]) => {
|
|
2630
|
+
const declaration = normalizeToolDeclaration(tool, options, key);
|
|
2631
|
+
return declaration ? [declaration] : [];
|
|
2632
|
+
});
|
|
1978
2633
|
}
|
|
1979
|
-
function
|
|
2634
|
+
function resolvePromptTools(args) {
|
|
1980
2635
|
var _a;
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
return
|
|
1985
|
-
}
|
|
1986
|
-
async function getCurrentParentSpanContext() {
|
|
1987
|
-
var _a, _b;
|
|
1988
|
-
return (_b = getContextManager().getParentSpanIds()) != null ? _b : (_a = currentReplayTraceDestination()) == null ? void 0 : _a.parentSpanContext;
|
|
2636
|
+
if (args.override !== void 0) {
|
|
2637
|
+
return (_a = normalizeToolDeclarations(args.override, args.options)) != null ? _a : [];
|
|
2638
|
+
}
|
|
2639
|
+
return normalizeToolDeclarations(args.inferred, args.options);
|
|
1989
2640
|
}
|
|
1990
|
-
|
|
1991
|
-
const
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2641
|
+
function promptToolsAttribute(tools) {
|
|
2642
|
+
const values = promptToolsAttributeValue(tools);
|
|
2643
|
+
if (values === void 0) return void 0;
|
|
2644
|
+
return {
|
|
2645
|
+
key: PROMPT_TOOLS_ATTRIBUTE,
|
|
2646
|
+
value: { arrayValue: { values: values.map((stringValue) => ({ stringValue })) } }
|
|
1996
2647
|
};
|
|
1997
|
-
return cm.runInContext(span, fn);
|
|
1998
2648
|
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2649
|
+
function promptToolsAttributeValue(tools) {
|
|
2650
|
+
if (tools === void 0) return void 0;
|
|
2651
|
+
return tools.map((tool) => {
|
|
2652
|
+
try {
|
|
2653
|
+
return JSON.stringify(tool);
|
|
2654
|
+
} catch (e) {
|
|
2655
|
+
return JSON.stringify({ type: tool.type, name: tool.name });
|
|
2656
|
+
}
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
var resolveLocal = (sourceDirectory, detectBranch, completed) => {
|
|
2660
|
+
const cwd = sourceDirectory ? path.resolve(sourceDirectory) : process.cwd();
|
|
2661
|
+
let cancelled = false;
|
|
2662
|
+
let active;
|
|
2663
|
+
let deadlineTimer;
|
|
2664
|
+
const deadline = Date.now() + 1e3;
|
|
2665
|
+
const run = (args, done) => {
|
|
2666
|
+
if (cancelled) return;
|
|
2667
|
+
const remaining = deadline - Date.now();
|
|
2668
|
+
if (remaining <= 0) {
|
|
2669
|
+
done(void 0);
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
try {
|
|
2673
|
+
active = child_process.execFile(
|
|
2674
|
+
"git",
|
|
2675
|
+
args,
|
|
2676
|
+
{
|
|
2677
|
+
cwd,
|
|
2678
|
+
encoding: "utf8",
|
|
2679
|
+
maxBuffer: 4096,
|
|
2680
|
+
windowsHide: true,
|
|
2681
|
+
env: {
|
|
2682
|
+
...process.env,
|
|
2683
|
+
// The selected application cwd, not the invoking shell's Git plumbing, owns identity.
|
|
2684
|
+
GIT_DIR: void 0,
|
|
2685
|
+
GIT_WORK_TREE: void 0,
|
|
2686
|
+
GIT_COMMON_DIR: void 0,
|
|
2687
|
+
GIT_NAMESPACE: void 0,
|
|
2688
|
+
GIT_INDEX_FILE: void 0,
|
|
2689
|
+
GIT_OBJECT_DIRECTORY: void 0,
|
|
2690
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: void 0,
|
|
2691
|
+
GIT_CONFIG_PARAMETERS: void 0,
|
|
2692
|
+
GIT_CONFIG_COUNT: "0",
|
|
2693
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
2694
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
2695
|
+
}
|
|
2696
|
+
},
|
|
2697
|
+
(error, stdout) => {
|
|
2698
|
+
clearTimeout(deadlineTimer);
|
|
2699
|
+
deadlineTimer = void 0;
|
|
2700
|
+
active = void 0;
|
|
2701
|
+
if (!cancelled) {
|
|
2702
|
+
try {
|
|
2703
|
+
done(error ? void 0 : stdout.trim());
|
|
2704
|
+
} catch (e) {
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
);
|
|
2709
|
+
active.unref();
|
|
2710
|
+
if (active.stdout && "unref" in active.stdout && typeof active.stdout.unref === "function")
|
|
2711
|
+
active.stdout.unref();
|
|
2712
|
+
if (active.stderr && "unref" in active.stderr && typeof active.stderr.unref === "function")
|
|
2713
|
+
active.stderr.unref();
|
|
2714
|
+
deadlineTimer = setTimeout(() => {
|
|
2715
|
+
try {
|
|
2716
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2717
|
+
} catch (e) {
|
|
2718
|
+
}
|
|
2719
|
+
}, remaining);
|
|
2720
|
+
deadlineTimer.unref();
|
|
2721
|
+
} catch (e) {
|
|
2003
2722
|
try {
|
|
2004
|
-
|
|
2005
|
-
} catch (
|
|
2006
|
-
return { value: void 0, done: true, error: e };
|
|
2723
|
+
done(void 0);
|
|
2724
|
+
} catch (e2) {
|
|
2007
2725
|
}
|
|
2008
|
-
});
|
|
2009
|
-
if ("error" in result && result.error !== void 0) {
|
|
2010
|
-
throw result.error;
|
|
2011
2726
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2727
|
+
};
|
|
2728
|
+
const scheduled = setTimeout(() => {
|
|
2729
|
+
try {
|
|
2730
|
+
run(["rev-parse", "HEAD"], (rawSha) => {
|
|
2731
|
+
const commitSha = validAppCommitSha(rawSha);
|
|
2732
|
+
if (!commitSha) {
|
|
2733
|
+
completed({});
|
|
2734
|
+
return;
|
|
2735
|
+
}
|
|
2736
|
+
run(["-c", "core.fsmonitor=false", "status", "--porcelain"], (status) => {
|
|
2737
|
+
const finish = (branch) => {
|
|
2738
|
+
run(["rev-parse", "HEAD"], (finalSha) => {
|
|
2739
|
+
const coherent = validAppCommitSha(finalSha) === commitSha;
|
|
2740
|
+
completed({
|
|
2741
|
+
commitSha,
|
|
2742
|
+
...coherent && status !== void 0 ? { commitDirty: status !== "" } : {},
|
|
2743
|
+
...coherent && branch && branch !== "HEAD" ? { branch } : {}
|
|
2744
|
+
});
|
|
2745
|
+
});
|
|
2746
|
+
};
|
|
2747
|
+
if (detectBranch) run(["symbolic-ref", "--quiet", "--short", "HEAD"], finish);
|
|
2748
|
+
else finish();
|
|
2749
|
+
});
|
|
2750
|
+
});
|
|
2751
|
+
} catch (e) {
|
|
2752
|
+
completed({});
|
|
2753
|
+
}
|
|
2754
|
+
}, 0);
|
|
2755
|
+
scheduled.unref();
|
|
2756
|
+
return () => {
|
|
2757
|
+
cancelled = true;
|
|
2758
|
+
clearTimeout(scheduled);
|
|
2759
|
+
clearTimeout(deadlineTimer);
|
|
2760
|
+
try {
|
|
2761
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2762
|
+
} catch (e) {
|
|
2014
2763
|
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2764
|
+
};
|
|
2765
|
+
};
|
|
2766
|
+
function createAppGitContext2(options, runtime = {}) {
|
|
2767
|
+
return new AppGitContext(options, { ...runtime, resolveLocal });
|
|
2768
|
+
}
|
|
2769
|
+
function hasDestination(options) {
|
|
2770
|
+
var _a;
|
|
2771
|
+
if (options.enabled === false) return false;
|
|
2772
|
+
return Boolean(((_a = options.writeKey) == null ? void 0 : _a.trim()) || resolveLocalDebuggerBaseUrl(options.localDebuggerUrl));
|
|
2017
2773
|
}
|
|
2774
|
+
var EventShipper2 = class extends EventShipper {
|
|
2775
|
+
constructor(options) {
|
|
2776
|
+
var _a;
|
|
2777
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2778
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2779
|
+
try {
|
|
2780
|
+
super({ ...options, appGitContext });
|
|
2781
|
+
} catch (error) {
|
|
2782
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2783
|
+
throw error;
|
|
2784
|
+
}
|
|
2785
|
+
if (ownsAppGitContext) this.ownAppGitContextForShutdown();
|
|
2786
|
+
}
|
|
2787
|
+
};
|
|
2788
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
2789
|
+
constructor(options) {
|
|
2790
|
+
var _a;
|
|
2791
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2792
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2793
|
+
try {
|
|
2794
|
+
super({ ...options, appGitContext });
|
|
2795
|
+
} catch (error) {
|
|
2796
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2797
|
+
throw error;
|
|
2798
|
+
}
|
|
2799
|
+
this.ownsAppGitContext = ownsAppGitContext;
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2018
2802
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
2019
2803
|
var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
|
|
2020
2804
|
"OpenTelemetry SDK Context Key SUPPRESS_TRACING"
|
|
@@ -2045,14 +2829,14 @@ installTracingSuppressionHook();
|
|
|
2045
2829
|
// package.json
|
|
2046
2830
|
var package_default = {
|
|
2047
2831
|
name: "@raindrop-ai/ai-sdk",
|
|
2048
|
-
version: "0.3.
|
|
2832
|
+
version: "0.3.4"};
|
|
2049
2833
|
|
|
2050
2834
|
// src/internal/version.ts
|
|
2051
2835
|
var libraryName = package_default.name;
|
|
2052
2836
|
var libraryVersion = package_default.version;
|
|
2053
2837
|
|
|
2054
2838
|
// src/internal/events.ts
|
|
2055
|
-
var
|
|
2839
|
+
var EventShipper3 = class extends EventShipper2 {
|
|
2056
2840
|
constructor(opts) {
|
|
2057
2841
|
var _a, _b, _c;
|
|
2058
2842
|
super({
|
|
@@ -2192,7 +2976,7 @@ function boundedStringify(value, limit) {
|
|
|
2192
2976
|
}
|
|
2193
2977
|
|
|
2194
2978
|
// src/internal/wrap/helpers.ts
|
|
2195
|
-
function
|
|
2979
|
+
function isRecord2(value) {
|
|
2196
2980
|
return typeof value === "object" && value !== null;
|
|
2197
2981
|
}
|
|
2198
2982
|
function isFunction(value) {
|
|
@@ -2231,7 +3015,7 @@ function extractModelInfo(model) {
|
|
|
2231
3015
|
}
|
|
2232
3016
|
return { modelId: model };
|
|
2233
3017
|
}
|
|
2234
|
-
if (!
|
|
3018
|
+
if (!isRecord2(model)) return {};
|
|
2235
3019
|
const provider = typeof model["provider"] === "string" ? model["provider"] : void 0;
|
|
2236
3020
|
let modelIdRaw;
|
|
2237
3021
|
if (typeof model["modelId"] === "string") {
|
|
@@ -2252,13 +3036,13 @@ function extractModelInfo(model) {
|
|
|
2252
3036
|
return { provider, modelId: modelIdRaw };
|
|
2253
3037
|
}
|
|
2254
3038
|
function extractTextOutput(result) {
|
|
2255
|
-
if (!
|
|
3039
|
+
if (!isRecord2(result)) return void 0;
|
|
2256
3040
|
const text = result["text"];
|
|
2257
3041
|
return typeof text === "string" ? text : void 0;
|
|
2258
3042
|
}
|
|
2259
3043
|
function extractObjectOutput(result) {
|
|
2260
3044
|
var _a;
|
|
2261
|
-
if (!
|
|
3045
|
+
if (!isRecord2(result)) return void 0;
|
|
2262
3046
|
const obj = result["object"];
|
|
2263
3047
|
if (obj === void 0) return void 0;
|
|
2264
3048
|
return (_a = safeJson(obj)) != null ? _a : String(obj);
|
|
@@ -2266,24 +3050,24 @@ function extractObjectOutput(result) {
|
|
|
2266
3050
|
function isAgentClass(value) {
|
|
2267
3051
|
if (typeof value !== "function") return false;
|
|
2268
3052
|
const proto = value.prototype;
|
|
2269
|
-
if (!
|
|
3053
|
+
if (!isRecord2(proto)) return false;
|
|
2270
3054
|
return typeof proto["generate"] === "function" && typeof proto["stream"] === "function";
|
|
2271
3055
|
}
|
|
2272
3056
|
function extractModel(result) {
|
|
2273
|
-
if (!
|
|
3057
|
+
if (!isRecord2(result)) return void 0;
|
|
2274
3058
|
const model = result["model"];
|
|
2275
3059
|
if (typeof model === "string" && model.length) return model;
|
|
2276
3060
|
const response = result["response"];
|
|
2277
|
-
if (
|
|
3061
|
+
if (isRecord2(response)) {
|
|
2278
3062
|
const modelId = response["modelId"];
|
|
2279
3063
|
if (typeof modelId === "string" && modelId.length) return modelId;
|
|
2280
3064
|
}
|
|
2281
3065
|
return void 0;
|
|
2282
3066
|
}
|
|
2283
3067
|
function extractFinishReason(result) {
|
|
2284
|
-
if (!
|
|
3068
|
+
if (!isRecord2(result)) return void 0;
|
|
2285
3069
|
if (typeof result["finishReason"] === "string") return result["finishReason"];
|
|
2286
|
-
if (
|
|
3070
|
+
if (isRecord2(result["finishReason"]) && typeof result["finishReason"]["unified"] === "string") {
|
|
2287
3071
|
return result["finishReason"]["unified"];
|
|
2288
3072
|
}
|
|
2289
3073
|
return void 0;
|
|
@@ -2327,7 +3111,7 @@ function attachmentMediaType(part) {
|
|
|
2327
3111
|
if (typeof part["mediaType"] === "string") return part["mediaType"];
|
|
2328
3112
|
if (typeof part["mimeType"] === "string") return part["mimeType"];
|
|
2329
3113
|
const file = part["file"];
|
|
2330
|
-
if (
|
|
3114
|
+
if (isRecord2(file)) {
|
|
2331
3115
|
if (typeof file["mediaType"] === "string") return file["mediaType"];
|
|
2332
3116
|
if (typeof file["mimeType"] === "string") return file["mimeType"];
|
|
2333
3117
|
}
|
|
@@ -2337,7 +3121,7 @@ function attachmentName(part) {
|
|
|
2337
3121
|
if (typeof part["filename"] === "string") return part["filename"];
|
|
2338
3122
|
if (typeof part["name"] === "string") return part["name"];
|
|
2339
3123
|
const file = part["file"];
|
|
2340
|
-
if (
|
|
3124
|
+
if (isRecord2(file)) {
|
|
2341
3125
|
if (typeof file["filename"] === "string") return file["filename"];
|
|
2342
3126
|
if (typeof file["name"] === "string") return file["name"];
|
|
2343
3127
|
}
|
|
@@ -2346,7 +3130,7 @@ function attachmentName(part) {
|
|
|
2346
3130
|
function attachmentData(part) {
|
|
2347
3131
|
if ("data" in part) return part["data"];
|
|
2348
3132
|
const file = part["file"];
|
|
2349
|
-
if (
|
|
3133
|
+
if (isRecord2(file)) {
|
|
2350
3134
|
if ("file_data" in file) return file["file_data"];
|
|
2351
3135
|
if ("data" in file) return file["data"];
|
|
2352
3136
|
}
|
|
@@ -2364,7 +3148,7 @@ function contentPartToAttachment(part, role) {
|
|
|
2364
3148
|
}
|
|
2365
3149
|
if (partType === "image_url") {
|
|
2366
3150
|
const imageUrlPart = part["image_url"];
|
|
2367
|
-
const imageUrlValue =
|
|
3151
|
+
const imageUrlValue = isRecord2(imageUrlPart) ? imageUrlPart["url"] : imageUrlPart;
|
|
2368
3152
|
const value = asDataUrl(imageUrlValue, "image/png");
|
|
2369
3153
|
if (!value) return void 0;
|
|
2370
3154
|
return { type: "image", role, value };
|
|
@@ -2384,7 +3168,7 @@ function attachmentsFromContent(content, role) {
|
|
|
2384
3168
|
if (!Array.isArray(content)) return void 0;
|
|
2385
3169
|
const attachments = [];
|
|
2386
3170
|
for (const part of content) {
|
|
2387
|
-
if (!
|
|
3171
|
+
if (!isRecord2(part)) continue;
|
|
2388
3172
|
const attachment = contentPartToAttachment(part, role);
|
|
2389
3173
|
if (attachment) attachments.push(attachment);
|
|
2390
3174
|
}
|
|
@@ -2417,7 +3201,7 @@ async function outputAttachmentsFromFiles(files) {
|
|
|
2417
3201
|
if (!Array.isArray(resolvedFiles)) return void 0;
|
|
2418
3202
|
const attachments = [];
|
|
2419
3203
|
for (const file of resolvedFiles) {
|
|
2420
|
-
if (!
|
|
3204
|
+
if (!isRecord2(file)) continue;
|
|
2421
3205
|
const attachment = generatedFileToAttachment(file);
|
|
2422
3206
|
if (attachment) attachments.push(attachment);
|
|
2423
3207
|
}
|
|
@@ -2428,7 +3212,7 @@ function extractTextFromMessageContent(content) {
|
|
|
2428
3212
|
if (!Array.isArray(content)) return void 0;
|
|
2429
3213
|
let result = "";
|
|
2430
3214
|
for (const part of content) {
|
|
2431
|
-
if (!
|
|
3215
|
+
if (!isRecord2(part) || part["type"] !== "text" || typeof part["text"] !== "string") continue;
|
|
2432
3216
|
result += part["text"];
|
|
2433
3217
|
}
|
|
2434
3218
|
return result.length ? result : void 0;
|
|
@@ -2445,7 +3229,7 @@ function lastUserMessageFromArgs(args) {
|
|
|
2445
3229
|
if (!messages) return void 0;
|
|
2446
3230
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2447
3231
|
const message = messages[i];
|
|
2448
|
-
if (
|
|
3232
|
+
if (isRecord2(message) && message["role"] === "user") {
|
|
2449
3233
|
return message;
|
|
2450
3234
|
}
|
|
2451
3235
|
}
|
|
@@ -2453,24 +3237,24 @@ function lastUserMessageFromArgs(args) {
|
|
|
2453
3237
|
}
|
|
2454
3238
|
function extractInputAttachmentsFromArgs(args) {
|
|
2455
3239
|
var _a;
|
|
2456
|
-
if (!
|
|
3240
|
+
if (!isRecord2(args)) return void 0;
|
|
2457
3241
|
return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
|
|
2458
3242
|
}
|
|
2459
3243
|
async function extractOutputAttachmentsFromResult(result) {
|
|
2460
|
-
if (!
|
|
3244
|
+
if (!isRecord2(result)) return void 0;
|
|
2461
3245
|
const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
|
|
2462
3246
|
if (fileAttachments == null ? void 0 : fileAttachments.length) return fileAttachments;
|
|
2463
3247
|
const responseMessages = extractResponseMessages(result);
|
|
2464
3248
|
for (let i = responseMessages.length - 1; i >= 0; i--) {
|
|
2465
3249
|
const message = responseMessages[i];
|
|
2466
|
-
if (!
|
|
3250
|
+
if (!isRecord2(message) || message["role"] !== "assistant") continue;
|
|
2467
3251
|
return attachmentsFromContent(message["content"], "output");
|
|
2468
3252
|
}
|
|
2469
3253
|
return attachmentsFromContent(result["content"], "output");
|
|
2470
3254
|
}
|
|
2471
3255
|
function lastUserMessageTextFromArgs(args) {
|
|
2472
3256
|
var _a, _b;
|
|
2473
|
-
if (!
|
|
3257
|
+
if (!isRecord2(args)) return void 0;
|
|
2474
3258
|
const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
|
|
2475
3259
|
if (content === void 0) return void 0;
|
|
2476
3260
|
const text = extractTextFromMessageContent(content);
|
|
@@ -2479,13 +3263,13 @@ function lastUserMessageTextFromArgs(args) {
|
|
|
2479
3263
|
}
|
|
2480
3264
|
function extractInputFromArgs(args) {
|
|
2481
3265
|
var _a;
|
|
2482
|
-
if (!
|
|
3266
|
+
if (!isRecord2(args)) return void 0;
|
|
2483
3267
|
const prompt = args["prompt"];
|
|
2484
3268
|
if (typeof prompt === "string") return prompt;
|
|
2485
3269
|
const messages = messagesFromArgs(args);
|
|
2486
3270
|
if (Array.isArray(messages) && messages.length > 0) {
|
|
2487
3271
|
const last = messages[messages.length - 1];
|
|
2488
|
-
if (
|
|
3272
|
+
if (isRecord2(last)) {
|
|
2489
3273
|
const content = last["content"];
|
|
2490
3274
|
const text = extractTextFromMessageContent(content);
|
|
2491
3275
|
if (text !== void 0) return text;
|
|
@@ -2499,7 +3283,7 @@ function extractInputFromArgs(args) {
|
|
|
2499
3283
|
return safeJson(args);
|
|
2500
3284
|
}
|
|
2501
3285
|
function coerceMessagesFromArgs(args) {
|
|
2502
|
-
if (!
|
|
3286
|
+
if (!isRecord2(args)) return [];
|
|
2503
3287
|
const result = [];
|
|
2504
3288
|
if (typeof args["system"] === "string" && args["system"]) {
|
|
2505
3289
|
result.push({ role: "system", content: args["system"] });
|
|
@@ -2507,7 +3291,7 @@ function coerceMessagesFromArgs(args) {
|
|
|
2507
3291
|
const messages = messagesFromArgs(args);
|
|
2508
3292
|
if (Array.isArray(messages)) {
|
|
2509
3293
|
for (const message of messages) {
|
|
2510
|
-
if (
|
|
3294
|
+
if (isRecord2(message) && typeof message["role"] === "string") {
|
|
2511
3295
|
result.push(message);
|
|
2512
3296
|
}
|
|
2513
3297
|
}
|
|
@@ -2519,21 +3303,21 @@ function coerceMessagesFromArgs(args) {
|
|
|
2519
3303
|
return result;
|
|
2520
3304
|
}
|
|
2521
3305
|
function extractResponseMessages(result) {
|
|
2522
|
-
if (!
|
|
3306
|
+
if (!isRecord2(result)) return [];
|
|
2523
3307
|
const response = result["response"];
|
|
2524
|
-
if (
|
|
3308
|
+
if (isRecord2(response) && Array.isArray(response["messages"])) {
|
|
2525
3309
|
return response["messages"].filter(
|
|
2526
|
-
(message) =>
|
|
3310
|
+
(message) => isRecord2(message) && typeof message["role"] === "string" && "content" in message
|
|
2527
3311
|
).map((message) => message);
|
|
2528
3312
|
}
|
|
2529
3313
|
const steps = result["steps"];
|
|
2530
3314
|
if (Array.isArray(steps) && steps.length > 0) {
|
|
2531
3315
|
const lastStep = steps[steps.length - 1];
|
|
2532
|
-
if (
|
|
3316
|
+
if (isRecord2(lastStep) && isRecord2(lastStep["response"])) {
|
|
2533
3317
|
const responseMessages = lastStep["response"]["messages"];
|
|
2534
3318
|
if (Array.isArray(responseMessages)) {
|
|
2535
3319
|
return responseMessages.filter(
|
|
2536
|
-
(message) =>
|
|
3320
|
+
(message) => isRecord2(message) && typeof message["role"] === "string" && "content" in message
|
|
2537
3321
|
).map((message) => message);
|
|
2538
3322
|
}
|
|
2539
3323
|
}
|
|
@@ -2554,7 +3338,7 @@ function isTranscriptToolResultError(part, result) {
|
|
|
2554
3338
|
if (part["isError"] === true || part["type"] === "tool-error") {
|
|
2555
3339
|
return true;
|
|
2556
3340
|
}
|
|
2557
|
-
if (
|
|
3341
|
+
if (isRecord2(result) && typeof result["type"] === "string") {
|
|
2558
3342
|
return result["type"].startsWith("error") || result["type"] === "execution-denied";
|
|
2559
3343
|
}
|
|
2560
3344
|
return false;
|
|
@@ -2563,7 +3347,7 @@ function getTranscriptToolErrorMessage(result) {
|
|
|
2563
3347
|
if (typeof result === "string" && result.length > 0) {
|
|
2564
3348
|
return result;
|
|
2565
3349
|
}
|
|
2566
|
-
if (
|
|
3350
|
+
if (isRecord2(result)) {
|
|
2567
3351
|
if (typeof result["value"] === "string" && result["value"].length > 0) {
|
|
2568
3352
|
return result["value"];
|
|
2569
3353
|
}
|
|
@@ -2577,12 +3361,12 @@ function getTranscriptToolErrorMessage(result) {
|
|
|
2577
3361
|
return safeJsonWithUint8(result);
|
|
2578
3362
|
}
|
|
2579
3363
|
function getTranscriptMessageParts(message) {
|
|
2580
|
-
if (!
|
|
3364
|
+
if (!isRecord2(message)) return [];
|
|
2581
3365
|
const content = message["content"];
|
|
2582
3366
|
if (Array.isArray(content)) {
|
|
2583
|
-
return content.filter(
|
|
3367
|
+
return content.filter(isRecord2);
|
|
2584
3368
|
}
|
|
2585
|
-
return
|
|
3369
|
+
return isRecord2(content) ? [content] : [];
|
|
2586
3370
|
}
|
|
2587
3371
|
function getTranscriptToolCallInput(part) {
|
|
2588
3372
|
return "input" in part ? part["input"] : "args" in part ? part["args"] : void 0;
|
|
@@ -2683,7 +3467,7 @@ function extractTextFromLmContent(content) {
|
|
|
2683
3467
|
if (!Array.isArray(content)) return void 0;
|
|
2684
3468
|
let result = "";
|
|
2685
3469
|
for (const part of content) {
|
|
2686
|
-
if (
|
|
3470
|
+
if (isRecord2(part) && part["type"] === "text" && typeof part["text"] === "string") {
|
|
2687
3471
|
result += part["text"];
|
|
2688
3472
|
}
|
|
2689
3473
|
}
|
|
@@ -2693,7 +3477,7 @@ function extractToolCallsFromLmContent(content) {
|
|
|
2693
3477
|
if (!Array.isArray(content)) return void 0;
|
|
2694
3478
|
const calls = [];
|
|
2695
3479
|
for (const part of content) {
|
|
2696
|
-
if (!
|
|
3480
|
+
if (!isRecord2(part) || part["type"] !== "tool-call") continue;
|
|
2697
3481
|
const toolCallId = getTranscriptToolCallId(part);
|
|
2698
3482
|
const toolName = typeof part["toolName"] === "string" ? part["toolName"] : void 0;
|
|
2699
3483
|
if (toolCallId || toolName) {
|
|
@@ -2703,15 +3487,15 @@ function extractToolCallsFromLmContent(content) {
|
|
|
2703
3487
|
return calls.length ? calls : void 0;
|
|
2704
3488
|
}
|
|
2705
3489
|
function extractExperimentalTelemetry(args) {
|
|
2706
|
-
if (!
|
|
3490
|
+
if (!isRecord2(args)) return void 0;
|
|
2707
3491
|
const telemetryConfig = args["experimental_telemetry"];
|
|
2708
|
-
if (!
|
|
3492
|
+
if (!isRecord2(telemetryConfig)) return void 0;
|
|
2709
3493
|
return {
|
|
2710
3494
|
functionId: typeof telemetryConfig["functionId"] === "string" ? telemetryConfig["functionId"] : void 0,
|
|
2711
3495
|
isEnabled: typeof telemetryConfig["isEnabled"] === "boolean" ? telemetryConfig["isEnabled"] : void 0,
|
|
2712
3496
|
recordInputs: typeof telemetryConfig["recordInputs"] === "boolean" ? telemetryConfig["recordInputs"] : void 0,
|
|
2713
3497
|
recordOutputs: typeof telemetryConfig["recordOutputs"] === "boolean" ? telemetryConfig["recordOutputs"] : void 0,
|
|
2714
|
-
metadata:
|
|
3498
|
+
metadata: isRecord2(telemetryConfig["metadata"]) ? telemetryConfig["metadata"] : void 0
|
|
2715
3499
|
};
|
|
2716
3500
|
}
|
|
2717
3501
|
function opName(operationId, functionId) {
|
|
@@ -2739,7 +3523,7 @@ function attrsFromTelemetryMetadata(metadata) {
|
|
|
2739
3523
|
});
|
|
2740
3524
|
}
|
|
2741
3525
|
function attrsFromHeaders(headers) {
|
|
2742
|
-
if (!
|
|
3526
|
+
if (!isRecord2(headers)) return [];
|
|
2743
3527
|
return Object.entries(headers).filter(([, v]) => typeof v === "string").map(([k, v]) => attrString(`ai.request.headers.${k}`, v));
|
|
2744
3528
|
}
|
|
2745
3529
|
function attrsFromModelProvider(provider) {
|
|
@@ -2752,7 +3536,7 @@ function attrsFromModelProvider(provider) {
|
|
|
2752
3536
|
];
|
|
2753
3537
|
}
|
|
2754
3538
|
function attrsFromSettings(args) {
|
|
2755
|
-
if (!
|
|
3539
|
+
if (!isRecord2(args)) return [];
|
|
2756
3540
|
const result = [];
|
|
2757
3541
|
const settingKeys = [
|
|
2758
3542
|
"maxRetries",
|
|
@@ -2780,7 +3564,7 @@ function attrsFromSettings(args) {
|
|
|
2780
3564
|
return result;
|
|
2781
3565
|
}
|
|
2782
3566
|
function attrsFromGenAiRequest(options) {
|
|
2783
|
-
if (!
|
|
3567
|
+
if (!isRecord2(options)) return [];
|
|
2784
3568
|
return [
|
|
2785
3569
|
attrDouble(
|
|
2786
3570
|
"gen_ai.request.frequency_penalty",
|
|
@@ -2810,7 +3594,7 @@ function attrsFromGenAiRequest(options) {
|
|
|
2810
3594
|
];
|
|
2811
3595
|
}
|
|
2812
3596
|
function attrProviderOptions(options) {
|
|
2813
|
-
if (!
|
|
3597
|
+
if (!isRecord2(options) || !isRecord2(options["providerOptions"])) return void 0;
|
|
2814
3598
|
const json = safeJsonWithUint8(options["providerOptions"]);
|
|
2815
3599
|
return json ? attrString("ai.request.providerOptions", json) : void 0;
|
|
2816
3600
|
}
|
|
@@ -2852,10 +3636,10 @@ function readRaindropCallMetadataFromArgs(args) {
|
|
|
2852
3636
|
var _a;
|
|
2853
3637
|
if (args.length === 0) return void 0;
|
|
2854
3638
|
const first = args[0];
|
|
2855
|
-
if (!
|
|
2856
|
-
const topLevel =
|
|
2857
|
-
const stable =
|
|
2858
|
-
const stableMetadata =
|
|
3639
|
+
if (!isRecord2(first)) return void 0;
|
|
3640
|
+
const topLevel = isRecord2(first["metadata"]) ? first["metadata"] : void 0;
|
|
3641
|
+
const stable = isRecord2(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
|
|
3642
|
+
const stableMetadata = isRecord2(stable) ? stable : void 0;
|
|
2859
3643
|
const exp = extractExperimentalTelemetry(first);
|
|
2860
3644
|
const expMetadata = (exp == null ? void 0 : exp.metadata) && typeof exp.metadata === "object" ? exp.metadata : void 0;
|
|
2861
3645
|
const raw = (_a = topLevel != null ? topLevel : stableMetadata) != null ? _a : expMetadata;
|
|
@@ -3295,38 +4079,38 @@ var CACHE_WRITE_METADATA_KEYS = [
|
|
|
3295
4079
|
["bedrock", "cacheWriteInputTokens"]
|
|
3296
4080
|
];
|
|
3297
4081
|
function cacheWriteTokensFromProviderMetadata(providerMetadata) {
|
|
3298
|
-
if (!
|
|
4082
|
+
if (!isRecord2(providerMetadata)) return void 0;
|
|
3299
4083
|
return firstTokenCount(
|
|
3300
4084
|
...CACHE_WRITE_METADATA_KEYS.flatMap(([namespace, key]) => {
|
|
3301
4085
|
const scope = providerMetadata[namespace];
|
|
3302
|
-
if (!
|
|
4086
|
+
if (!isRecord2(scope)) return [];
|
|
3303
4087
|
const usage = scope["usage"];
|
|
3304
|
-
return [scope[key],
|
|
4088
|
+
return [scope[key], isRecord2(usage) ? usage[key] : void 0];
|
|
3305
4089
|
})
|
|
3306
4090
|
);
|
|
3307
4091
|
}
|
|
3308
4092
|
function extractUsageMetricsFromUsage(usage, _provider, providerMetadata) {
|
|
3309
|
-
if (!
|
|
4093
|
+
if (!isRecord2(usage)) return {};
|
|
3310
4094
|
const inputTokenValue = usage["inputTokens"];
|
|
3311
4095
|
const outputTokenValue = usage["outputTokens"];
|
|
3312
4096
|
const inputTokenDetails = usage["inputTokenDetails"];
|
|
3313
4097
|
const outputTokenDetails = usage["outputTokenDetails"];
|
|
3314
|
-
const hasStructuredUsage =
|
|
4098
|
+
const hasStructuredUsage = isRecord2(inputTokenValue) || isRecord2(outputTokenValue) || isRecord2(inputTokenDetails) || isRecord2(outputTokenDetails);
|
|
3315
4099
|
const inputTokens = firstTokenCount(
|
|
3316
|
-
|
|
4100
|
+
isRecord2(inputTokenValue) ? inputTokenValue["total"] : void 0,
|
|
3317
4101
|
inputTokenValue,
|
|
3318
4102
|
usage["promptTokens"],
|
|
3319
4103
|
usage["prompt_tokens"]
|
|
3320
4104
|
);
|
|
3321
4105
|
const outputTokens = firstTokenCount(
|
|
3322
|
-
|
|
4106
|
+
isRecord2(outputTokenValue) ? outputTokenValue["total"] : void 0,
|
|
3323
4107
|
outputTokenValue,
|
|
3324
4108
|
usage["completionTokens"],
|
|
3325
4109
|
usage["completion_tokens"]
|
|
3326
4110
|
);
|
|
3327
4111
|
const reasoningTokens = firstTokenCount(
|
|
3328
|
-
|
|
3329
|
-
|
|
4112
|
+
isRecord2(outputTokenValue) ? outputTokenValue["reasoning"] : void 0,
|
|
4113
|
+
isRecord2(outputTokenDetails) ? outputTokenDetails["reasoningTokens"] : void 0,
|
|
3330
4114
|
usage["reasoningTokens"],
|
|
3331
4115
|
usage["completionReasoningTokens"],
|
|
3332
4116
|
usage["completion_reasoning_tokens"],
|
|
@@ -3335,27 +4119,27 @@ function extractUsageMetricsFromUsage(usage, _provider, providerMetadata) {
|
|
|
3335
4119
|
usage["thinking_tokens"]
|
|
3336
4120
|
);
|
|
3337
4121
|
const cacheReadInputTokens = firstTokenCount(
|
|
3338
|
-
|
|
3339
|
-
|
|
4122
|
+
isRecord2(inputTokenValue) ? inputTokenValue["cacheRead"] : void 0,
|
|
4123
|
+
isRecord2(inputTokenDetails) ? inputTokenDetails["cacheReadTokens"] : void 0,
|
|
3340
4124
|
usage["cachedInputTokens"],
|
|
3341
4125
|
usage["promptCachedTokens"],
|
|
3342
4126
|
usage["prompt_cached_tokens"]
|
|
3343
4127
|
);
|
|
3344
4128
|
const cacheWriteInputTokens = firstTokenCount(
|
|
3345
|
-
|
|
3346
|
-
|
|
4129
|
+
isRecord2(inputTokenValue) ? inputTokenValue["cacheWrite"] : void 0,
|
|
4130
|
+
isRecord2(inputTokenDetails) ? inputTokenDetails["cacheWriteTokens"] : void 0,
|
|
3347
4131
|
usage["cacheWriteInputTokens"],
|
|
3348
4132
|
usage["cacheCreationInputTokens"],
|
|
3349
4133
|
usage["cache_creation_input_tokens"],
|
|
3350
4134
|
cacheWriteTokensFromProviderMetadata(providerMetadata)
|
|
3351
4135
|
);
|
|
3352
4136
|
const nonCachedInputTokens = firstTokenCount(
|
|
3353
|
-
|
|
3354
|
-
|
|
4137
|
+
isRecord2(inputTokenValue) ? inputTokenValue["noCache"] : void 0,
|
|
4138
|
+
isRecord2(inputTokenDetails) ? inputTokenDetails["noCacheTokens"] : void 0
|
|
3355
4139
|
);
|
|
3356
4140
|
const nonReasoningOutputTokens = firstTokenCount(
|
|
3357
|
-
|
|
3358
|
-
|
|
4141
|
+
isRecord2(outputTokenValue) ? outputTokenValue["text"] : void 0,
|
|
4142
|
+
isRecord2(outputTokenDetails) ? outputTokenDetails["textTokens"] : void 0
|
|
3359
4143
|
);
|
|
3360
4144
|
const totalTokens = firstTokenCount(
|
|
3361
4145
|
usage["totalTokens"],
|
|
@@ -3581,17 +4365,10 @@ var RaindropTelemetryIntegration = class {
|
|
|
3581
4365
|
if (event.promptMessages) {
|
|
3582
4366
|
inputAttrs.push(attrString("ai.prompt.messages", safeJsonWithUint8(event.promptMessages)));
|
|
3583
4367
|
}
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
event.stepTools.map((t) => {
|
|
3589
|
-
var _a;
|
|
3590
|
-
return (_a = safeJsonWithUint8(t)) != null ? _a : "";
|
|
3591
|
-
})
|
|
3592
|
-
)
|
|
3593
|
-
);
|
|
3594
|
-
}
|
|
4368
|
+
const promptTools = promptToolsAttribute(
|
|
4369
|
+
resolvePromptTools({ override: this.promptTools, inferred: event.stepTools })
|
|
4370
|
+
);
|
|
4371
|
+
if (promptTools) inputAttrs.push(promptTools);
|
|
3595
4372
|
if (event.stepToolChoice != null) {
|
|
3596
4373
|
inputAttrs.push(
|
|
3597
4374
|
attrString("ai.prompt.toolChoice", safeJsonWithUint8(event.stepToolChoice))
|
|
@@ -3939,6 +4716,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
3939
4716
|
this.subagentWrapping = opts.subagentWrapping !== false;
|
|
3940
4717
|
this.debug = opts.debug === true;
|
|
3941
4718
|
this.defaultContext = opts.context;
|
|
4719
|
+
this.promptTools = opts.tools;
|
|
3942
4720
|
this.subagents = new SubagentApi({
|
|
3943
4721
|
traceShipper: this.traceShipper,
|
|
3944
4722
|
eventShipper: this.eventShipper,
|
|
@@ -4564,7 +5342,7 @@ function createStandaloneSelfDiagnosticsTool(args) {
|
|
|
4564
5342
|
}
|
|
4565
5343
|
|
|
4566
5344
|
// src/internal/traces.ts
|
|
4567
|
-
var
|
|
5345
|
+
var TraceShipper3 = class extends TraceShipper2 {
|
|
4568
5346
|
constructor(opts) {
|
|
4569
5347
|
var _a, _b, _c;
|
|
4570
5348
|
super({
|
|
@@ -4577,6 +5355,18 @@ var TraceShipper2 = class extends TraceShipper {
|
|
|
4577
5355
|
};
|
|
4578
5356
|
|
|
4579
5357
|
// src/internal/wrap/wrapAISDK.ts
|
|
5358
|
+
function promptToolsOptionsFrom(aiSDK) {
|
|
5359
|
+
if (!isRecord2(aiSDK)) return void 0;
|
|
5360
|
+
const asSchema = aiSDK["asSchema"];
|
|
5361
|
+
if (!isFunction(asSchema)) return void 0;
|
|
5362
|
+
return {
|
|
5363
|
+
schema: (schema) => {
|
|
5364
|
+
const converted = asSchema(schema);
|
|
5365
|
+
const json = isRecord2(converted) ? converted["jsonSchema"] : void 0;
|
|
5366
|
+
return isRecord2(json) ? json : void 0;
|
|
5367
|
+
}
|
|
5368
|
+
};
|
|
5369
|
+
}
|
|
4580
5370
|
var pendingStoresByShipper = /* @__PURE__ */ new WeakMap();
|
|
4581
5371
|
var PendingToolSpanStore = class _PendingToolSpanStore {
|
|
4582
5372
|
constructor() {
|
|
@@ -4633,9 +5423,9 @@ function _resetWarnedMissingUserId() {
|
|
|
4633
5423
|
warnedMissingUserId = false;
|
|
4634
5424
|
}
|
|
4635
5425
|
function extractRaindropCallOptions(options) {
|
|
4636
|
-
if (!
|
|
5426
|
+
if (!isRecord2(options)) return {};
|
|
4637
5427
|
const em = options["metadata"];
|
|
4638
|
-
if (
|
|
5428
|
+
if (isRecord2(em)) return extractRaindropMetadata(em);
|
|
4639
5429
|
const telemetry = extractExperimentalTelemetry(options);
|
|
4640
5430
|
if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
|
|
4641
5431
|
return {};
|
|
@@ -4697,20 +5487,20 @@ function mergeContexts(wrapTime, callTime) {
|
|
|
4697
5487
|
return result;
|
|
4698
5488
|
}
|
|
4699
5489
|
function detectAISDKVersion(aiSDK) {
|
|
4700
|
-
if (!
|
|
5490
|
+
if (!isRecord2(aiSDK)) return "unknown";
|
|
4701
5491
|
if (isFunction(aiSDK["jsonSchema"])) return "6";
|
|
4702
5492
|
if (isFunction(aiSDK["tool"])) return "5";
|
|
4703
5493
|
return "4";
|
|
4704
5494
|
}
|
|
4705
5495
|
function hasStructuredTelemetryEvents(aiSDK) {
|
|
4706
|
-
if (!
|
|
5496
|
+
if (!isRecord2(aiSDK)) return false;
|
|
4707
5497
|
const hasRegister = isFunction(aiSDK["registerTelemetry"]) || isFunction(aiSDK["registerTelemetryIntegration"]);
|
|
4708
5498
|
const hasV7Marker = isFunction(aiSDK["experimental_streamLanguageModelCall"]) || isFunction(aiSDK["experimental_streamModelCall"]);
|
|
4709
5499
|
return hasRegister && hasV7Marker;
|
|
4710
5500
|
}
|
|
4711
5501
|
function resolveRegisterTelemetry(aiSDK) {
|
|
4712
5502
|
var _a;
|
|
4713
|
-
if (!
|
|
5503
|
+
if (!isRecord2(aiSDK)) return void 0;
|
|
4714
5504
|
const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
|
|
4715
5505
|
return isFunction(fn) ? fn : void 0;
|
|
4716
5506
|
}
|
|
@@ -4741,18 +5531,18 @@ function isAsyncIterable(value) {
|
|
|
4741
5531
|
return value !== null && typeof value === "object" && Symbol.asyncIterator in value;
|
|
4742
5532
|
}
|
|
4743
5533
|
function resolveUsageRecord(result) {
|
|
4744
|
-
if (!
|
|
5534
|
+
if (!isRecord2(result)) return void 0;
|
|
4745
5535
|
let usage;
|
|
4746
5536
|
try {
|
|
4747
|
-
if (
|
|
5537
|
+
if (isRecord2(result["totalUsage"])) {
|
|
4748
5538
|
usage = result["totalUsage"];
|
|
4749
|
-
} else if (
|
|
5539
|
+
} else if (isRecord2(result["usage"])) {
|
|
4750
5540
|
usage = result["usage"];
|
|
4751
5541
|
}
|
|
4752
5542
|
} catch (e) {
|
|
4753
5543
|
return void 0;
|
|
4754
5544
|
}
|
|
4755
|
-
return
|
|
5545
|
+
return isRecord2(usage) ? usage : void 0;
|
|
4756
5546
|
}
|
|
4757
5547
|
function extractUsageMetrics(result) {
|
|
4758
5548
|
return extractUsageMetricsFromUsage(resolveUsageRecord(result));
|
|
@@ -4773,7 +5563,7 @@ function shouldKeepEventPending(params) {
|
|
|
4773
5563
|
}
|
|
4774
5564
|
function normalizePromptAttr(arg) {
|
|
4775
5565
|
var _a, _b;
|
|
4776
|
-
if (!
|
|
5566
|
+
if (!isRecord2(arg)) return arg;
|
|
4777
5567
|
const system = arg["system"];
|
|
4778
5568
|
const prompt = arg["prompt"];
|
|
4779
5569
|
const messages = arg["messages"];
|
|
@@ -4827,7 +5617,7 @@ async function runWithRootContextAsync(rootSpan, eventId, fn) {
|
|
|
4827
5617
|
);
|
|
4828
5618
|
}
|
|
4829
5619
|
function teeStreamObjectBaseStream(result) {
|
|
4830
|
-
if (!result || !
|
|
5620
|
+
if (!result || !isRecord2(result)) return;
|
|
4831
5621
|
const baseStream = result["baseStream"];
|
|
4832
5622
|
if (!(baseStream && typeof baseStream === "object" && "tee" in baseStream)) return;
|
|
4833
5623
|
try {
|
|
@@ -4868,7 +5658,7 @@ function setupOperation(params) {
|
|
|
4868
5658
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
4869
5659
|
const outerOperationId = `ai.${operation}`;
|
|
4870
5660
|
const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
|
|
4871
|
-
const modelInfoFromArgs =
|
|
5661
|
+
const modelInfoFromArgs = isRecord2(arg) ? extractModelInfo(arg["model"]) : {};
|
|
4872
5662
|
const rootSpan = sendTraces ? traceShipper.startSpan({
|
|
4873
5663
|
name: outerOperationId,
|
|
4874
5664
|
parent: inheritedParent,
|
|
@@ -4883,7 +5673,7 @@ function setupOperation(params) {
|
|
|
4883
5673
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
4884
5674
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
4885
5675
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
4886
|
-
...attrsFromHeaders(
|
|
5676
|
+
...attrsFromHeaders(isRecord2(arg) ? arg["headers"] : void 0),
|
|
4887
5677
|
...attrsFromSettings(arg),
|
|
4888
5678
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [attrString("ai.prompt", safeJsonWithUint8(normalizePromptAttr(arg)))]
|
|
4889
5679
|
]
|
|
@@ -4900,7 +5690,9 @@ function setupOperation(params) {
|
|
|
4900
5690
|
traceShipper,
|
|
4901
5691
|
rootParentForChildren,
|
|
4902
5692
|
selfDiagnostics: operationSelfDiagnostics,
|
|
4903
|
-
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
5693
|
+
aiSDKVersion: detectAISDKVersion(aiSDK),
|
|
5694
|
+
promptTools: options.tools,
|
|
5695
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
4904
5696
|
};
|
|
4905
5697
|
const toolCalls = [];
|
|
4906
5698
|
const argsWithWrappedTools = wrapTools(arg, wrapCtx, toolCalls);
|
|
@@ -4973,8 +5765,8 @@ function createFinalize(params) {
|
|
|
4973
5765
|
endTimeUnixNano: spanEndTimeUnixNano,
|
|
4974
5766
|
keepEventPending
|
|
4975
5767
|
});
|
|
4976
|
-
const providerMetadata =
|
|
4977
|
-
const resultToolCalls =
|
|
5768
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
5769
|
+
const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : setup.toolCalls.length ? safeJsonWithUint8(setup.toolCalls) : void 0;
|
|
4978
5770
|
traceShipper.endSpan(setup.rootSpan, {
|
|
4979
5771
|
attributes: [
|
|
4980
5772
|
...((_d = setup.telemetry) == null ? void 0 : _d.recordOutputs) === false ? [] : [
|
|
@@ -5246,6 +6038,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
5246
6038
|
sendEvents: ((_b = deps.options.send) == null ? void 0 : _b.events) !== false,
|
|
5247
6039
|
debug,
|
|
5248
6040
|
settledEventIds: deps.settledEventIds,
|
|
6041
|
+
tools: deps.options.tools,
|
|
5249
6042
|
context: {
|
|
5250
6043
|
userId: wrapTimeCtx.userId,
|
|
5251
6044
|
eventId: wrapTimeCtx.eventId,
|
|
@@ -5288,7 +6081,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
5288
6081
|
const arg = callArgs[0];
|
|
5289
6082
|
const callMetadata = readRaindropCallMetadataFromArgs(callArgs);
|
|
5290
6083
|
const callOriginal = () => original.call(aiSDK, ...callArgs);
|
|
5291
|
-
if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) &&
|
|
6084
|
+
if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord2(arg)) {
|
|
5292
6085
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
5293
6086
|
const callMeta = (telemetry == null ? void 0 : telemetry.metadata) ? extractRaindropMetadata(telemetry.metadata) : {};
|
|
5294
6087
|
const perCallEventIdExplicit = (_b2 = (_a2 = callMetadata == null ? void 0 : callMetadata.eventId) != null ? _a2 : callMeta.eventId) != null ? _b2 : wrapTimeCtx.eventId;
|
|
@@ -5300,16 +6093,18 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
5300
6093
|
eventShipper: deps.eventShipper,
|
|
5301
6094
|
traceShipper: deps.traceShipper,
|
|
5302
6095
|
selfDiagnostics: selfDiagnostics2,
|
|
5303
|
-
aiSDKVersion: "7"
|
|
6096
|
+
aiSDKVersion: "7",
|
|
6097
|
+
promptTools: deps.options.tools,
|
|
6098
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
5304
6099
|
};
|
|
5305
|
-
const tools =
|
|
6100
|
+
const tools = isRecord2(arg["tools"]) ? { ...arg["tools"] } : {};
|
|
5306
6101
|
const toolName = selfDiagnostics2.toolName;
|
|
5307
6102
|
if (!(toolName in tools)) {
|
|
5308
6103
|
const reportTool = createSelfDiagnosticsTool(perCallCtx);
|
|
5309
6104
|
if (reportTool) tools[toolName] = reportTool;
|
|
5310
6105
|
}
|
|
5311
|
-
const existingTelemetry =
|
|
5312
|
-
const existingMetadata =
|
|
6106
|
+
const existingTelemetry = isRecord2(arg["experimental_telemetry"]) ? arg["experimental_telemetry"] : {};
|
|
6107
|
+
const existingMetadata = isRecord2(existingTelemetry["metadata"]) ? existingTelemetry["metadata"] : {};
|
|
5313
6108
|
const mergedMetadata = existingMetadata["raindrop.eventId"] ? existingMetadata : {
|
|
5314
6109
|
...existingMetadata,
|
|
5315
6110
|
"raindrop.eventId": perCallEventId,
|
|
@@ -5505,7 +6300,9 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
5505
6300
|
traceShipper: deps.traceShipper,
|
|
5506
6301
|
rootParentForChildren,
|
|
5507
6302
|
selfDiagnostics,
|
|
5508
|
-
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
6303
|
+
aiSDKVersion: detectAISDKVersion(aiSDK),
|
|
6304
|
+
promptTools: deps.options.tools,
|
|
6305
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
5509
6306
|
};
|
|
5510
6307
|
const toolCalls = [];
|
|
5511
6308
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -5555,8 +6352,8 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
5555
6352
|
keepEventPending: false
|
|
5556
6353
|
});
|
|
5557
6354
|
const finishReason = extractFinishReason(result);
|
|
5558
|
-
const providerMetadata =
|
|
5559
|
-
const resultToolCalls =
|
|
6355
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
6356
|
+
const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
|
|
5560
6357
|
deps.traceShipper.endSpan(rootSpan, {
|
|
5561
6358
|
attributes: [
|
|
5562
6359
|
...(telemetry == null ? void 0 : telemetry.recordOutputs) === false ? [] : [
|
|
@@ -5725,7 +6522,9 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
5725
6522
|
traceShipper: deps.traceShipper,
|
|
5726
6523
|
rootParentForChildren,
|
|
5727
6524
|
selfDiagnostics,
|
|
5728
|
-
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
6525
|
+
aiSDKVersion: detectAISDKVersion(aiSDK),
|
|
6526
|
+
promptTools: deps.options.tools,
|
|
6527
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
5729
6528
|
};
|
|
5730
6529
|
const toolCalls = [];
|
|
5731
6530
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -5775,8 +6574,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
5775
6574
|
keepEventPending: false
|
|
5776
6575
|
});
|
|
5777
6576
|
const finishReason = extractFinishReason(result);
|
|
5778
|
-
const providerMetadata =
|
|
5779
|
-
const resultToolCalls =
|
|
6577
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
6578
|
+
const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
|
|
5780
6579
|
deps.traceShipper.endSpan(rootSpan, {
|
|
5781
6580
|
attributes: [
|
|
5782
6581
|
...(telemetry == null ? void 0 : telemetry.recordOutputs) === false ? [] : [
|
|
@@ -5888,8 +6687,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
5888
6687
|
};
|
|
5889
6688
|
}
|
|
5890
6689
|
function wrapTools(args, ctx, toolCalls) {
|
|
5891
|
-
if (!
|
|
5892
|
-
const tools =
|
|
6690
|
+
if (!isRecord2(args)) return args;
|
|
6691
|
+
const tools = isRecord2(args["tools"]) ? { ...args["tools"] } : {};
|
|
5893
6692
|
if (ctx.selfDiagnostics) {
|
|
5894
6693
|
const reportToolName = ctx.selfDiagnostics.toolName;
|
|
5895
6694
|
if (!(reportToolName in tools)) {
|
|
@@ -5912,7 +6711,7 @@ function wrapTools(args, ctx, toolCalls) {
|
|
|
5912
6711
|
}
|
|
5913
6712
|
function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
5914
6713
|
var _a;
|
|
5915
|
-
if (!
|
|
6714
|
+
if (!isRecord2(tool) || !isFunction(tool["execute"])) return tool;
|
|
5916
6715
|
const originalExecute = tool["execute"];
|
|
5917
6716
|
const { operationName, resourceName } = opName("ai.toolCall", (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
|
|
5918
6717
|
const createToolSpan = (toolCallId, toolArgs, parent) => {
|
|
@@ -5973,7 +6772,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
5973
6772
|
const wrappedExecute = function(...execArgs) {
|
|
5974
6773
|
const toolArgs = execArgs[0];
|
|
5975
6774
|
const execOptions = execArgs.length > 1 ? execArgs[1] : void 0;
|
|
5976
|
-
const toolCallId =
|
|
6775
|
+
const toolCallId = isRecord2(execOptions) && typeof execOptions["toolCallId"] === "string" ? execOptions["toolCallId"] : randomUUID();
|
|
5977
6776
|
const result = originalExecute.apply(this, execArgs);
|
|
5978
6777
|
if (isAsyncIterable(result)) {
|
|
5979
6778
|
return (async function* () {
|
|
@@ -6048,20 +6847,20 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
6048
6847
|
return { ...tool, execute: wrappedExecute };
|
|
6049
6848
|
}
|
|
6050
6849
|
function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
6051
|
-
if (!
|
|
6850
|
+
if (!isRecord2(args) || !("model" in args)) return args;
|
|
6052
6851
|
let model = args["model"];
|
|
6053
6852
|
if (typeof model === "string") {
|
|
6054
6853
|
const maybeProvider = globalThis.AI_SDK_DEFAULT_PROVIDER;
|
|
6055
|
-
const gateway =
|
|
6854
|
+
const gateway = isRecord2(aiSDK) ? aiSDK["gateway"] : void 0;
|
|
6056
6855
|
const provider = maybeProvider != null ? maybeProvider : gateway;
|
|
6057
|
-
if (
|
|
6856
|
+
if (isRecord2(provider) && isFunction(provider["languageModel"])) {
|
|
6058
6857
|
try {
|
|
6059
6858
|
model = provider["languageModel"](model);
|
|
6060
6859
|
} catch (e) {
|
|
6061
6860
|
}
|
|
6062
6861
|
}
|
|
6063
6862
|
}
|
|
6064
|
-
if (!
|
|
6863
|
+
if (!isRecord2(model)) return args;
|
|
6065
6864
|
const modelInfo = extractModelInfo(model);
|
|
6066
6865
|
const doGenerateOpId = `${outerOperationId}.doGenerate`;
|
|
6067
6866
|
const doStreamOpId = `${outerOperationId}.doStream`;
|
|
@@ -6078,13 +6877,13 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6078
6877
|
try {
|
|
6079
6878
|
const result = await original.apply(target, callArgs);
|
|
6080
6879
|
if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
|
|
6081
|
-
if (localDebuggerEnabled() && ctx.rootParentForChildren &&
|
|
6880
|
+
if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord2(result)) {
|
|
6082
6881
|
const traceId = ctx.rootParentForChildren.traceIdB64;
|
|
6083
6882
|
const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
|
|
6084
6883
|
const content = result["content"];
|
|
6085
6884
|
if (Array.isArray(content)) {
|
|
6086
6885
|
for (const part of content) {
|
|
6087
|
-
if (
|
|
6886
|
+
if (isRecord2(part)) {
|
|
6088
6887
|
if ((part["type"] === "reasoning" || part["type"] === "thinking") && typeof ((_a = part["text"]) != null ? _a : part["thinking"]) === "string") {
|
|
6089
6888
|
sendLocalDebuggerLiveEvent({
|
|
6090
6889
|
traceId,
|
|
@@ -6153,7 +6952,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6153
6952
|
});
|
|
6154
6953
|
throw error;
|
|
6155
6954
|
}
|
|
6156
|
-
const stream =
|
|
6955
|
+
const stream = isRecord2(result) ? result["stream"] : void 0;
|
|
6157
6956
|
const RS = globalThis.ReadableStream;
|
|
6158
6957
|
if (!RS || !(stream instanceof RS)) {
|
|
6159
6958
|
if (span) ctx.traceShipper.endSpan(span);
|
|
@@ -6226,7 +7025,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6226
7025
|
return;
|
|
6227
7026
|
}
|
|
6228
7027
|
if (firstChunkMs === void 0) firstChunkMs = Date.now();
|
|
6229
|
-
if (
|
|
7028
|
+
if (isRecord2(value)) {
|
|
6230
7029
|
const type = value["type"];
|
|
6231
7030
|
if (type === "text-delta") {
|
|
6232
7031
|
let textDelta;
|
|
@@ -6241,7 +7040,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6241
7040
|
}
|
|
6242
7041
|
if (type === "finish") finishReason = extractFinishReason(value);
|
|
6243
7042
|
if (type === "tool-call") toolCallsLocal.push(value);
|
|
6244
|
-
if ("response" in value &&
|
|
7043
|
+
if ("response" in value && isRecord2(value["response"])) {
|
|
6245
7044
|
const response = value["response"];
|
|
6246
7045
|
if (typeof response["id"] === "string") responseId = response["id"];
|
|
6247
7046
|
if (typeof response["modelId"] === "string")
|
|
@@ -6318,10 +7117,15 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6318
7117
|
function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
6319
7118
|
var _a, _b, _c;
|
|
6320
7119
|
const { operationName, resourceName } = opName(operationId, (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
|
|
6321
|
-
const
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
7120
|
+
const promptTools = promptToolsAttribute(
|
|
7121
|
+
resolvePromptTools({
|
|
7122
|
+
override: ctx.promptTools,
|
|
7123
|
+
inferred: isRecord2(options) ? options["tools"] : void 0,
|
|
7124
|
+
options: ctx.promptToolsOptions
|
|
7125
|
+
})
|
|
7126
|
+
);
|
|
7127
|
+
const toolChoiceJson = isRecord2(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
|
|
7128
|
+
const promptJson = isRecord2(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
|
|
6325
7129
|
return ctx.traceShipper.startSpan({
|
|
6326
7130
|
name: operationId,
|
|
6327
7131
|
parent,
|
|
@@ -6336,7 +7140,7 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
6336
7140
|
attrString("ai.model.id", modelInfo.modelId),
|
|
6337
7141
|
...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
|
|
6338
7142
|
attrString("ai.prompt.messages", promptJson),
|
|
6339
|
-
|
|
7143
|
+
promptTools,
|
|
6340
7144
|
attrString("ai.prompt.toolChoice", toolChoiceJson)
|
|
6341
7145
|
],
|
|
6342
7146
|
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, modelInfo.modelId),
|
|
@@ -6348,26 +7152,26 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
6348
7152
|
function endDoGenerateSpan(span, result, modelInfo, ctx) {
|
|
6349
7153
|
var _a;
|
|
6350
7154
|
const finishReason = extractFinishReason(result);
|
|
6351
|
-
const content =
|
|
6352
|
-
const response =
|
|
6353
|
-
const usage =
|
|
6354
|
-
const providerMetadata =
|
|
7155
|
+
const content = isRecord2(result) ? result["content"] : void 0;
|
|
7156
|
+
const response = isRecord2(result) ? result["response"] : void 0;
|
|
7157
|
+
const usage = isRecord2(result) ? result["usage"] : void 0;
|
|
7158
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
6355
7159
|
let responseId;
|
|
6356
|
-
if (
|
|
7160
|
+
if (isRecord2(response) && typeof response["id"] === "string") {
|
|
6357
7161
|
responseId = response["id"];
|
|
6358
7162
|
} else {
|
|
6359
7163
|
responseId = randomUUID();
|
|
6360
7164
|
}
|
|
6361
7165
|
let responseModelId;
|
|
6362
|
-
if (
|
|
7166
|
+
if (isRecord2(response) && typeof response["modelId"] === "string") {
|
|
6363
7167
|
responseModelId = response["modelId"];
|
|
6364
7168
|
} else {
|
|
6365
7169
|
responseModelId = modelInfo.modelId;
|
|
6366
7170
|
}
|
|
6367
7171
|
let responseTimestampIso;
|
|
6368
|
-
if (
|
|
7172
|
+
if (isRecord2(response) && response["timestamp"] instanceof Date) {
|
|
6369
7173
|
responseTimestampIso = response["timestamp"].toISOString();
|
|
6370
|
-
} else if (
|
|
7174
|
+
} else if (isRecord2(response) && typeof response["timestamp"] === "string") {
|
|
6371
7175
|
responseTimestampIso = response["timestamp"];
|
|
6372
7176
|
} else {
|
|
6373
7177
|
responseTimestampIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -6401,10 +7205,15 @@ function endDoGenerateSpan(span, result, modelInfo, ctx) {
|
|
|
6401
7205
|
function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
6402
7206
|
var _a, _b, _c;
|
|
6403
7207
|
const { operationName, resourceName } = opName(operationId, (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
|
|
6404
|
-
const
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
7208
|
+
const promptTools = promptToolsAttribute(
|
|
7209
|
+
resolvePromptTools({
|
|
7210
|
+
override: ctx.promptTools,
|
|
7211
|
+
inferred: isRecord2(options) ? options["tools"] : void 0,
|
|
7212
|
+
options: ctx.promptToolsOptions
|
|
7213
|
+
})
|
|
7214
|
+
);
|
|
7215
|
+
const toolChoiceJson = isRecord2(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
|
|
7216
|
+
const promptJson = isRecord2(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
|
|
6408
7217
|
return ctx.traceShipper.startSpan({
|
|
6409
7218
|
name: operationId,
|
|
6410
7219
|
parent,
|
|
@@ -6419,7 +7228,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
6419
7228
|
attrString("ai.model.id", modelInfo.modelId),
|
|
6420
7229
|
...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
|
|
6421
7230
|
attrString("ai.prompt.messages", promptJson),
|
|
6422
|
-
|
|
7231
|
+
promptTools,
|
|
6423
7232
|
attrString("ai.prompt.toolChoice", toolChoiceJson)
|
|
6424
7233
|
],
|
|
6425
7234
|
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, modelInfo.modelId),
|
|
@@ -6433,7 +7242,7 @@ function resolveContext(context, info) {
|
|
|
6433
7242
|
return typeof context === "function" ? context(info) : context;
|
|
6434
7243
|
}
|
|
6435
7244
|
function wrapOnFinish(args, onFinish) {
|
|
6436
|
-
if (!
|
|
7245
|
+
if (!isRecord2(args)) return args;
|
|
6437
7246
|
const existing = args["onFinish"];
|
|
6438
7247
|
if (existing === void 0) {
|
|
6439
7248
|
return { ...args, onFinish: async (result) => onFinish(result) };
|
|
@@ -6543,11 +7352,11 @@ function userAttrsToOtlp(attrs) {
|
|
|
6543
7352
|
function envDebugEnabled() {
|
|
6544
7353
|
var _a;
|
|
6545
7354
|
if (typeof process === "undefined") return false;
|
|
6546
|
-
const
|
|
6547
|
-
return
|
|
7355
|
+
const flag2 = (_a = process.env) == null ? void 0 : _a.RAINDROP_AI_DEBUG;
|
|
7356
|
+
return flag2 === "1" || flag2 === "true";
|
|
6548
7357
|
}
|
|
6549
7358
|
function createRaindropAISDK(opts) {
|
|
6550
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
7359
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6551
7360
|
const writeKey = opts.writeKey;
|
|
6552
7361
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
6553
7362
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
@@ -6556,37 +7365,53 @@ function createRaindropAISDK(opts) {
|
|
|
6556
7365
|
const localWorkshopInput = opts.localWorkshopUrl === false ? null : opts.localWorkshopUrl;
|
|
6557
7366
|
const resolvedLocalDebuggerUrl = resolveLocalDebuggerBaseUrl(localWorkshopInput);
|
|
6558
7367
|
const localDebuggerUrl = localWorkshopInput === null ? null : resolvedLocalDebuggerUrl != null ? resolvedLocalDebuggerUrl : void 0;
|
|
6559
|
-
const
|
|
6560
|
-
const eventsEnabled = eventsRequested &&
|
|
6561
|
-
const tracesEnabled = tracesRequested &&
|
|
6562
|
-
|
|
7368
|
+
const hasDestination2 = Boolean(writeKey == null ? void 0 : writeKey.trim()) || Boolean(resolvedLocalDebuggerUrl);
|
|
7369
|
+
const eventsEnabled = eventsRequested && hasDestination2;
|
|
7370
|
+
const tracesEnabled = tracesRequested && hasDestination2;
|
|
7371
|
+
const appGitContext = (_c = opts.appGitContext) != null ? _c : createAppGitContext2(
|
|
7372
|
+
eventsEnabled || tracesEnabled ? opts.appGit : false,
|
|
7373
|
+
{ allowLocalGit: true }
|
|
7374
|
+
);
|
|
7375
|
+
if (!hasDestination2 && (eventsRequested || tracesRequested)) {
|
|
6563
7376
|
console.warn(
|
|
6564
7377
|
"[raindrop-ai/ai-sdk] writeKey not provided and no local Workshop reachable; telemetry shipping is disabled"
|
|
6565
7378
|
);
|
|
6566
7379
|
}
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
7380
|
+
let eventShipper;
|
|
7381
|
+
let traceShipper;
|
|
7382
|
+
try {
|
|
7383
|
+
eventShipper = new EventShipper3({
|
|
7384
|
+
writeKey,
|
|
7385
|
+
endpoint: opts.endpoint,
|
|
7386
|
+
enabled: eventsEnabled,
|
|
7387
|
+
debug: ((_d = opts.events) == null ? void 0 : _d.debug) === true || envDebug,
|
|
7388
|
+
partialFlushMs: (_e = opts.events) == null ? void 0 : _e.partialFlushMs,
|
|
7389
|
+
projectId: opts.projectId,
|
|
7390
|
+
localDebuggerUrl,
|
|
7391
|
+
appGitContext
|
|
7392
|
+
});
|
|
7393
|
+
traceShipper = new TraceShipper3({
|
|
7394
|
+
writeKey,
|
|
7395
|
+
endpoint: opts.endpoint,
|
|
7396
|
+
enabled: tracesEnabled,
|
|
7397
|
+
debug: ((_f = opts.traces) == null ? void 0 : _f.debug) === true || envDebug,
|
|
7398
|
+
debugSpans: ((_g = opts.traces) == null ? void 0 : _g.debugSpans) === true || envDebug,
|
|
7399
|
+
flushIntervalMs: (_h = opts.traces) == null ? void 0 : _h.flushIntervalMs,
|
|
7400
|
+
maxBatchSize: (_i = opts.traces) == null ? void 0 : _i.maxBatchSize,
|
|
7401
|
+
maxQueueSize: (_j = opts.traces) == null ? void 0 : _j.maxQueueSize,
|
|
7402
|
+
projectId: opts.projectId,
|
|
7403
|
+
localDebuggerUrl,
|
|
7404
|
+
transformSpan: (_k = opts.traces) == null ? void 0 : _k.transformSpan,
|
|
7405
|
+
disableDefaultRedaction: (_l = opts.traces) == null ? void 0 : _l.disableDefaultRedaction,
|
|
7406
|
+
appGitContext
|
|
7407
|
+
});
|
|
7408
|
+
} catch (error) {
|
|
7409
|
+
try {
|
|
7410
|
+
appGitContext.dispose();
|
|
7411
|
+
} catch (e) {
|
|
7412
|
+
}
|
|
7413
|
+
throw error;
|
|
7414
|
+
}
|
|
6590
7415
|
const settledEventIds = /* @__PURE__ */ new Set();
|
|
6591
7416
|
const subagentApi = new SubagentApi({
|
|
6592
7417
|
traceShipper,
|
|
@@ -6624,11 +7449,16 @@ function createRaindropAISDK(opts) {
|
|
|
6624
7449
|
];
|
|
6625
7450
|
let context;
|
|
6626
7451
|
let subagentWrapping;
|
|
7452
|
+
let tools;
|
|
6627
7453
|
if (contextOrOptions === void 0) ; else if ("context" in contextOrOptions) {
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
7454
|
+
const shaped = contextOrOptions;
|
|
7455
|
+
context = shaped.context;
|
|
7456
|
+
subagentWrapping = shaped.subagentWrapping;
|
|
7457
|
+
tools = shaped.tools;
|
|
7458
|
+
} else if (("subagentWrapping" in contextOrOptions || "tools" in contextOrOptions) && !FLAT_CONTEXT_KEYS.some((k) => k in contextOrOptions)) {
|
|
7459
|
+
const shaped = contextOrOptions;
|
|
7460
|
+
subagentWrapping = shaped.subagentWrapping;
|
|
7461
|
+
tools = shaped.tools;
|
|
6632
7462
|
} else {
|
|
6633
7463
|
context = contextOrOptions;
|
|
6634
7464
|
}
|
|
@@ -6640,7 +7470,8 @@ function createRaindropAISDK(opts) {
|
|
|
6640
7470
|
subagentWrapping,
|
|
6641
7471
|
debug: envDebug,
|
|
6642
7472
|
settledEventIds,
|
|
6643
|
-
context
|
|
7473
|
+
context,
|
|
7474
|
+
tools
|
|
6644
7475
|
});
|
|
6645
7476
|
},
|
|
6646
7477
|
subagents: subagentApi,
|
|
@@ -6754,16 +7585,23 @@ function createRaindropAISDK(opts) {
|
|
|
6754
7585
|
await Promise.all([eventShipper.flush(), traceShipper.flush()]);
|
|
6755
7586
|
},
|
|
6756
7587
|
async shutdown() {
|
|
6757
|
-
|
|
7588
|
+
try {
|
|
7589
|
+
await Promise.all([eventShipper.shutdown(), traceShipper.shutdown()]);
|
|
7590
|
+
} finally {
|
|
7591
|
+
try {
|
|
7592
|
+
appGitContext.dispose();
|
|
7593
|
+
} catch (e) {
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
6758
7596
|
}
|
|
6759
7597
|
};
|
|
6760
7598
|
}
|
|
6761
7599
|
function raindrop(options = {}) {
|
|
6762
7600
|
var _a;
|
|
6763
|
-
const { context, subagentWrapping, writeKey, ...rest } = options;
|
|
7601
|
+
const { context, subagentWrapping, tools, writeKey, ...rest } = options;
|
|
6764
7602
|
const resolvedWriteKey = writeKey != null ? writeKey : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.RAINDROP_WRITE_KEY : void 0;
|
|
6765
7603
|
const client = createRaindropAISDK({ ...rest, writeKey: resolvedWriteKey });
|
|
6766
|
-
return client.createTelemetryIntegration({ context, subagentWrapping });
|
|
7604
|
+
return client.createTelemetryIntegration({ context, subagentWrapping, tools });
|
|
6767
7605
|
}
|
|
6768
7606
|
|
|
6769
7607
|
// src/index.workers.ts
|
|
@@ -6779,6 +7617,7 @@ exports.HANDOFF_ATTRIBUTE_PREFIXES = HANDOFF_ATTRIBUTE_PREFIXES;
|
|
|
6779
7617
|
exports.HANDOFF_ATTRIBUTE_SUFFIXES = HANDOFF_ATTRIBUTE_SUFFIXES;
|
|
6780
7618
|
exports.HANDOFF_TERMINAL_CANCELLED = HANDOFF_TERMINAL_CANCELLED;
|
|
6781
7619
|
exports.HANDOFF_TERMINAL_PROPERTY_KEY = HANDOFF_TERMINAL_PROPERTY_KEY;
|
|
7620
|
+
exports.PROMPT_TOOLS_ATTRIBUTE = PROMPT_TOOLS_ATTRIBUTE;
|
|
6782
7621
|
exports.REDACTED_PLACEHOLDER = REDACTED_PLACEHOLDER;
|
|
6783
7622
|
exports.RaindropTelemetryIntegration = RaindropTelemetryIntegration;
|
|
6784
7623
|
exports.SUBAGENT_ABORTED_OUTPUT = SUBAGENT_ABORTED_OUTPUT;
|