@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
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { execFile } from 'child_process';
|
|
3
|
+
import { resolve } from 'path';
|
|
2
4
|
|
|
3
5
|
// ../core/dist/chunk-BYBMRLZM.js
|
|
4
6
|
var EVAL_CORRELATION_ID_ATTRIBUTE = "raindrop.eval_correlation_id";
|
|
@@ -62,7 +64,574 @@ function evalScopeAttributes() {
|
|
|
62
64
|
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
// ../core/dist/chunk-
|
|
67
|
+
// ../core/dist/chunk-I6TVJQEC.js
|
|
68
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
69
|
+
function state() {
|
|
70
|
+
const holder = globalThis;
|
|
71
|
+
let current = holder[STATE_KEY];
|
|
72
|
+
if (!current) {
|
|
73
|
+
let storage = null;
|
|
74
|
+
try {
|
|
75
|
+
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
76
|
+
if (Ctor) storage = new Ctor();
|
|
77
|
+
} catch (e) {
|
|
78
|
+
storage = null;
|
|
79
|
+
}
|
|
80
|
+
current = {
|
|
81
|
+
storage,
|
|
82
|
+
syncDestination: void 0,
|
|
83
|
+
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
84
|
+
};
|
|
85
|
+
holder[STATE_KEY] = current;
|
|
86
|
+
}
|
|
87
|
+
return current;
|
|
88
|
+
}
|
|
89
|
+
function currentReplayTraceDestination() {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const routing = state();
|
|
92
|
+
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
93
|
+
}
|
|
94
|
+
function rememberReplayTraceDestination(span) {
|
|
95
|
+
const destination = currentReplayTraceDestination();
|
|
96
|
+
if (destination) state().spanDestinations.set(span, destination);
|
|
97
|
+
}
|
|
98
|
+
function copyReplayTraceDestination(source, target) {
|
|
99
|
+
const destination = state().spanDestinations.get(source);
|
|
100
|
+
if (destination) state().spanDestinations.set(target, destination);
|
|
101
|
+
}
|
|
102
|
+
function replayTraceDestinationFor(value) {
|
|
103
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
return state().spanDestinations.get(value);
|
|
107
|
+
}
|
|
108
|
+
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
if (!destination || !spanId || !traceId) return;
|
|
111
|
+
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
112
|
+
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
113
|
+
}
|
|
114
|
+
function replayTraceUrl(baseUrl) {
|
|
115
|
+
return `${baseUrl.replace(/\/+$/, "")}/v1/traces`;
|
|
116
|
+
}
|
|
117
|
+
var NOOP_SPAN = {
|
|
118
|
+
traceIdB64: "",
|
|
119
|
+
spanIdB64: "",
|
|
120
|
+
eventId: "",
|
|
121
|
+
log() {
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function getAsyncLocalStorageCtor() {
|
|
125
|
+
return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
126
|
+
}
|
|
127
|
+
var SynchronousContextStorage = class {
|
|
128
|
+
constructor() {
|
|
129
|
+
this._stack = [];
|
|
130
|
+
}
|
|
131
|
+
isEmpty() {
|
|
132
|
+
return this._stack.length === 0;
|
|
133
|
+
}
|
|
134
|
+
getStore() {
|
|
135
|
+
return this._stack[this._stack.length - 1];
|
|
136
|
+
}
|
|
137
|
+
run(store, callback) {
|
|
138
|
+
this._stack.push(store);
|
|
139
|
+
try {
|
|
140
|
+
return callback();
|
|
141
|
+
} finally {
|
|
142
|
+
this._stack.pop();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var ContextManager = class {
|
|
147
|
+
};
|
|
148
|
+
var RaindropContextManager = class extends ContextManager {
|
|
149
|
+
constructor() {
|
|
150
|
+
super();
|
|
151
|
+
this._fallback = null;
|
|
152
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
153
|
+
if (Ctor) {
|
|
154
|
+
this._storage = new Ctor();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this._fallback = new SynchronousContextStorage();
|
|
158
|
+
this._storage = this._fallback;
|
|
159
|
+
}
|
|
160
|
+
maybeAdoptAsyncLocalStorage() {
|
|
161
|
+
if (!this._fallback || !this._fallback.isEmpty()) return;
|
|
162
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
163
|
+
if (!Ctor) return;
|
|
164
|
+
this._storage = new Ctor();
|
|
165
|
+
this._fallback = null;
|
|
166
|
+
}
|
|
167
|
+
isReady() {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
getParentSpanIds() {
|
|
171
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
172
|
+
const span = this._storage.getStore();
|
|
173
|
+
if (!span || span === NOOP_SPAN) return void 0;
|
|
174
|
+
return {
|
|
175
|
+
traceIdB64: span.traceIdB64,
|
|
176
|
+
spanIdB64: span.spanIdB64,
|
|
177
|
+
eventId: span.eventId
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
runInContext(span, callback) {
|
|
181
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
182
|
+
return this._storage.run(span, callback);
|
|
183
|
+
}
|
|
184
|
+
getCurrentSpan() {
|
|
185
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
186
|
+
return this._storage.getStore();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var _contextManager = null;
|
|
190
|
+
function getContextManager() {
|
|
191
|
+
if (!_contextManager) {
|
|
192
|
+
_contextManager = globalThis.RAINDROP_CONTEXT_MANAGER ? new globalThis.RAINDROP_CONTEXT_MANAGER() : new RaindropContextManager();
|
|
193
|
+
}
|
|
194
|
+
return _contextManager;
|
|
195
|
+
}
|
|
196
|
+
function currentSpan() {
|
|
197
|
+
var _a;
|
|
198
|
+
return (_a = getContextManager().getCurrentSpan()) != null ? _a : NOOP_SPAN;
|
|
199
|
+
}
|
|
200
|
+
function withCurrent(span, callback) {
|
|
201
|
+
return getContextManager().runInContext(span, callback);
|
|
202
|
+
}
|
|
203
|
+
async function getCurrentParentSpanContext() {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
return (_b = getContextManager().getParentSpanIds()) != null ? _b : (_a = currentReplayTraceDestination()) == null ? void 0 : _a.parentSpanContext;
|
|
206
|
+
}
|
|
207
|
+
async function runWithParentSpanContext(ctx, fn) {
|
|
208
|
+
const cm = getContextManager();
|
|
209
|
+
const span = {
|
|
210
|
+
traceIdB64: ctx.traceIdB64,
|
|
211
|
+
spanIdB64: ctx.spanIdB64,
|
|
212
|
+
eventId: ctx.eventId
|
|
213
|
+
};
|
|
214
|
+
return cm.runInContext(span, fn);
|
|
215
|
+
}
|
|
216
|
+
async function* asyncGeneratorWithCurrent(span, gen) {
|
|
217
|
+
let nextValue;
|
|
218
|
+
while (true) {
|
|
219
|
+
const result = await withCurrent(span, async () => {
|
|
220
|
+
try {
|
|
221
|
+
return await gen.next(nextValue);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
return { value: void 0, done: true, error: e };
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
if ("error" in result && result.error !== void 0) {
|
|
227
|
+
throw result.error;
|
|
228
|
+
}
|
|
229
|
+
if (result.done) {
|
|
230
|
+
return result.value;
|
|
231
|
+
}
|
|
232
|
+
nextValue = yield result.value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var MAX_BINDING_STACK = 128;
|
|
236
|
+
var EMPTY_STACK = [];
|
|
237
|
+
var ContextStackStorage = class {
|
|
238
|
+
/** Emitted once when this runtime cannot support an ambient push. */
|
|
239
|
+
constructor(noAmbientBindWarning) {
|
|
240
|
+
this.noAmbientBindWarning = noAmbientBindWarning;
|
|
241
|
+
this._als = null;
|
|
242
|
+
this._enterWithUsable = false;
|
|
243
|
+
this._syncStack = EMPTY_STACK;
|
|
244
|
+
this._adoptionChecked = false;
|
|
245
|
+
this._warnedNoAmbientBind = false;
|
|
246
|
+
}
|
|
247
|
+
maybeAdoptAsyncLocalStorage() {
|
|
248
|
+
if (this._adoptionChecked) return;
|
|
249
|
+
this._adoptionChecked = true;
|
|
250
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
251
|
+
if (!Ctor) return;
|
|
252
|
+
const als = new Ctor();
|
|
253
|
+
try {
|
|
254
|
+
als.run(EMPTY_STACK, () => {
|
|
255
|
+
});
|
|
256
|
+
} catch (e) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this._als = als;
|
|
260
|
+
if (typeof als.enterWith === "function") {
|
|
261
|
+
try {
|
|
262
|
+
als.enterWith(EMPTY_STACK);
|
|
263
|
+
this._enterWithUsable = true;
|
|
264
|
+
} catch (e) {
|
|
265
|
+
this._enterWithUsable = false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
getStack() {
|
|
270
|
+
var _a;
|
|
271
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
272
|
+
if (this._als) return (_a = this._als.getStore()) != null ? _a : this._syncStack;
|
|
273
|
+
return this._syncStack;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Persist an ambient stack mutation. Returns false when an ALS is adopted but
|
|
277
|
+
* `enterWith` is unusable (workerd): callers must NOT fall back to the
|
|
278
|
+
* process-shared sync stack, since concurrent isolates would cross-stamp.
|
|
279
|
+
*/
|
|
280
|
+
setAmbientStack(stack) {
|
|
281
|
+
if (this._als) {
|
|
282
|
+
if (!this._enterWithUsable) return false;
|
|
283
|
+
this._als.enterWith(stack);
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
this._syncStack = stack;
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
push(binding) {
|
|
290
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
291
|
+
if (this._als && !this._enterWithUsable) {
|
|
292
|
+
this.warnNoAmbientBindOnce();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
let stack = this.getStack();
|
|
296
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
297
|
+
stack = stack.filter((b) => b.isLive());
|
|
298
|
+
if (stack.length >= MAX_BINDING_STACK) {
|
|
299
|
+
stack = stack.slice(stack.length - (MAX_BINDING_STACK - 1));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
this.setAmbientStack([...stack, binding]);
|
|
303
|
+
}
|
|
304
|
+
remove(binding) {
|
|
305
|
+
binding.markDead();
|
|
306
|
+
const stack = this.getStack();
|
|
307
|
+
const pruned = stack.filter((b) => b !== binding && b.isLive());
|
|
308
|
+
if (pruned.length !== stack.length) {
|
|
309
|
+
this.setAmbientStack(pruned);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
runWith(binding, callback) {
|
|
313
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
314
|
+
if (this._als) {
|
|
315
|
+
return this._als.run([...this.getStack(), binding], callback);
|
|
316
|
+
}
|
|
317
|
+
const previous = this._syncStack;
|
|
318
|
+
this._syncStack = [...previous, binding];
|
|
319
|
+
try {
|
|
320
|
+
return callback();
|
|
321
|
+
} finally {
|
|
322
|
+
this._syncStack = previous;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
current() {
|
|
326
|
+
const stack = this.getStack();
|
|
327
|
+
if (stack.length === 0) return void 0;
|
|
328
|
+
const top = stack[stack.length - 1];
|
|
329
|
+
if (top.isLive()) return top;
|
|
330
|
+
const pruned = stack.filter((b) => b.isLive());
|
|
331
|
+
this.setAmbientStack(pruned);
|
|
332
|
+
return pruned.length > 0 ? pruned[pruned.length - 1] : void 0;
|
|
333
|
+
}
|
|
334
|
+
warnNoAmbientBindOnce() {
|
|
335
|
+
if (this._warnedNoAmbientBind) return;
|
|
336
|
+
this._warnedNoAmbientBind = true;
|
|
337
|
+
console.warn(this.noAmbientBindWarning);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var NO_AMBIENT_ROUTING_BIND_WARNING = "[raindrop] This runtime's AsyncLocalStorage does not implement enterWith (e.g. Cloudflare Workers), so begin()/finish() cannot scope auto-instrumented spans to a project without cross-contaminating concurrent requests. Manual events and explicit span routing are unaffected; use asCurrent()/withSpan (run-based) to route auto-instrumented spans on this runtime.";
|
|
341
|
+
var ROUTING_STORAGE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.routingContextStorage");
|
|
342
|
+
function routingStorage() {
|
|
343
|
+
const holder = globalThis;
|
|
344
|
+
let storage = holder[ROUTING_STORAGE_KEY];
|
|
345
|
+
if (!storage) {
|
|
346
|
+
storage = new ContextStackStorage(NO_AMBIENT_ROUTING_BIND_WARNING);
|
|
347
|
+
holder[ROUTING_STORAGE_KEY] = storage;
|
|
348
|
+
}
|
|
349
|
+
return storage;
|
|
350
|
+
}
|
|
351
|
+
function currentRoutingBinding() {
|
|
352
|
+
const bound = routingStorage().current();
|
|
353
|
+
if (!bound) return void 0;
|
|
354
|
+
return {
|
|
355
|
+
projectId: bound.projectId,
|
|
356
|
+
authHint: bound.authHint,
|
|
357
|
+
...bound.appGit ? { appGit: bound.appGit } : {},
|
|
358
|
+
...bound.appGitSource ? { appGitSource: bound.appGitSource } : {}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
var APP_COMMIT_SHA = "raindrop.app.commit_sha";
|
|
362
|
+
var APP_COMMIT_DIRTY = "raindrop.app.commit_dirty";
|
|
363
|
+
var APP_BRANCH = "raindrop.app.branch";
|
|
364
|
+
var APP_GIT_KEYS = [APP_COMMIT_SHA, APP_COMMIT_DIRTY, APP_BRANCH];
|
|
365
|
+
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
366
|
+
function appGitExplicitKeys(properties) {
|
|
367
|
+
const keys = /* @__PURE__ */ new Set();
|
|
368
|
+
if (!properties) return keys;
|
|
369
|
+
for (const key of APP_GIT_KEYS) {
|
|
370
|
+
if (own(properties, key)) keys.add(key);
|
|
371
|
+
}
|
|
372
|
+
return keys;
|
|
373
|
+
}
|
|
374
|
+
function mergeAppGitSnapshot(base, properties, explicitKeys = /* @__PURE__ */ new Set()) {
|
|
375
|
+
try {
|
|
376
|
+
const result = { ...base };
|
|
377
|
+
if (properties && own(properties, APP_COMMIT_SHA) && properties[APP_COMMIT_SHA] !== result[APP_COMMIT_SHA]) {
|
|
378
|
+
if (!explicitKeys.has(APP_COMMIT_DIRTY) && !own(properties, APP_COMMIT_DIRTY)) {
|
|
379
|
+
delete result[APP_COMMIT_DIRTY];
|
|
380
|
+
}
|
|
381
|
+
if (!explicitKeys.has(APP_BRANCH) && !own(properties, APP_BRANCH)) {
|
|
382
|
+
delete result[APP_BRANCH];
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
for (const key of APP_GIT_KEYS) {
|
|
386
|
+
if (properties && own(properties, key)) result[key] = properties[key];
|
|
387
|
+
}
|
|
388
|
+
return Object.freeze(result);
|
|
389
|
+
} catch (e) {
|
|
390
|
+
return Object.freeze({});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function validAppCommitSha(value) {
|
|
394
|
+
if (typeof value !== "string" || value.length > 128) return void 0;
|
|
395
|
+
const cleaned = value.trim();
|
|
396
|
+
return /^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(cleaned) ? cleaned.toLowerCase() : void 0;
|
|
397
|
+
}
|
|
398
|
+
function shortString(value) {
|
|
399
|
+
if (typeof value !== "string" || value.length > 1024) return void 0;
|
|
400
|
+
const cleaned = value.trim();
|
|
401
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
402
|
+
}
|
|
403
|
+
function flag(value) {
|
|
404
|
+
if (value === true || value === "true" || value === "1") return true;
|
|
405
|
+
if (value === false || value === "false" || value === "0") return false;
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
function environment() {
|
|
409
|
+
try {
|
|
410
|
+
return typeof process === "undefined" ? {} : process.env;
|
|
411
|
+
} catch (e) {
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
var DEPLOYMENTS = [
|
|
416
|
+
["VERCEL", "VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF"],
|
|
417
|
+
["NETLIFY", "COMMIT_REF", "BRANCH"],
|
|
418
|
+
["RAILWAY_ENVIRONMENT_NAME", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
419
|
+
["RAILWAY_ENVIRONMENT", "RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH"],
|
|
420
|
+
["RENDER", "RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH"],
|
|
421
|
+
["DYNO", "HEROKU_BUILD_COMMIT", ""],
|
|
422
|
+
["DYNO", "HEROKU_SLUG_COMMIT", ""],
|
|
423
|
+
["AWS_APP_ID", "AWS_COMMIT_ID", "AWS_BRANCH"],
|
|
424
|
+
["WORKERS_CI", "WORKERS_CI_COMMIT_SHA", "WORKERS_CI_BRANCH"]
|
|
425
|
+
];
|
|
426
|
+
var CI_SOURCES = [
|
|
427
|
+
["GITHUB_ACTIONS", "GITHUB_SHA", "GITHUB_REF_NAME"],
|
|
428
|
+
["GITLAB_CI", "CI_COMMIT_SHA", "CI_COMMIT_REF_NAME"],
|
|
429
|
+
["CIRCLECI", "CIRCLE_SHA1", "CIRCLE_BRANCH"]
|
|
430
|
+
];
|
|
431
|
+
function detectedSource(env, table, detectBranch) {
|
|
432
|
+
for (const row of table) {
|
|
433
|
+
const [marker, shaKey, branchKey] = row;
|
|
434
|
+
if (!marker || !shaKey || !shortString(env[marker]) || flag(env[marker]) === false) continue;
|
|
435
|
+
const commitSha = validAppCommitSha(env[shaKey]);
|
|
436
|
+
if (commitSha)
|
|
437
|
+
return {
|
|
438
|
+
commitSha,
|
|
439
|
+
...detectBranch && branchKey ? { branch: shortString(env[branchKey]) } : {}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
return {};
|
|
443
|
+
}
|
|
444
|
+
var AppGitContextImpl = class {
|
|
445
|
+
constructor(options, runtime = {}) {
|
|
446
|
+
this.defaults = {};
|
|
447
|
+
this.explicit = {};
|
|
448
|
+
this.explicitKeys = /* @__PURE__ */ new Set();
|
|
449
|
+
this.disposed = false;
|
|
450
|
+
this.operations = /* @__PURE__ */ new Map();
|
|
451
|
+
this.operationOverflow = false;
|
|
452
|
+
this.detectBranch = false;
|
|
453
|
+
this.disabled = false;
|
|
454
|
+
var _a, _b, _c, _d, _e, _f;
|
|
455
|
+
try {
|
|
456
|
+
if (options === false) {
|
|
457
|
+
this.disabled = true;
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const opts = options != null ? options : {};
|
|
461
|
+
const env = (_a = runtime.env) != null ? _a : environment();
|
|
462
|
+
const detectBranch = (_c = (_b = flag(opts.detectBranch)) != null ? _b : flag(env.RAINDROP_GIT_DETECT_BRANCH)) != null ? _c : false;
|
|
463
|
+
this.detectBranch = detectBranch;
|
|
464
|
+
const collectBranch = detectBranch || runtime.captureLegacyReplayBranch === true;
|
|
465
|
+
const autoDetect = runtime.allowDiscovery === false ? false : (_e = (_d = flag(opts.autoDetect)) != null ? _d : flag(env.RAINDROP_GIT_AUTO_DETECT)) != null ? _e : true;
|
|
466
|
+
const configuredSha = opts.commitSha;
|
|
467
|
+
const explicitSha = configuredSha === void 0 ? env.RAINDROP_COMMIT_SHA : configuredSha;
|
|
468
|
+
if (explicitSha === null) this.explicit[APP_COMMIT_SHA] = null;
|
|
469
|
+
else if (typeof explicitSha === "string" && validAppCommitSha(explicitSha))
|
|
470
|
+
this.explicit[APP_COMMIT_SHA] = explicitSha;
|
|
471
|
+
const configuredDirty = opts.commitDirty;
|
|
472
|
+
const explicitDirty = configuredDirty === void 0 ? flag(env.RAINDROP_COMMIT_DIRTY) : configuredDirty;
|
|
473
|
+
if (explicitDirty === null || typeof explicitDirty === "boolean")
|
|
474
|
+
this.explicit[APP_COMMIT_DIRTY] = explicitDirty;
|
|
475
|
+
const configuredBranch = opts.branch;
|
|
476
|
+
const explicitBranch = configuredBranch === void 0 ? env.RAINDROP_BRANCH : configuredBranch;
|
|
477
|
+
if (explicitBranch === null) this.explicit[APP_BRANCH] = null;
|
|
478
|
+
else if (typeof explicitBranch === "string" && explicitBranch.length <= 1024)
|
|
479
|
+
this.explicit[APP_BRANCH] = explicitBranch;
|
|
480
|
+
this.explicitKeys = appGitExplicitKeys(this.explicit);
|
|
481
|
+
this.defaults = { ...this.explicit };
|
|
482
|
+
if (!autoDetect || explicitSha !== void 0) return;
|
|
483
|
+
const sourceDirectory = (_f = shortString(opts.sourceDirectory)) != null ? _f : shortString(env.RAINDROP_GIT_SOURCE_DIRECTORY);
|
|
484
|
+
if (runtime.allowLocalGit === false && !sourceDirectory) return;
|
|
485
|
+
const deploy = sourceDirectory ? {} : detectedSource(env, DEPLOYMENTS, collectBranch);
|
|
486
|
+
if (deploy.commitSha) {
|
|
487
|
+
this.accept(deploy);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const fallback = sourceDirectory ? {} : detectedSource(env, CI_SOURCES, collectBranch);
|
|
491
|
+
if (runtime.resolveLocal && (runtime.allowLocalGit !== false || sourceDirectory)) {
|
|
492
|
+
this.cancel = runtime.resolveLocal(sourceDirectory, collectBranch, (result) => {
|
|
493
|
+
try {
|
|
494
|
+
if (!this.disposed) this.accept(result.commitSha ? result : fallback);
|
|
495
|
+
} catch (e) {
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
} else this.accept(fallback);
|
|
499
|
+
} catch (e) {
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
accept(result) {
|
|
503
|
+
const sha = validAppCommitSha(result.commitSha);
|
|
504
|
+
if (!sha) return;
|
|
505
|
+
this.replayBranch = shortString(result.branch);
|
|
506
|
+
this.defaults = {
|
|
507
|
+
[APP_COMMIT_SHA]: sha,
|
|
508
|
+
...typeof result.commitDirty === "boolean" ? { [APP_COMMIT_DIRTY]: result.commitDirty } : {},
|
|
509
|
+
...this.detectBranch && this.replayBranch ? { [APP_BRANCH]: this.replayBranch } : {},
|
|
510
|
+
...this.explicit
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
snapshot(properties) {
|
|
514
|
+
var _a;
|
|
515
|
+
try {
|
|
516
|
+
const binding = currentRoutingBinding();
|
|
517
|
+
const base = this.disabled && (binding == null ? void 0 : binding.appGitSource) !== "replay-override" ? {} : (_a = binding == null ? void 0 : binding.appGit) != null ? _a : this.defaults;
|
|
518
|
+
return this.mergeSnapshot(base, properties);
|
|
519
|
+
} catch (e) {
|
|
520
|
+
return Object.freeze({});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/** Safe defaults when no operation/span start was observed; never infer identity. */
|
|
524
|
+
snapshotExplicit(properties, eventId) {
|
|
525
|
+
try {
|
|
526
|
+
const base = { ...this.explicit };
|
|
527
|
+
const operation = eventId ? this.operations.get(eventId) : void 0;
|
|
528
|
+
if (operation) {
|
|
529
|
+
for (const key of operation.explicitKeys) base[key] = operation.snapshot[key];
|
|
530
|
+
}
|
|
531
|
+
return this.mergeSnapshot(base, properties, new Set(Object.keys(base)));
|
|
532
|
+
} catch (e) {
|
|
533
|
+
return mergeAppGitSnapshot({}, properties);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/** Existing replay branch reporting stays separate from opt-in event properties. */
|
|
537
|
+
snapshotForReplay() {
|
|
538
|
+
const snapshot = this.snapshot();
|
|
539
|
+
if (this.replayBranch && !own(snapshot, APP_BRANCH) && snapshot[APP_COMMIT_SHA] === this.defaults[APP_COMMIT_SHA]) {
|
|
540
|
+
return Object.freeze({ ...snapshot, [APP_BRANCH]: this.replayBranch });
|
|
541
|
+
}
|
|
542
|
+
return snapshot;
|
|
543
|
+
}
|
|
544
|
+
/** Merge a frozen span snapshot without losing client-authored provenance. */
|
|
545
|
+
mergeSnapshot(base, properties, explicitKeys = this.explicitKeys) {
|
|
546
|
+
return mergeAppGitSnapshot(base, properties, /* @__PURE__ */ new Set([...this.explicitKeys, ...explicitKeys]));
|
|
547
|
+
}
|
|
548
|
+
/** Shippers belonging to one client share this bounded operation registry. */
|
|
549
|
+
forOperation(eventId, properties, owner) {
|
|
550
|
+
if (!eventId) return this.snapshot(properties);
|
|
551
|
+
let operation = this.operations.get(eventId);
|
|
552
|
+
if (!operation) {
|
|
553
|
+
if (this.operations.size >= 1e4) this.operationOverflow = true;
|
|
554
|
+
if (this.operationOverflow) return this.mergeSnapshot({}, properties);
|
|
555
|
+
operation = {
|
|
556
|
+
snapshot: this.snapshot(properties),
|
|
557
|
+
owners: /* @__PURE__ */ new Set(),
|
|
558
|
+
unowned: owner === void 0,
|
|
559
|
+
explicitKeys: appGitExplicitKeys(properties)
|
|
560
|
+
};
|
|
561
|
+
this.operations.set(eventId, operation);
|
|
562
|
+
} else if (properties && APP_GIT_KEYS.some((key) => own(properties, key))) {
|
|
563
|
+
const explicitKeys = /* @__PURE__ */ new Set([...this.explicitKeys, ...operation.explicitKeys]);
|
|
564
|
+
operation.snapshot = this.mergeSnapshot(operation.snapshot, properties, explicitKeys);
|
|
565
|
+
for (const key of appGitExplicitKeys(properties)) operation.explicitKeys.add(key);
|
|
566
|
+
}
|
|
567
|
+
if (!owner) operation.unowned = true;
|
|
568
|
+
if (owner) operation.owners.add(owner);
|
|
569
|
+
return operation.snapshot;
|
|
570
|
+
}
|
|
571
|
+
releaseOperation(eventId, owner) {
|
|
572
|
+
const operation = this.operations.get(eventId);
|
|
573
|
+
if (!operation) return;
|
|
574
|
+
operation.owners.delete(owner);
|
|
575
|
+
if (operation.owners.size === 0 && !operation.unowned) this.operations.delete(eventId);
|
|
576
|
+
}
|
|
577
|
+
finishOperation(eventId) {
|
|
578
|
+
this.operations.delete(eventId);
|
|
579
|
+
}
|
|
580
|
+
dispose() {
|
|
581
|
+
var _a;
|
|
582
|
+
this.disposed = true;
|
|
583
|
+
try {
|
|
584
|
+
(_a = this.cancel) == null ? void 0 : _a.call(this);
|
|
585
|
+
} catch (e) {
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
var AppGitContext = AppGitContextImpl;
|
|
590
|
+
function createAppGitContext(options, runtime = {}) {
|
|
591
|
+
return new AppGitContext(options, runtime);
|
|
592
|
+
}
|
|
593
|
+
function withAppGitProperties(properties, snapshot) {
|
|
594
|
+
try {
|
|
595
|
+
const merged = { ...properties };
|
|
596
|
+
for (const key of APP_GIT_KEYS)
|
|
597
|
+
if (!own(merged, key) && own(snapshot, key)) merged[key] = snapshot[key];
|
|
598
|
+
return merged;
|
|
599
|
+
} catch (e) {
|
|
600
|
+
return properties != null ? properties : {};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function withAppGitAttributes(attributes, snapshot) {
|
|
604
|
+
try {
|
|
605
|
+
const present = new Set(attributes.flatMap((attr) => attr ? [attr.key] : []));
|
|
606
|
+
const added = [];
|
|
607
|
+
for (const key of APP_GIT_KEYS) {
|
|
608
|
+
if (present.has(key) || present.has(`ai.telemetry.metadata.${key}`) || present.has(`traceloop.association.properties.${key}`))
|
|
609
|
+
continue;
|
|
610
|
+
const value = snapshot[key];
|
|
611
|
+
if (typeof value === "string") added.push({ key, value: { stringValue: value } });
|
|
612
|
+
else if (typeof value === "boolean") added.push({ key, value: { boolValue: value } });
|
|
613
|
+
}
|
|
614
|
+
return added.length ? [...attributes, ...added] : attributes;
|
|
615
|
+
} catch (e) {
|
|
616
|
+
return attributes;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function appGitPropertiesFromAttributes(attributes) {
|
|
620
|
+
var _a, _b, _c;
|
|
621
|
+
const properties = {};
|
|
622
|
+
try {
|
|
623
|
+
for (const attr of attributes) {
|
|
624
|
+
if (!attr) continue;
|
|
625
|
+
for (const key of APP_GIT_KEYS) {
|
|
626
|
+
if (attr.key === key || attr.key === `ai.telemetry.metadata.${key}` || attr.key === `traceloop.association.properties.${key}`) {
|
|
627
|
+
properties[key] = (_c = (_b = (_a = attr.value.stringValue) != null ? _a : attr.value.boolValue) != null ? _b : attr.value.intValue) != null ? _c : null;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
} catch (e) {
|
|
632
|
+
}
|
|
633
|
+
return properties;
|
|
634
|
+
}
|
|
66
635
|
function normalizeFeatureFlags(input) {
|
|
67
636
|
if (Array.isArray(input)) {
|
|
68
637
|
return Object.fromEntries(input.map((name) => [name, "true"]));
|
|
@@ -447,7 +1016,7 @@ function runWithTracingSuppressed(fn) {
|
|
|
447
1016
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
448
1017
|
var MAX_RETRY_DELAY_MS = 3e4;
|
|
449
1018
|
function wait(ms) {
|
|
450
|
-
return new Promise((
|
|
1019
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
451
1020
|
}
|
|
452
1021
|
function formatEndpoint(endpoint) {
|
|
453
1022
|
if (!endpoint) return void 0;
|
|
@@ -484,9 +1053,9 @@ async function raceWithTimeout(promise, timeoutMs) {
|
|
|
484
1053
|
() => true,
|
|
485
1054
|
() => true
|
|
486
1055
|
),
|
|
487
|
-
new Promise((
|
|
1056
|
+
new Promise((resolve2) => {
|
|
488
1057
|
var _a;
|
|
489
|
-
timer = setTimeout(() =>
|
|
1058
|
+
timer = setTimeout(() => resolve2(false), Math.max(0, timeoutMs));
|
|
490
1059
|
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
491
1060
|
})
|
|
492
1061
|
]);
|
|
@@ -653,82 +1222,33 @@ function attrStringArray(key, values) {
|
|
|
653
1222
|
function buildOtlpSpan(args) {
|
|
654
1223
|
const attrs = args.attributes.filter((x) => x !== void 0);
|
|
655
1224
|
const span = {
|
|
656
|
-
traceId: args.ids.traceIdB64,
|
|
657
|
-
spanId: args.ids.spanIdB64,
|
|
658
|
-
name: args.name,
|
|
659
|
-
startTimeUnixNano: args.startTimeUnixNano,
|
|
660
|
-
endTimeUnixNano: args.endTimeUnixNano
|
|
661
|
-
};
|
|
662
|
-
if (args.ids.parentSpanIdB64) span.parentSpanId = args.ids.parentSpanIdB64;
|
|
663
|
-
if (attrs.length) span.attributes = attrs;
|
|
664
|
-
if (args.status) span.status = args.status;
|
|
665
|
-
return span;
|
|
666
|
-
}
|
|
667
|
-
function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", serviceVersion = "0.0.0") {
|
|
668
|
-
return {
|
|
669
|
-
resourceSpans: [
|
|
670
|
-
{
|
|
671
|
-
resource: {
|
|
672
|
-
attributes: [{ key: "service.name", value: { stringValue: serviceName } }]
|
|
673
|
-
},
|
|
674
|
-
scopeSpans: [
|
|
675
|
-
{
|
|
676
|
-
scope: { name: serviceName, version: serviceVersion },
|
|
677
|
-
spans
|
|
678
|
-
}
|
|
679
|
-
]
|
|
680
|
-
}
|
|
681
|
-
]
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
|
|
685
|
-
function state() {
|
|
686
|
-
const holder = globalThis;
|
|
687
|
-
let current = holder[STATE_KEY];
|
|
688
|
-
if (!current) {
|
|
689
|
-
let storage = null;
|
|
690
|
-
try {
|
|
691
|
-
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
692
|
-
if (Ctor) storage = new Ctor();
|
|
693
|
-
} catch (e) {
|
|
694
|
-
storage = null;
|
|
695
|
-
}
|
|
696
|
-
current = {
|
|
697
|
-
storage,
|
|
698
|
-
syncDestination: void 0,
|
|
699
|
-
spanDestinations: /* @__PURE__ */ new WeakMap()
|
|
700
|
-
};
|
|
701
|
-
holder[STATE_KEY] = current;
|
|
702
|
-
}
|
|
703
|
-
return current;
|
|
704
|
-
}
|
|
705
|
-
function currentReplayTraceDestination() {
|
|
706
|
-
var _a, _b;
|
|
707
|
-
const routing = state();
|
|
708
|
-
return (_b = (_a = routing.storage) == null ? void 0 : _a.getStore()) != null ? _b : routing.syncDestination;
|
|
709
|
-
}
|
|
710
|
-
function rememberReplayTraceDestination(span) {
|
|
711
|
-
const destination = currentReplayTraceDestination();
|
|
712
|
-
if (destination) state().spanDestinations.set(span, destination);
|
|
713
|
-
}
|
|
714
|
-
function copyReplayTraceDestination(source, target) {
|
|
715
|
-
const destination = state().spanDestinations.get(source);
|
|
716
|
-
if (destination) state().spanDestinations.set(target, destination);
|
|
717
|
-
}
|
|
718
|
-
function replayTraceDestinationFor(value) {
|
|
719
|
-
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
720
|
-
return void 0;
|
|
721
|
-
}
|
|
722
|
-
return state().spanDestinations.get(value);
|
|
723
|
-
}
|
|
724
|
-
function recordReplayExportedSpan(destination, spanId, traceId) {
|
|
725
|
-
var _a, _b;
|
|
726
|
-
if (!destination || !spanId || !traceId) return;
|
|
727
|
-
(_a = destination.exportedSpanIds) == null ? void 0 : _a.add(spanId);
|
|
728
|
-
(_b = destination.exportedTraceIds) == null ? void 0 : _b.add(traceId);
|
|
1225
|
+
traceId: args.ids.traceIdB64,
|
|
1226
|
+
spanId: args.ids.spanIdB64,
|
|
1227
|
+
name: args.name,
|
|
1228
|
+
startTimeUnixNano: args.startTimeUnixNano,
|
|
1229
|
+
endTimeUnixNano: args.endTimeUnixNano
|
|
1230
|
+
};
|
|
1231
|
+
if (args.ids.parentSpanIdB64) span.parentSpanId = args.ids.parentSpanIdB64;
|
|
1232
|
+
if (attrs.length) span.attributes = attrs;
|
|
1233
|
+
if (args.status) span.status = args.status;
|
|
1234
|
+
return span;
|
|
729
1235
|
}
|
|
730
|
-
function
|
|
731
|
-
return
|
|
1236
|
+
function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", serviceVersion = "0.0.0") {
|
|
1237
|
+
return {
|
|
1238
|
+
resourceSpans: [
|
|
1239
|
+
{
|
|
1240
|
+
resource: {
|
|
1241
|
+
attributes: [{ key: "service.name", value: { stringValue: serviceName } }]
|
|
1242
|
+
},
|
|
1243
|
+
scopeSpans: [
|
|
1244
|
+
{
|
|
1245
|
+
scope: { name: serviceName, version: serviceVersion },
|
|
1246
|
+
spans
|
|
1247
|
+
}
|
|
1248
|
+
]
|
|
1249
|
+
}
|
|
1250
|
+
]
|
|
1251
|
+
};
|
|
732
1252
|
}
|
|
733
1253
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
734
1254
|
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
@@ -864,6 +1384,13 @@ function projectIdHeaders(projectId) {
|
|
|
864
1384
|
}
|
|
865
1385
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
866
1386
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
1387
|
+
function appGitOwnerId(prefix) {
|
|
1388
|
+
try {
|
|
1389
|
+
return `${prefix}:${randomUUID()}`;
|
|
1390
|
+
} catch (e) {
|
|
1391
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
867
1394
|
function mergePatches(target, source) {
|
|
868
1395
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
869
1396
|
const out = { ...target, ...source };
|
|
@@ -913,22 +1440,25 @@ function eventTelemetryProperties(patch) {
|
|
|
913
1440
|
}
|
|
914
1441
|
var EventShipper = class {
|
|
915
1442
|
constructor(opts) {
|
|
1443
|
+
this.appGitOwner = appGitOwnerId("event");
|
|
916
1444
|
this.buffers = /* @__PURE__ */ new Map();
|
|
917
1445
|
this.sticky = /* @__PURE__ */ new Map();
|
|
918
1446
|
this.timers = /* @__PURE__ */ new Map();
|
|
919
1447
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
920
1448
|
this.hasShutdown = false;
|
|
921
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
922
|
-
this.
|
|
923
|
-
this.
|
|
1449
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1450
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
1451
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
1452
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
1453
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
924
1454
|
this.enabled = opts.enabled !== false;
|
|
925
1455
|
this.debug = opts.debug;
|
|
926
|
-
this.partialFlushMs = (
|
|
927
|
-
this.sdkName = (
|
|
1456
|
+
this.partialFlushMs = (_d = opts.partialFlushMs) != null ? _d : 1e3;
|
|
1457
|
+
this.sdkName = (_e = opts.sdkName) != null ? _e : "core";
|
|
928
1458
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
929
|
-
this.defaultEventName = (
|
|
1459
|
+
this.defaultEventName = (_f = opts.defaultEventName) != null ? _f : "ai_generation";
|
|
930
1460
|
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
931
|
-
this.localDebuggerUrl = (
|
|
1461
|
+
this.localDebuggerUrl = (_g = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _g : void 0;
|
|
932
1462
|
if (this.debug && this.localDebuggerUrl) {
|
|
933
1463
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
934
1464
|
}
|
|
@@ -939,8 +1469,8 @@ var EventShipper = class {
|
|
|
939
1469
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
940
1470
|
this.context = {
|
|
941
1471
|
library: {
|
|
942
|
-
name: (
|
|
943
|
-
version: (
|
|
1472
|
+
name: (_h = opts.libraryName) != null ? _h : "@raindrop-ai/core",
|
|
1473
|
+
version: (_i = opts.libraryVersion) != null ? _i : "0.0.0"
|
|
944
1474
|
},
|
|
945
1475
|
metadata: {
|
|
946
1476
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -948,6 +1478,9 @@ var EventShipper = class {
|
|
|
948
1478
|
}
|
|
949
1479
|
};
|
|
950
1480
|
}
|
|
1481
|
+
ownAppGitContextForShutdown() {
|
|
1482
|
+
this.ownsAppGitContext = true;
|
|
1483
|
+
}
|
|
951
1484
|
isDebugEnabled() {
|
|
952
1485
|
return this.debug;
|
|
953
1486
|
}
|
|
@@ -1026,6 +1559,13 @@ var EventShipper = class {
|
|
|
1026
1559
|
}
|
|
1027
1560
|
const sticky = (_c = this.sticky.get(eventId)) != null ? _c : {};
|
|
1028
1561
|
const existing = (_d = this.buffers.get(eventId)) != null ? _d : {};
|
|
1562
|
+
patch = {
|
|
1563
|
+
...patch,
|
|
1564
|
+
properties: withAppGitProperties(
|
|
1565
|
+
patch.properties,
|
|
1566
|
+
this.appGitContext.forOperation(eventId, patch.properties, this.appGitOwner)
|
|
1567
|
+
)
|
|
1568
|
+
};
|
|
1029
1569
|
const merged = mergePatches(existing, patch);
|
|
1030
1570
|
merged.isPending = (_g = (_f = (_e = patch.isPending) != null ? _e : existing.isPending) != null ? _f : sticky.isPending) != null ? _g : true;
|
|
1031
1571
|
this.buffers.set(eventId, merged);
|
|
@@ -1039,6 +1579,8 @@ var EventShipper = class {
|
|
|
1039
1579
|
if (t) clearTimeout(t);
|
|
1040
1580
|
if (merged.isPending === false) {
|
|
1041
1581
|
await this.flushOne(eventId);
|
|
1582
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
1583
|
+
else this.appGitContext.finishOperation(eventId);
|
|
1042
1584
|
return;
|
|
1043
1585
|
}
|
|
1044
1586
|
const timeout = setTimeout(() => {
|
|
@@ -1070,6 +1612,7 @@ var EventShipper = class {
|
|
|
1070
1612
|
if (!settled) this.warnShutdownDrop("in-flight request(s) at shutdown");
|
|
1071
1613
|
} finally {
|
|
1072
1614
|
this.shutdownDeadlineAt = void 0;
|
|
1615
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1073
1616
|
}
|
|
1074
1617
|
}
|
|
1075
1618
|
async trackSignal(signal) {
|
|
@@ -1504,6 +2047,13 @@ function redactJsonAttributeValue(key, value) {
|
|
|
1504
2047
|
if (scrubbedJson === json) return void 0;
|
|
1505
2048
|
return { stringValue: scrubbedJson };
|
|
1506
2049
|
}
|
|
2050
|
+
function appGitOwnerId2(prefix) {
|
|
2051
|
+
try {
|
|
2052
|
+
return `${prefix}:${randomUUID()}`;
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
1507
2057
|
function identityAttrs(args) {
|
|
1508
2058
|
return [
|
|
1509
2059
|
attrString("ai.telemetry.metadata.raindrop.ai.userId", args.userId),
|
|
@@ -1526,23 +2076,30 @@ function applyOtelSpanAttributeLimit(limit) {
|
|
|
1526
2076
|
}
|
|
1527
2077
|
var TraceShipper = class {
|
|
1528
2078
|
constructor(opts) {
|
|
2079
|
+
this.appGitOwner = appGitOwnerId2("trace");
|
|
2080
|
+
this.appGitEventIds = /* @__PURE__ */ new WeakMap();
|
|
2081
|
+
this.appGitActiveSpans = /* @__PURE__ */ new Map();
|
|
2082
|
+
this.appGitCaptured = /* @__PURE__ */ new WeakSet();
|
|
2083
|
+
this.appGitAdded = /* @__PURE__ */ new WeakMap();
|
|
1529
2084
|
this.queue = [];
|
|
1530
2085
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
1531
2086
|
this.hasShutdown = false;
|
|
1532
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1533
|
-
this.
|
|
1534
|
-
this.
|
|
2087
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2088
|
+
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
2089
|
+
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
2090
|
+
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
2091
|
+
this.baseUrl = (_c = formatEndpoint(opts.endpoint)) != null ? _c : "https://api.raindrop.ai/v1/";
|
|
1535
2092
|
this.enabled = opts.enabled !== false;
|
|
1536
2093
|
this.debug = opts.debug;
|
|
1537
2094
|
this.debugSpans = opts.debugSpans === true;
|
|
1538
|
-
this.flushIntervalMs = (
|
|
1539
|
-
this.maxBatchSize = (
|
|
1540
|
-
this.maxQueueSize = (
|
|
1541
|
-
this.sdkName = (
|
|
2095
|
+
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
2096
|
+
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
2097
|
+
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
2098
|
+
this.sdkName = (_g = opts.sdkName) != null ? _g : "core";
|
|
1542
2099
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
1543
|
-
this.serviceName = (
|
|
1544
|
-
this.serviceVersion = (
|
|
1545
|
-
this.localDebuggerUrl = (
|
|
2100
|
+
this.serviceName = (_h = opts.serviceName) != null ? _h : "raindrop.core";
|
|
2101
|
+
this.serviceVersion = (_i = opts.serviceVersion) != null ? _i : "0.0.0";
|
|
2102
|
+
this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _j : void 0;
|
|
1546
2103
|
if (this.debug && this.localDebuggerUrl) {
|
|
1547
2104
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
1548
2105
|
}
|
|
@@ -1643,7 +2200,7 @@ var TraceShipper = class {
|
|
|
1643
2200
|
return { ...this.authHeaders(), ...projectIdHeaders(this.projectId) };
|
|
1644
2201
|
}
|
|
1645
2202
|
startSpan(args) {
|
|
1646
|
-
var _a, _b;
|
|
2203
|
+
var _a, _b, _c;
|
|
1647
2204
|
const ids = createSpanIds(args.parent);
|
|
1648
2205
|
const started = (_a = args.startTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1649
2206
|
const attrs = [
|
|
@@ -1653,13 +2210,24 @@ var TraceShipper = class {
|
|
|
1653
2210
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1654
2211
|
];
|
|
1655
2212
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
2213
|
+
const tracksAppGit = this.appGitActiveSpans.has(args.eventId) || this.appGitActiveSpans.size < 1e4;
|
|
2214
|
+
const appGitOverrides = appGitPropertiesFromAttributes(attrs);
|
|
1656
2215
|
const span = {
|
|
1657
2216
|
ids,
|
|
1658
2217
|
name: args.name,
|
|
1659
2218
|
startTimeUnixNano: started,
|
|
1660
|
-
attributes:
|
|
2219
|
+
attributes: withAppGitAttributes(
|
|
2220
|
+
attrs,
|
|
2221
|
+
this.appGitContext.forOperation(args.eventId, appGitOverrides, this.appGitOwner)
|
|
2222
|
+
)
|
|
1661
2223
|
};
|
|
1662
2224
|
rememberReplayTraceDestination(span);
|
|
2225
|
+
this.appGitCaptured.add(span);
|
|
2226
|
+
this.appGitEventIds.set(span, args.eventId);
|
|
2227
|
+
if (tracksAppGit) {
|
|
2228
|
+
this.appGitActiveSpans.set(args.eventId, ((_c = this.appGitActiveSpans.get(args.eventId)) != null ? _c : 0) + 1);
|
|
2229
|
+
}
|
|
2230
|
+
this.appGitAdded.set(span, new Set(span.attributes.filter((attr) => !attrs.includes(attr))));
|
|
1663
2231
|
const openSpan = buildOtlpSpan({
|
|
1664
2232
|
ids: span.ids,
|
|
1665
2233
|
name: span.name,
|
|
@@ -1699,11 +2267,17 @@ var TraceShipper = class {
|
|
|
1699
2267
|
});
|
|
1700
2268
|
}
|
|
1701
2269
|
endSpan(span, extra) {
|
|
1702
|
-
var _a, _b;
|
|
2270
|
+
var _a, _b, _c;
|
|
1703
2271
|
if (span.endTimeUnixNano) return;
|
|
1704
2272
|
span.endTimeUnixNano = (_a = extra == null ? void 0 : extra.endTimeUnixNano) != null ? _a : nowUnixNanoString();
|
|
1705
2273
|
if ((_b = extra == null ? void 0 : extra.attributes) == null ? void 0 : _b.length) {
|
|
2274
|
+
const overrides = appGitPropertiesFromAttributes(extra.attributes);
|
|
2275
|
+
const eventId2 = this.appGitEventIds.get(span);
|
|
2276
|
+
const snapshot = eventId2 ? this.appGitContext.forOperation(eventId2, overrides, this.appGitOwner) : overrides;
|
|
2277
|
+
const added = this.appGitAdded.get(span);
|
|
2278
|
+
span.attributes = span.attributes.filter((attr) => !(added == null ? void 0 : added.has(attr)) || !attr || !Object.prototype.hasOwnProperty.call(overrides, APP_COMMIT_SHA) && !Object.prototype.hasOwnProperty.call(overrides, attr.key));
|
|
1706
2279
|
span.attributes.push(...extra.attributes);
|
|
2280
|
+
span.attributes = withAppGitAttributes(span.attributes, snapshot);
|
|
1707
2281
|
}
|
|
1708
2282
|
let status = extra == null ? void 0 : extra.status;
|
|
1709
2283
|
if (!status && (extra == null ? void 0 : extra.error) !== void 0) {
|
|
@@ -1719,8 +2293,19 @@ var TraceShipper = class {
|
|
|
1719
2293
|
status
|
|
1720
2294
|
});
|
|
1721
2295
|
copyReplayTraceDestination(span, otlp);
|
|
2296
|
+
this.appGitCaptured.add(otlp);
|
|
1722
2297
|
this.enqueue(otlp);
|
|
1723
2298
|
this.mirrorToLocalDebugger(otlp, true);
|
|
2299
|
+
const eventId = this.appGitEventIds.get(span);
|
|
2300
|
+
if (eventId && this.appGitActiveSpans.has(eventId)) {
|
|
2301
|
+
const remaining = ((_c = this.appGitActiveSpans.get(eventId)) != null ? _c : 1) - 1;
|
|
2302
|
+
if (remaining > 0) this.appGitActiveSpans.set(eventId, remaining);
|
|
2303
|
+
else {
|
|
2304
|
+
this.appGitActiveSpans.delete(eventId);
|
|
2305
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(eventId, this.appGitOwner);
|
|
2306
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(eventId);
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
1724
2309
|
}
|
|
1725
2310
|
createSpan(args) {
|
|
1726
2311
|
var _a;
|
|
@@ -1731,20 +2316,41 @@ var TraceShipper = class {
|
|
|
1731
2316
|
...Object.entries(evalScopeAttributes()).map(([key, value]) => attrString(key, value))
|
|
1732
2317
|
];
|
|
1733
2318
|
if ((_a = args.attributes) == null ? void 0 : _a.length) attrs.push(...args.attributes);
|
|
2319
|
+
const tracksAppGit = !this.appGitActiveSpans.has(args.eventId);
|
|
1734
2320
|
const otlp = buildOtlpSpan({
|
|
1735
2321
|
ids,
|
|
1736
2322
|
name: args.name,
|
|
1737
2323
|
startTimeUnixNano: args.startTimeUnixNano,
|
|
1738
2324
|
endTimeUnixNano: args.endTimeUnixNano,
|
|
1739
|
-
attributes:
|
|
2325
|
+
attributes: withAppGitAttributes(
|
|
2326
|
+
attrs,
|
|
2327
|
+
this.appGitContext.forOperation(
|
|
2328
|
+
args.eventId,
|
|
2329
|
+
appGitPropertiesFromAttributes(attrs),
|
|
2330
|
+
this.appGitOwner
|
|
2331
|
+
)
|
|
2332
|
+
),
|
|
1740
2333
|
status: args.status
|
|
1741
2334
|
});
|
|
1742
2335
|
rememberReplayTraceDestination(otlp);
|
|
2336
|
+
this.appGitCaptured.add(otlp);
|
|
2337
|
+
if (tracksAppGit) {
|
|
2338
|
+
if (this.appGitContext.releaseOperation) this.appGitContext.releaseOperation(args.eventId, this.appGitOwner);
|
|
2339
|
+
else if (this.ownsAppGitContext) this.appGitContext.finishOperation(args.eventId);
|
|
2340
|
+
}
|
|
1743
2341
|
this.enqueue(otlp);
|
|
1744
2342
|
this.mirrorToLocalDebugger(otlp, true);
|
|
1745
2343
|
}
|
|
1746
2344
|
enqueue(span) {
|
|
2345
|
+
var _a;
|
|
1747
2346
|
if (!this.enabled) return;
|
|
2347
|
+
const attributes = (_a = span.attributes) != null ? _a : [];
|
|
2348
|
+
const enriched = this.appGitCaptured.has(span) ? attributes : withAppGitAttributes(attributes, this.appGitContext.snapshot(appGitPropertiesFromAttributes(attributes)));
|
|
2349
|
+
if (enriched !== attributes) {
|
|
2350
|
+
const original = span;
|
|
2351
|
+
span = { ...span, attributes: enriched.filter((attr) => attr !== void 0) };
|
|
2352
|
+
copyReplayTraceDestination(original, span);
|
|
2353
|
+
}
|
|
1748
2354
|
if (this.debugSpans) {
|
|
1749
2355
|
const short = (s) => s ? s.slice(-8) : "none";
|
|
1750
2356
|
console.log(
|
|
@@ -1890,127 +2496,305 @@ var TraceShipper = class {
|
|
|
1890
2496
|
}
|
|
1891
2497
|
} finally {
|
|
1892
2498
|
this.shutdownDeadlineAt = void 0;
|
|
2499
|
+
if (this.ownsAppGitContext) this.appGitContext.dispose();
|
|
1893
2500
|
}
|
|
1894
2501
|
}
|
|
1895
2502
|
};
|
|
1896
|
-
var
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
2503
|
+
var PROMPT_TOOLS_ATTRIBUTE = "ai.prompt.tools";
|
|
2504
|
+
function isRecord(value) {
|
|
2505
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2506
|
+
}
|
|
2507
|
+
var JSON_SCHEMA_KEYS = [
|
|
2508
|
+
"type",
|
|
2509
|
+
"properties",
|
|
2510
|
+
"$schema",
|
|
2511
|
+
"$ref",
|
|
2512
|
+
"anyOf",
|
|
2513
|
+
"oneOf",
|
|
2514
|
+
"allOf",
|
|
2515
|
+
"enum",
|
|
2516
|
+
"const",
|
|
2517
|
+
"items",
|
|
2518
|
+
"additionalProperties",
|
|
2519
|
+
"required"
|
|
2520
|
+
];
|
|
2521
|
+
function isJsonSchema(value) {
|
|
2522
|
+
if (!isRecord(value)) return false;
|
|
2523
|
+
if (typeof value["~standard"] === "object") return false;
|
|
2524
|
+
if (isRecord(value._def) || isRecord(value._zod)) return false;
|
|
2525
|
+
if (Object.keys(value).length === 0) return true;
|
|
2526
|
+
return JSON_SCHEMA_KEYS.some((key) => key in value);
|
|
2527
|
+
}
|
|
2528
|
+
function toJsonSchema(value, options) {
|
|
2529
|
+
if (value === void 0 || value === null) return void 0;
|
|
2530
|
+
if (isJsonSchema(value)) return value;
|
|
2531
|
+
if (isRecord(value) && isJsonSchema(value.jsonSchema)) return value.jsonSchema;
|
|
2532
|
+
if (isRecord(value) && isJsonSchema(value.json)) return value.json;
|
|
2533
|
+
if (options == null ? void 0 : options.schema) {
|
|
1918
2534
|
try {
|
|
1919
|
-
return
|
|
1920
|
-
}
|
|
1921
|
-
|
|
2535
|
+
return options.schema(value);
|
|
2536
|
+
} catch (e) {
|
|
2537
|
+
return void 0;
|
|
1922
2538
|
}
|
|
1923
2539
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2540
|
+
return void 0;
|
|
2541
|
+
}
|
|
2542
|
+
function pickString(value) {
|
|
2543
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
2544
|
+
}
|
|
2545
|
+
function functionTool(name, description, schema, options) {
|
|
2546
|
+
const tool = { type: "function", name };
|
|
2547
|
+
const desc = pickString(description);
|
|
2548
|
+
if (desc !== void 0) tool.description = desc;
|
|
2549
|
+
const inputSchema = toJsonSchema(schema, options);
|
|
2550
|
+
if (inputSchema !== void 0) tool.inputSchema = inputSchema;
|
|
2551
|
+
return tool;
|
|
2552
|
+
}
|
|
2553
|
+
function normalizeToolDeclaration(tool, options, fallbackName) {
|
|
2554
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2555
|
+
if (!isRecord(tool)) return void 0;
|
|
2556
|
+
if (tool.type === "provider-defined" || tool.type === "provider") {
|
|
2557
|
+
const name2 = (_b = (_a = pickString(tool.name)) != null ? _a : pickString(tool.id)) != null ? _b : fallbackName;
|
|
2558
|
+
if (name2 === void 0) return void 0;
|
|
2559
|
+
const declaration = { type: "provider-defined", name: name2 };
|
|
2560
|
+
const id = pickString(tool.id);
|
|
2561
|
+
if (id !== void 0) declaration.id = id;
|
|
2562
|
+
if (isRecord(tool.args)) declaration.args = tool.args;
|
|
2563
|
+
return declaration;
|
|
2564
|
+
}
|
|
2565
|
+
if (isRecord(tool.toolSpec)) {
|
|
2566
|
+
const spec = tool.toolSpec;
|
|
2567
|
+
const name2 = (_c = pickString(spec.name)) != null ? _c : fallbackName;
|
|
2568
|
+
if (name2 === void 0) return void 0;
|
|
2569
|
+
return functionTool(name2, spec.description, spec.inputSchema, options);
|
|
2570
|
+
}
|
|
2571
|
+
if (isRecord(tool.function)) {
|
|
2572
|
+
const fn = tool.function;
|
|
2573
|
+
const name2 = (_d = pickString(fn.name)) != null ? _d : fallbackName;
|
|
2574
|
+
if (name2 === void 0) return void 0;
|
|
2575
|
+
return functionTool(name2, fn.description, (_e = fn.parameters) != null ? _e : fn.input_schema, options);
|
|
2576
|
+
}
|
|
2577
|
+
const name = (_g = (_f = pickString(tool.name)) != null ? _f : pickString(tool.id)) != null ? _g : fallbackName;
|
|
2578
|
+
if (name === void 0) return void 0;
|
|
2579
|
+
const type = pickString(tool.type);
|
|
2580
|
+
if (type !== void 0 && type !== "function" && type !== "dynamic" && type !== "custom") {
|
|
2581
|
+
if (!("input_schema" in tool) && !("inputSchema" in tool) && !("parameters" in tool)) {
|
|
2582
|
+
return { type: "provider-defined", id: type, name };
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
return functionTool(
|
|
2586
|
+
name,
|
|
2587
|
+
tool.description,
|
|
2588
|
+
(_j = (_i = (_h = tool.inputSchema) != null ? _h : tool.input_schema) != null ? _i : tool.parameters) != null ? _j : tool.schema,
|
|
2589
|
+
options
|
|
2590
|
+
);
|
|
2591
|
+
}
|
|
2592
|
+
var NOT_A_GEMINI_GROUP_KEYS = ["name", "id", "type", "function", "toolSpec", "cachePoint"];
|
|
2593
|
+
function isGeminiToolGroup(tool) {
|
|
2594
|
+
if (Array.isArray(tool.functionDeclarations)) return true;
|
|
2595
|
+
const keys = Object.keys(tool);
|
|
2596
|
+
if (keys.length === 0 || NOT_A_GEMINI_GROUP_KEYS.some((key) => key in tool)) return false;
|
|
2597
|
+
return keys.every((key) => isRecord(tool[key]));
|
|
2598
|
+
}
|
|
2599
|
+
function expandGeminiTool(tool, options) {
|
|
2600
|
+
const declarations = [];
|
|
2601
|
+
for (const [key, value] of Object.entries(tool)) {
|
|
2602
|
+
if (key === "functionDeclarations" && Array.isArray(value)) {
|
|
2603
|
+
for (const declaration of value) {
|
|
2604
|
+
const normalized = normalizeToolDeclaration(declaration, options);
|
|
2605
|
+
if (normalized) declarations.push(normalized);
|
|
2606
|
+
}
|
|
2607
|
+
} else if (isRecord(value)) {
|
|
2608
|
+
declarations.push({ type: "provider-defined", id: key, name: key, args: value });
|
|
1935
2609
|
}
|
|
1936
|
-
this._fallback = new SynchronousContextStorage();
|
|
1937
|
-
this._storage = this._fallback;
|
|
1938
|
-
}
|
|
1939
|
-
maybeAdoptAsyncLocalStorage() {
|
|
1940
|
-
if (!this._fallback || !this._fallback.isEmpty()) return;
|
|
1941
|
-
const Ctor = getAsyncLocalStorageCtor();
|
|
1942
|
-
if (!Ctor) return;
|
|
1943
|
-
this._storage = new Ctor();
|
|
1944
|
-
this._fallback = null;
|
|
1945
|
-
}
|
|
1946
|
-
isReady() {
|
|
1947
|
-
return true;
|
|
1948
|
-
}
|
|
1949
|
-
getParentSpanIds() {
|
|
1950
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1951
|
-
const span = this._storage.getStore();
|
|
1952
|
-
if (!span || span === NOOP_SPAN) return void 0;
|
|
1953
|
-
return {
|
|
1954
|
-
traceIdB64: span.traceIdB64,
|
|
1955
|
-
spanIdB64: span.spanIdB64,
|
|
1956
|
-
eventId: span.eventId
|
|
1957
|
-
};
|
|
1958
|
-
}
|
|
1959
|
-
runInContext(span, callback) {
|
|
1960
|
-
this.maybeAdoptAsyncLocalStorage();
|
|
1961
|
-
return this._storage.run(span, callback);
|
|
1962
2610
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
2611
|
+
return declarations;
|
|
2612
|
+
}
|
|
2613
|
+
function normalizeToolDeclarations(tools, options) {
|
|
2614
|
+
if (tools === void 0 || tools === null) return void 0;
|
|
2615
|
+
if (Array.isArray(tools)) {
|
|
2616
|
+
return tools.flatMap((tool) => {
|
|
2617
|
+
if (isRecord(tool) && isGeminiToolGroup(tool)) {
|
|
2618
|
+
return expandGeminiTool(tool, options);
|
|
2619
|
+
}
|
|
2620
|
+
const declaration = normalizeToolDeclaration(tool, options);
|
|
2621
|
+
return declaration ? [declaration] : [];
|
|
2622
|
+
});
|
|
1972
2623
|
}
|
|
1973
|
-
return
|
|
2624
|
+
if (!isRecord(tools)) return void 0;
|
|
2625
|
+
return Object.entries(tools).flatMap(([key, tool]) => {
|
|
2626
|
+
const declaration = normalizeToolDeclaration(tool, options, key);
|
|
2627
|
+
return declaration ? [declaration] : [];
|
|
2628
|
+
});
|
|
1974
2629
|
}
|
|
1975
|
-
function
|
|
2630
|
+
function resolvePromptTools(args) {
|
|
1976
2631
|
var _a;
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
return
|
|
1981
|
-
}
|
|
1982
|
-
async function getCurrentParentSpanContext() {
|
|
1983
|
-
var _a, _b;
|
|
1984
|
-
return (_b = getContextManager().getParentSpanIds()) != null ? _b : (_a = currentReplayTraceDestination()) == null ? void 0 : _a.parentSpanContext;
|
|
2632
|
+
if (args.override !== void 0) {
|
|
2633
|
+
return (_a = normalizeToolDeclarations(args.override, args.options)) != null ? _a : [];
|
|
2634
|
+
}
|
|
2635
|
+
return normalizeToolDeclarations(args.inferred, args.options);
|
|
1985
2636
|
}
|
|
1986
|
-
|
|
1987
|
-
const
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2637
|
+
function promptToolsAttribute(tools) {
|
|
2638
|
+
const values = promptToolsAttributeValue(tools);
|
|
2639
|
+
if (values === void 0) return void 0;
|
|
2640
|
+
return {
|
|
2641
|
+
key: PROMPT_TOOLS_ATTRIBUTE,
|
|
2642
|
+
value: { arrayValue: { values: values.map((stringValue) => ({ stringValue })) } }
|
|
1992
2643
|
};
|
|
1993
|
-
return cm.runInContext(span, fn);
|
|
1994
2644
|
}
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2645
|
+
function promptToolsAttributeValue(tools) {
|
|
2646
|
+
if (tools === void 0) return void 0;
|
|
2647
|
+
return tools.map((tool) => {
|
|
2648
|
+
try {
|
|
2649
|
+
return JSON.stringify(tool);
|
|
2650
|
+
} catch (e) {
|
|
2651
|
+
return JSON.stringify({ type: tool.type, name: tool.name });
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
var resolveLocal = (sourceDirectory, detectBranch, completed) => {
|
|
2656
|
+
const cwd = sourceDirectory ? resolve(sourceDirectory) : process.cwd();
|
|
2657
|
+
let cancelled = false;
|
|
2658
|
+
let active;
|
|
2659
|
+
let deadlineTimer;
|
|
2660
|
+
const deadline = Date.now() + 1e3;
|
|
2661
|
+
const run = (args, done) => {
|
|
2662
|
+
if (cancelled) return;
|
|
2663
|
+
const remaining = deadline - Date.now();
|
|
2664
|
+
if (remaining <= 0) {
|
|
2665
|
+
done(void 0);
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
try {
|
|
2669
|
+
active = execFile(
|
|
2670
|
+
"git",
|
|
2671
|
+
args,
|
|
2672
|
+
{
|
|
2673
|
+
cwd,
|
|
2674
|
+
encoding: "utf8",
|
|
2675
|
+
maxBuffer: 4096,
|
|
2676
|
+
windowsHide: true,
|
|
2677
|
+
env: {
|
|
2678
|
+
...process.env,
|
|
2679
|
+
// The selected application cwd, not the invoking shell's Git plumbing, owns identity.
|
|
2680
|
+
GIT_DIR: void 0,
|
|
2681
|
+
GIT_WORK_TREE: void 0,
|
|
2682
|
+
GIT_COMMON_DIR: void 0,
|
|
2683
|
+
GIT_NAMESPACE: void 0,
|
|
2684
|
+
GIT_INDEX_FILE: void 0,
|
|
2685
|
+
GIT_OBJECT_DIRECTORY: void 0,
|
|
2686
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: void 0,
|
|
2687
|
+
GIT_CONFIG_PARAMETERS: void 0,
|
|
2688
|
+
GIT_CONFIG_COUNT: "0",
|
|
2689
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
2690
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
2691
|
+
}
|
|
2692
|
+
},
|
|
2693
|
+
(error, stdout) => {
|
|
2694
|
+
clearTimeout(deadlineTimer);
|
|
2695
|
+
deadlineTimer = void 0;
|
|
2696
|
+
active = void 0;
|
|
2697
|
+
if (!cancelled) {
|
|
2698
|
+
try {
|
|
2699
|
+
done(error ? void 0 : stdout.trim());
|
|
2700
|
+
} catch (e) {
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
);
|
|
2705
|
+
active.unref();
|
|
2706
|
+
if (active.stdout && "unref" in active.stdout && typeof active.stdout.unref === "function")
|
|
2707
|
+
active.stdout.unref();
|
|
2708
|
+
if (active.stderr && "unref" in active.stderr && typeof active.stderr.unref === "function")
|
|
2709
|
+
active.stderr.unref();
|
|
2710
|
+
deadlineTimer = setTimeout(() => {
|
|
2711
|
+
try {
|
|
2712
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2713
|
+
} catch (e) {
|
|
2714
|
+
}
|
|
2715
|
+
}, remaining);
|
|
2716
|
+
deadlineTimer.unref();
|
|
2717
|
+
} catch (e) {
|
|
1999
2718
|
try {
|
|
2000
|
-
|
|
2001
|
-
} catch (
|
|
2002
|
-
return { value: void 0, done: true, error: e };
|
|
2719
|
+
done(void 0);
|
|
2720
|
+
} catch (e2) {
|
|
2003
2721
|
}
|
|
2004
|
-
});
|
|
2005
|
-
if ("error" in result && result.error !== void 0) {
|
|
2006
|
-
throw result.error;
|
|
2007
2722
|
}
|
|
2008
|
-
|
|
2009
|
-
|
|
2723
|
+
};
|
|
2724
|
+
const scheduled = setTimeout(() => {
|
|
2725
|
+
try {
|
|
2726
|
+
run(["rev-parse", "HEAD"], (rawSha) => {
|
|
2727
|
+
const commitSha = validAppCommitSha(rawSha);
|
|
2728
|
+
if (!commitSha) {
|
|
2729
|
+
completed({});
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
run(["-c", "core.fsmonitor=false", "status", "--porcelain"], (status) => {
|
|
2733
|
+
const finish = (branch) => {
|
|
2734
|
+
run(["rev-parse", "HEAD"], (finalSha) => {
|
|
2735
|
+
const coherent = validAppCommitSha(finalSha) === commitSha;
|
|
2736
|
+
completed({
|
|
2737
|
+
commitSha,
|
|
2738
|
+
...coherent && status !== void 0 ? { commitDirty: status !== "" } : {},
|
|
2739
|
+
...coherent && branch && branch !== "HEAD" ? { branch } : {}
|
|
2740
|
+
});
|
|
2741
|
+
});
|
|
2742
|
+
};
|
|
2743
|
+
if (detectBranch) run(["symbolic-ref", "--quiet", "--short", "HEAD"], finish);
|
|
2744
|
+
else finish();
|
|
2745
|
+
});
|
|
2746
|
+
});
|
|
2747
|
+
} catch (e) {
|
|
2748
|
+
completed({});
|
|
2749
|
+
}
|
|
2750
|
+
}, 0);
|
|
2751
|
+
scheduled.unref();
|
|
2752
|
+
return () => {
|
|
2753
|
+
cancelled = true;
|
|
2754
|
+
clearTimeout(scheduled);
|
|
2755
|
+
clearTimeout(deadlineTimer);
|
|
2756
|
+
try {
|
|
2757
|
+
active == null ? void 0 : active.kill("SIGKILL");
|
|
2758
|
+
} catch (e) {
|
|
2010
2759
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2760
|
+
};
|
|
2761
|
+
};
|
|
2762
|
+
function createAppGitContext2(options, runtime = {}) {
|
|
2763
|
+
return new AppGitContext(options, { ...runtime, resolveLocal });
|
|
2764
|
+
}
|
|
2765
|
+
function hasDestination(options) {
|
|
2766
|
+
var _a;
|
|
2767
|
+
if (options.enabled === false) return false;
|
|
2768
|
+
return Boolean(((_a = options.writeKey) == null ? void 0 : _a.trim()) || resolveLocalDebuggerBaseUrl(options.localDebuggerUrl));
|
|
2013
2769
|
}
|
|
2770
|
+
var EventShipper2 = class extends EventShipper {
|
|
2771
|
+
constructor(options) {
|
|
2772
|
+
var _a;
|
|
2773
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2774
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2775
|
+
try {
|
|
2776
|
+
super({ ...options, appGitContext });
|
|
2777
|
+
} catch (error) {
|
|
2778
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2779
|
+
throw error;
|
|
2780
|
+
}
|
|
2781
|
+
if (ownsAppGitContext) this.ownAppGitContextForShutdown();
|
|
2782
|
+
}
|
|
2783
|
+
};
|
|
2784
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
2785
|
+
constructor(options) {
|
|
2786
|
+
var _a;
|
|
2787
|
+
const ownsAppGitContext = options.appGitContext === void 0;
|
|
2788
|
+
const appGitContext = (_a = options.appGitContext) != null ? _a : createAppGitContext2(options.appGit, { allowDiscovery: hasDestination(options) });
|
|
2789
|
+
try {
|
|
2790
|
+
super({ ...options, appGitContext });
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
if (ownsAppGitContext) appGitContext.dispose();
|
|
2793
|
+
throw error;
|
|
2794
|
+
}
|
|
2795
|
+
this.ownsAppGitContext = ownsAppGitContext;
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2014
2798
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
2015
2799
|
var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
|
|
2016
2800
|
"OpenTelemetry SDK Context Key SUPPRESS_TRACING"
|
|
@@ -2166,7 +2950,7 @@ function boundedStringify(value, limit) {
|
|
|
2166
2950
|
}
|
|
2167
2951
|
|
|
2168
2952
|
// src/internal/wrap/helpers.ts
|
|
2169
|
-
function
|
|
2953
|
+
function isRecord2(value) {
|
|
2170
2954
|
return typeof value === "object" && value !== null;
|
|
2171
2955
|
}
|
|
2172
2956
|
function isFunction(value) {
|
|
@@ -2205,7 +2989,7 @@ function extractModelInfo(model) {
|
|
|
2205
2989
|
}
|
|
2206
2990
|
return { modelId: model };
|
|
2207
2991
|
}
|
|
2208
|
-
if (!
|
|
2992
|
+
if (!isRecord2(model)) return {};
|
|
2209
2993
|
const provider = typeof model["provider"] === "string" ? model["provider"] : void 0;
|
|
2210
2994
|
let modelIdRaw;
|
|
2211
2995
|
if (typeof model["modelId"] === "string") {
|
|
@@ -2226,13 +3010,13 @@ function extractModelInfo(model) {
|
|
|
2226
3010
|
return { provider, modelId: modelIdRaw };
|
|
2227
3011
|
}
|
|
2228
3012
|
function extractTextOutput(result) {
|
|
2229
|
-
if (!
|
|
3013
|
+
if (!isRecord2(result)) return void 0;
|
|
2230
3014
|
const text = result["text"];
|
|
2231
3015
|
return typeof text === "string" ? text : void 0;
|
|
2232
3016
|
}
|
|
2233
3017
|
function extractObjectOutput(result) {
|
|
2234
3018
|
var _a;
|
|
2235
|
-
if (!
|
|
3019
|
+
if (!isRecord2(result)) return void 0;
|
|
2236
3020
|
const obj = result["object"];
|
|
2237
3021
|
if (obj === void 0) return void 0;
|
|
2238
3022
|
return (_a = safeJson(obj)) != null ? _a : String(obj);
|
|
@@ -2240,24 +3024,24 @@ function extractObjectOutput(result) {
|
|
|
2240
3024
|
function isAgentClass(value) {
|
|
2241
3025
|
if (typeof value !== "function") return false;
|
|
2242
3026
|
const proto = value.prototype;
|
|
2243
|
-
if (!
|
|
3027
|
+
if (!isRecord2(proto)) return false;
|
|
2244
3028
|
return typeof proto["generate"] === "function" && typeof proto["stream"] === "function";
|
|
2245
3029
|
}
|
|
2246
3030
|
function extractModel(result) {
|
|
2247
|
-
if (!
|
|
3031
|
+
if (!isRecord2(result)) return void 0;
|
|
2248
3032
|
const model = result["model"];
|
|
2249
3033
|
if (typeof model === "string" && model.length) return model;
|
|
2250
3034
|
const response = result["response"];
|
|
2251
|
-
if (
|
|
3035
|
+
if (isRecord2(response)) {
|
|
2252
3036
|
const modelId = response["modelId"];
|
|
2253
3037
|
if (typeof modelId === "string" && modelId.length) return modelId;
|
|
2254
3038
|
}
|
|
2255
3039
|
return void 0;
|
|
2256
3040
|
}
|
|
2257
3041
|
function extractFinishReason(result) {
|
|
2258
|
-
if (!
|
|
3042
|
+
if (!isRecord2(result)) return void 0;
|
|
2259
3043
|
if (typeof result["finishReason"] === "string") return result["finishReason"];
|
|
2260
|
-
if (
|
|
3044
|
+
if (isRecord2(result["finishReason"]) && typeof result["finishReason"]["unified"] === "string") {
|
|
2261
3045
|
return result["finishReason"]["unified"];
|
|
2262
3046
|
}
|
|
2263
3047
|
return void 0;
|
|
@@ -2301,7 +3085,7 @@ function attachmentMediaType(part) {
|
|
|
2301
3085
|
if (typeof part["mediaType"] === "string") return part["mediaType"];
|
|
2302
3086
|
if (typeof part["mimeType"] === "string") return part["mimeType"];
|
|
2303
3087
|
const file = part["file"];
|
|
2304
|
-
if (
|
|
3088
|
+
if (isRecord2(file)) {
|
|
2305
3089
|
if (typeof file["mediaType"] === "string") return file["mediaType"];
|
|
2306
3090
|
if (typeof file["mimeType"] === "string") return file["mimeType"];
|
|
2307
3091
|
}
|
|
@@ -2311,7 +3095,7 @@ function attachmentName(part) {
|
|
|
2311
3095
|
if (typeof part["filename"] === "string") return part["filename"];
|
|
2312
3096
|
if (typeof part["name"] === "string") return part["name"];
|
|
2313
3097
|
const file = part["file"];
|
|
2314
|
-
if (
|
|
3098
|
+
if (isRecord2(file)) {
|
|
2315
3099
|
if (typeof file["filename"] === "string") return file["filename"];
|
|
2316
3100
|
if (typeof file["name"] === "string") return file["name"];
|
|
2317
3101
|
}
|
|
@@ -2320,7 +3104,7 @@ function attachmentName(part) {
|
|
|
2320
3104
|
function attachmentData(part) {
|
|
2321
3105
|
if ("data" in part) return part["data"];
|
|
2322
3106
|
const file = part["file"];
|
|
2323
|
-
if (
|
|
3107
|
+
if (isRecord2(file)) {
|
|
2324
3108
|
if ("file_data" in file) return file["file_data"];
|
|
2325
3109
|
if ("data" in file) return file["data"];
|
|
2326
3110
|
}
|
|
@@ -2338,7 +3122,7 @@ function contentPartToAttachment(part, role) {
|
|
|
2338
3122
|
}
|
|
2339
3123
|
if (partType === "image_url") {
|
|
2340
3124
|
const imageUrlPart = part["image_url"];
|
|
2341
|
-
const imageUrlValue =
|
|
3125
|
+
const imageUrlValue = isRecord2(imageUrlPart) ? imageUrlPart["url"] : imageUrlPart;
|
|
2342
3126
|
const value = asDataUrl(imageUrlValue, "image/png");
|
|
2343
3127
|
if (!value) return void 0;
|
|
2344
3128
|
return { type: "image", role, value };
|
|
@@ -2358,7 +3142,7 @@ function attachmentsFromContent(content, role) {
|
|
|
2358
3142
|
if (!Array.isArray(content)) return void 0;
|
|
2359
3143
|
const attachments = [];
|
|
2360
3144
|
for (const part of content) {
|
|
2361
|
-
if (!
|
|
3145
|
+
if (!isRecord2(part)) continue;
|
|
2362
3146
|
const attachment = contentPartToAttachment(part, role);
|
|
2363
3147
|
if (attachment) attachments.push(attachment);
|
|
2364
3148
|
}
|
|
@@ -2391,7 +3175,7 @@ async function outputAttachmentsFromFiles(files) {
|
|
|
2391
3175
|
if (!Array.isArray(resolvedFiles)) return void 0;
|
|
2392
3176
|
const attachments = [];
|
|
2393
3177
|
for (const file of resolvedFiles) {
|
|
2394
|
-
if (!
|
|
3178
|
+
if (!isRecord2(file)) continue;
|
|
2395
3179
|
const attachment = generatedFileToAttachment(file);
|
|
2396
3180
|
if (attachment) attachments.push(attachment);
|
|
2397
3181
|
}
|
|
@@ -2402,7 +3186,7 @@ function extractTextFromMessageContent(content) {
|
|
|
2402
3186
|
if (!Array.isArray(content)) return void 0;
|
|
2403
3187
|
let result = "";
|
|
2404
3188
|
for (const part of content) {
|
|
2405
|
-
if (!
|
|
3189
|
+
if (!isRecord2(part) || part["type"] !== "text" || typeof part["text"] !== "string") continue;
|
|
2406
3190
|
result += part["text"];
|
|
2407
3191
|
}
|
|
2408
3192
|
return result.length ? result : void 0;
|
|
@@ -2419,7 +3203,7 @@ function lastUserMessageFromArgs(args) {
|
|
|
2419
3203
|
if (!messages) return void 0;
|
|
2420
3204
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2421
3205
|
const message = messages[i];
|
|
2422
|
-
if (
|
|
3206
|
+
if (isRecord2(message) && message["role"] === "user") {
|
|
2423
3207
|
return message;
|
|
2424
3208
|
}
|
|
2425
3209
|
}
|
|
@@ -2427,24 +3211,24 @@ function lastUserMessageFromArgs(args) {
|
|
|
2427
3211
|
}
|
|
2428
3212
|
function extractInputAttachmentsFromArgs(args) {
|
|
2429
3213
|
var _a;
|
|
2430
|
-
if (!
|
|
3214
|
+
if (!isRecord2(args)) return void 0;
|
|
2431
3215
|
return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
|
|
2432
3216
|
}
|
|
2433
3217
|
async function extractOutputAttachmentsFromResult(result) {
|
|
2434
|
-
if (!
|
|
3218
|
+
if (!isRecord2(result)) return void 0;
|
|
2435
3219
|
const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
|
|
2436
3220
|
if (fileAttachments == null ? void 0 : fileAttachments.length) return fileAttachments;
|
|
2437
3221
|
const responseMessages = extractResponseMessages(result);
|
|
2438
3222
|
for (let i = responseMessages.length - 1; i >= 0; i--) {
|
|
2439
3223
|
const message = responseMessages[i];
|
|
2440
|
-
if (!
|
|
3224
|
+
if (!isRecord2(message) || message["role"] !== "assistant") continue;
|
|
2441
3225
|
return attachmentsFromContent(message["content"], "output");
|
|
2442
3226
|
}
|
|
2443
3227
|
return attachmentsFromContent(result["content"], "output");
|
|
2444
3228
|
}
|
|
2445
3229
|
function lastUserMessageTextFromArgs(args) {
|
|
2446
3230
|
var _a, _b;
|
|
2447
|
-
if (!
|
|
3231
|
+
if (!isRecord2(args)) return void 0;
|
|
2448
3232
|
const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
|
|
2449
3233
|
if (content === void 0) return void 0;
|
|
2450
3234
|
const text = extractTextFromMessageContent(content);
|
|
@@ -2453,13 +3237,13 @@ function lastUserMessageTextFromArgs(args) {
|
|
|
2453
3237
|
}
|
|
2454
3238
|
function extractInputFromArgs(args) {
|
|
2455
3239
|
var _a;
|
|
2456
|
-
if (!
|
|
3240
|
+
if (!isRecord2(args)) return void 0;
|
|
2457
3241
|
const prompt = args["prompt"];
|
|
2458
3242
|
if (typeof prompt === "string") return prompt;
|
|
2459
3243
|
const messages = messagesFromArgs(args);
|
|
2460
3244
|
if (Array.isArray(messages) && messages.length > 0) {
|
|
2461
3245
|
const last = messages[messages.length - 1];
|
|
2462
|
-
if (
|
|
3246
|
+
if (isRecord2(last)) {
|
|
2463
3247
|
const content = last["content"];
|
|
2464
3248
|
const text = extractTextFromMessageContent(content);
|
|
2465
3249
|
if (text !== void 0) return text;
|
|
@@ -2473,7 +3257,7 @@ function extractInputFromArgs(args) {
|
|
|
2473
3257
|
return safeJson(args);
|
|
2474
3258
|
}
|
|
2475
3259
|
function coerceMessagesFromArgs(args) {
|
|
2476
|
-
if (!
|
|
3260
|
+
if (!isRecord2(args)) return [];
|
|
2477
3261
|
const result = [];
|
|
2478
3262
|
if (typeof args["system"] === "string" && args["system"]) {
|
|
2479
3263
|
result.push({ role: "system", content: args["system"] });
|
|
@@ -2481,7 +3265,7 @@ function coerceMessagesFromArgs(args) {
|
|
|
2481
3265
|
const messages = messagesFromArgs(args);
|
|
2482
3266
|
if (Array.isArray(messages)) {
|
|
2483
3267
|
for (const message of messages) {
|
|
2484
|
-
if (
|
|
3268
|
+
if (isRecord2(message) && typeof message["role"] === "string") {
|
|
2485
3269
|
result.push(message);
|
|
2486
3270
|
}
|
|
2487
3271
|
}
|
|
@@ -2493,21 +3277,21 @@ function coerceMessagesFromArgs(args) {
|
|
|
2493
3277
|
return result;
|
|
2494
3278
|
}
|
|
2495
3279
|
function extractResponseMessages(result) {
|
|
2496
|
-
if (!
|
|
3280
|
+
if (!isRecord2(result)) return [];
|
|
2497
3281
|
const response = result["response"];
|
|
2498
|
-
if (
|
|
3282
|
+
if (isRecord2(response) && Array.isArray(response["messages"])) {
|
|
2499
3283
|
return response["messages"].filter(
|
|
2500
|
-
(message) =>
|
|
3284
|
+
(message) => isRecord2(message) && typeof message["role"] === "string" && "content" in message
|
|
2501
3285
|
).map((message) => message);
|
|
2502
3286
|
}
|
|
2503
3287
|
const steps = result["steps"];
|
|
2504
3288
|
if (Array.isArray(steps) && steps.length > 0) {
|
|
2505
3289
|
const lastStep = steps[steps.length - 1];
|
|
2506
|
-
if (
|
|
3290
|
+
if (isRecord2(lastStep) && isRecord2(lastStep["response"])) {
|
|
2507
3291
|
const responseMessages = lastStep["response"]["messages"];
|
|
2508
3292
|
if (Array.isArray(responseMessages)) {
|
|
2509
3293
|
return responseMessages.filter(
|
|
2510
|
-
(message) =>
|
|
3294
|
+
(message) => isRecord2(message) && typeof message["role"] === "string" && "content" in message
|
|
2511
3295
|
).map((message) => message);
|
|
2512
3296
|
}
|
|
2513
3297
|
}
|
|
@@ -2528,7 +3312,7 @@ function isTranscriptToolResultError(part, result) {
|
|
|
2528
3312
|
if (part["isError"] === true || part["type"] === "tool-error") {
|
|
2529
3313
|
return true;
|
|
2530
3314
|
}
|
|
2531
|
-
if (
|
|
3315
|
+
if (isRecord2(result) && typeof result["type"] === "string") {
|
|
2532
3316
|
return result["type"].startsWith("error") || result["type"] === "execution-denied";
|
|
2533
3317
|
}
|
|
2534
3318
|
return false;
|
|
@@ -2537,7 +3321,7 @@ function getTranscriptToolErrorMessage(result) {
|
|
|
2537
3321
|
if (typeof result === "string" && result.length > 0) {
|
|
2538
3322
|
return result;
|
|
2539
3323
|
}
|
|
2540
|
-
if (
|
|
3324
|
+
if (isRecord2(result)) {
|
|
2541
3325
|
if (typeof result["value"] === "string" && result["value"].length > 0) {
|
|
2542
3326
|
return result["value"];
|
|
2543
3327
|
}
|
|
@@ -2551,12 +3335,12 @@ function getTranscriptToolErrorMessage(result) {
|
|
|
2551
3335
|
return safeJsonWithUint8(result);
|
|
2552
3336
|
}
|
|
2553
3337
|
function getTranscriptMessageParts(message) {
|
|
2554
|
-
if (!
|
|
3338
|
+
if (!isRecord2(message)) return [];
|
|
2555
3339
|
const content = message["content"];
|
|
2556
3340
|
if (Array.isArray(content)) {
|
|
2557
|
-
return content.filter(
|
|
3341
|
+
return content.filter(isRecord2);
|
|
2558
3342
|
}
|
|
2559
|
-
return
|
|
3343
|
+
return isRecord2(content) ? [content] : [];
|
|
2560
3344
|
}
|
|
2561
3345
|
function getTranscriptToolCallInput(part) {
|
|
2562
3346
|
return "input" in part ? part["input"] : "args" in part ? part["args"] : void 0;
|
|
@@ -2657,7 +3441,7 @@ function extractTextFromLmContent(content) {
|
|
|
2657
3441
|
if (!Array.isArray(content)) return void 0;
|
|
2658
3442
|
let result = "";
|
|
2659
3443
|
for (const part of content) {
|
|
2660
|
-
if (
|
|
3444
|
+
if (isRecord2(part) && part["type"] === "text" && typeof part["text"] === "string") {
|
|
2661
3445
|
result += part["text"];
|
|
2662
3446
|
}
|
|
2663
3447
|
}
|
|
@@ -2667,7 +3451,7 @@ function extractToolCallsFromLmContent(content) {
|
|
|
2667
3451
|
if (!Array.isArray(content)) return void 0;
|
|
2668
3452
|
const calls = [];
|
|
2669
3453
|
for (const part of content) {
|
|
2670
|
-
if (!
|
|
3454
|
+
if (!isRecord2(part) || part["type"] !== "tool-call") continue;
|
|
2671
3455
|
const toolCallId = getTranscriptToolCallId(part);
|
|
2672
3456
|
const toolName = typeof part["toolName"] === "string" ? part["toolName"] : void 0;
|
|
2673
3457
|
if (toolCallId || toolName) {
|
|
@@ -2677,15 +3461,15 @@ function extractToolCallsFromLmContent(content) {
|
|
|
2677
3461
|
return calls.length ? calls : void 0;
|
|
2678
3462
|
}
|
|
2679
3463
|
function extractExperimentalTelemetry(args) {
|
|
2680
|
-
if (!
|
|
3464
|
+
if (!isRecord2(args)) return void 0;
|
|
2681
3465
|
const telemetryConfig = args["experimental_telemetry"];
|
|
2682
|
-
if (!
|
|
3466
|
+
if (!isRecord2(telemetryConfig)) return void 0;
|
|
2683
3467
|
return {
|
|
2684
3468
|
functionId: typeof telemetryConfig["functionId"] === "string" ? telemetryConfig["functionId"] : void 0,
|
|
2685
3469
|
isEnabled: typeof telemetryConfig["isEnabled"] === "boolean" ? telemetryConfig["isEnabled"] : void 0,
|
|
2686
3470
|
recordInputs: typeof telemetryConfig["recordInputs"] === "boolean" ? telemetryConfig["recordInputs"] : void 0,
|
|
2687
3471
|
recordOutputs: typeof telemetryConfig["recordOutputs"] === "boolean" ? telemetryConfig["recordOutputs"] : void 0,
|
|
2688
|
-
metadata:
|
|
3472
|
+
metadata: isRecord2(telemetryConfig["metadata"]) ? telemetryConfig["metadata"] : void 0
|
|
2689
3473
|
};
|
|
2690
3474
|
}
|
|
2691
3475
|
function opName(operationId, functionId) {
|
|
@@ -2713,7 +3497,7 @@ function attrsFromTelemetryMetadata(metadata) {
|
|
|
2713
3497
|
});
|
|
2714
3498
|
}
|
|
2715
3499
|
function attrsFromHeaders(headers) {
|
|
2716
|
-
if (!
|
|
3500
|
+
if (!isRecord2(headers)) return [];
|
|
2717
3501
|
return Object.entries(headers).filter(([, v]) => typeof v === "string").map(([k, v]) => attrString(`ai.request.headers.${k}`, v));
|
|
2718
3502
|
}
|
|
2719
3503
|
function attrsFromModelProvider(provider) {
|
|
@@ -2726,7 +3510,7 @@ function attrsFromModelProvider(provider) {
|
|
|
2726
3510
|
];
|
|
2727
3511
|
}
|
|
2728
3512
|
function attrsFromSettings(args) {
|
|
2729
|
-
if (!
|
|
3513
|
+
if (!isRecord2(args)) return [];
|
|
2730
3514
|
const result = [];
|
|
2731
3515
|
const settingKeys = [
|
|
2732
3516
|
"maxRetries",
|
|
@@ -2754,7 +3538,7 @@ function attrsFromSettings(args) {
|
|
|
2754
3538
|
return result;
|
|
2755
3539
|
}
|
|
2756
3540
|
function attrsFromGenAiRequest(options) {
|
|
2757
|
-
if (!
|
|
3541
|
+
if (!isRecord2(options)) return [];
|
|
2758
3542
|
return [
|
|
2759
3543
|
attrDouble(
|
|
2760
3544
|
"gen_ai.request.frequency_penalty",
|
|
@@ -2784,7 +3568,7 @@ function attrsFromGenAiRequest(options) {
|
|
|
2784
3568
|
];
|
|
2785
3569
|
}
|
|
2786
3570
|
function attrProviderOptions(options) {
|
|
2787
|
-
if (!
|
|
3571
|
+
if (!isRecord2(options) || !isRecord2(options["providerOptions"])) return void 0;
|
|
2788
3572
|
const json = safeJsonWithUint8(options["providerOptions"]);
|
|
2789
3573
|
return json ? attrString("ai.request.providerOptions", json) : void 0;
|
|
2790
3574
|
}
|
|
@@ -2826,10 +3610,10 @@ function readRaindropCallMetadataFromArgs(args) {
|
|
|
2826
3610
|
var _a;
|
|
2827
3611
|
if (args.length === 0) return void 0;
|
|
2828
3612
|
const first = args[0];
|
|
2829
|
-
if (!
|
|
2830
|
-
const topLevel =
|
|
2831
|
-
const stable =
|
|
2832
|
-
const stableMetadata =
|
|
3613
|
+
if (!isRecord2(first)) return void 0;
|
|
3614
|
+
const topLevel = isRecord2(first["metadata"]) ? first["metadata"] : void 0;
|
|
3615
|
+
const stable = isRecord2(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
|
|
3616
|
+
const stableMetadata = isRecord2(stable) ? stable : void 0;
|
|
2833
3617
|
const exp = extractExperimentalTelemetry(first);
|
|
2834
3618
|
const expMetadata = (exp == null ? void 0 : exp.metadata) && typeof exp.metadata === "object" ? exp.metadata : void 0;
|
|
2835
3619
|
const raw = (_a = topLevel != null ? topLevel : stableMetadata) != null ? _a : expMetadata;
|
|
@@ -3269,38 +4053,38 @@ var CACHE_WRITE_METADATA_KEYS = [
|
|
|
3269
4053
|
["bedrock", "cacheWriteInputTokens"]
|
|
3270
4054
|
];
|
|
3271
4055
|
function cacheWriteTokensFromProviderMetadata(providerMetadata) {
|
|
3272
|
-
if (!
|
|
4056
|
+
if (!isRecord2(providerMetadata)) return void 0;
|
|
3273
4057
|
return firstTokenCount(
|
|
3274
4058
|
...CACHE_WRITE_METADATA_KEYS.flatMap(([namespace, key]) => {
|
|
3275
4059
|
const scope = providerMetadata[namespace];
|
|
3276
|
-
if (!
|
|
4060
|
+
if (!isRecord2(scope)) return [];
|
|
3277
4061
|
const usage = scope["usage"];
|
|
3278
|
-
return [scope[key],
|
|
4062
|
+
return [scope[key], isRecord2(usage) ? usage[key] : void 0];
|
|
3279
4063
|
})
|
|
3280
4064
|
);
|
|
3281
4065
|
}
|
|
3282
4066
|
function extractUsageMetricsFromUsage(usage, _provider, providerMetadata) {
|
|
3283
|
-
if (!
|
|
4067
|
+
if (!isRecord2(usage)) return {};
|
|
3284
4068
|
const inputTokenValue = usage["inputTokens"];
|
|
3285
4069
|
const outputTokenValue = usage["outputTokens"];
|
|
3286
4070
|
const inputTokenDetails = usage["inputTokenDetails"];
|
|
3287
4071
|
const outputTokenDetails = usage["outputTokenDetails"];
|
|
3288
|
-
const hasStructuredUsage =
|
|
4072
|
+
const hasStructuredUsage = isRecord2(inputTokenValue) || isRecord2(outputTokenValue) || isRecord2(inputTokenDetails) || isRecord2(outputTokenDetails);
|
|
3289
4073
|
const inputTokens = firstTokenCount(
|
|
3290
|
-
|
|
4074
|
+
isRecord2(inputTokenValue) ? inputTokenValue["total"] : void 0,
|
|
3291
4075
|
inputTokenValue,
|
|
3292
4076
|
usage["promptTokens"],
|
|
3293
4077
|
usage["prompt_tokens"]
|
|
3294
4078
|
);
|
|
3295
4079
|
const outputTokens = firstTokenCount(
|
|
3296
|
-
|
|
4080
|
+
isRecord2(outputTokenValue) ? outputTokenValue["total"] : void 0,
|
|
3297
4081
|
outputTokenValue,
|
|
3298
4082
|
usage["completionTokens"],
|
|
3299
4083
|
usage["completion_tokens"]
|
|
3300
4084
|
);
|
|
3301
4085
|
const reasoningTokens = firstTokenCount(
|
|
3302
|
-
|
|
3303
|
-
|
|
4086
|
+
isRecord2(outputTokenValue) ? outputTokenValue["reasoning"] : void 0,
|
|
4087
|
+
isRecord2(outputTokenDetails) ? outputTokenDetails["reasoningTokens"] : void 0,
|
|
3304
4088
|
usage["reasoningTokens"],
|
|
3305
4089
|
usage["completionReasoningTokens"],
|
|
3306
4090
|
usage["completion_reasoning_tokens"],
|
|
@@ -3309,27 +4093,27 @@ function extractUsageMetricsFromUsage(usage, _provider, providerMetadata) {
|
|
|
3309
4093
|
usage["thinking_tokens"]
|
|
3310
4094
|
);
|
|
3311
4095
|
const cacheReadInputTokens = firstTokenCount(
|
|
3312
|
-
|
|
3313
|
-
|
|
4096
|
+
isRecord2(inputTokenValue) ? inputTokenValue["cacheRead"] : void 0,
|
|
4097
|
+
isRecord2(inputTokenDetails) ? inputTokenDetails["cacheReadTokens"] : void 0,
|
|
3314
4098
|
usage["cachedInputTokens"],
|
|
3315
4099
|
usage["promptCachedTokens"],
|
|
3316
4100
|
usage["prompt_cached_tokens"]
|
|
3317
4101
|
);
|
|
3318
4102
|
const cacheWriteInputTokens = firstTokenCount(
|
|
3319
|
-
|
|
3320
|
-
|
|
4103
|
+
isRecord2(inputTokenValue) ? inputTokenValue["cacheWrite"] : void 0,
|
|
4104
|
+
isRecord2(inputTokenDetails) ? inputTokenDetails["cacheWriteTokens"] : void 0,
|
|
3321
4105
|
usage["cacheWriteInputTokens"],
|
|
3322
4106
|
usage["cacheCreationInputTokens"],
|
|
3323
4107
|
usage["cache_creation_input_tokens"],
|
|
3324
4108
|
cacheWriteTokensFromProviderMetadata(providerMetadata)
|
|
3325
4109
|
);
|
|
3326
4110
|
const nonCachedInputTokens = firstTokenCount(
|
|
3327
|
-
|
|
3328
|
-
|
|
4111
|
+
isRecord2(inputTokenValue) ? inputTokenValue["noCache"] : void 0,
|
|
4112
|
+
isRecord2(inputTokenDetails) ? inputTokenDetails["noCacheTokens"] : void 0
|
|
3329
4113
|
);
|
|
3330
4114
|
const nonReasoningOutputTokens = firstTokenCount(
|
|
3331
|
-
|
|
3332
|
-
|
|
4115
|
+
isRecord2(outputTokenValue) ? outputTokenValue["text"] : void 0,
|
|
4116
|
+
isRecord2(outputTokenDetails) ? outputTokenDetails["textTokens"] : void 0
|
|
3333
4117
|
);
|
|
3334
4118
|
const totalTokens = firstTokenCount(
|
|
3335
4119
|
usage["totalTokens"],
|
|
@@ -3555,17 +4339,10 @@ var RaindropTelemetryIntegration = class {
|
|
|
3555
4339
|
if (event.promptMessages) {
|
|
3556
4340
|
inputAttrs.push(attrString("ai.prompt.messages", safeJsonWithUint8(event.promptMessages)));
|
|
3557
4341
|
}
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
event.stepTools.map((t) => {
|
|
3563
|
-
var _a;
|
|
3564
|
-
return (_a = safeJsonWithUint8(t)) != null ? _a : "";
|
|
3565
|
-
})
|
|
3566
|
-
)
|
|
3567
|
-
);
|
|
3568
|
-
}
|
|
4342
|
+
const promptTools = promptToolsAttribute(
|
|
4343
|
+
resolvePromptTools({ override: this.promptTools, inferred: event.stepTools })
|
|
4344
|
+
);
|
|
4345
|
+
if (promptTools) inputAttrs.push(promptTools);
|
|
3569
4346
|
if (event.stepToolChoice != null) {
|
|
3570
4347
|
inputAttrs.push(
|
|
3571
4348
|
attrString("ai.prompt.toolChoice", safeJsonWithUint8(event.stepToolChoice))
|
|
@@ -3913,6 +4690,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
3913
4690
|
this.subagentWrapping = opts.subagentWrapping !== false;
|
|
3914
4691
|
this.debug = opts.debug === true;
|
|
3915
4692
|
this.defaultContext = opts.context;
|
|
4693
|
+
this.promptTools = opts.tools;
|
|
3916
4694
|
this.subagents = new SubagentApi({
|
|
3917
4695
|
traceShipper: this.traceShipper,
|
|
3918
4696
|
eventShipper: this.eventShipper,
|
|
@@ -4538,6 +5316,18 @@ function createStandaloneSelfDiagnosticsTool(args) {
|
|
|
4538
5316
|
}
|
|
4539
5317
|
|
|
4540
5318
|
// src/internal/wrap/wrapAISDK.ts
|
|
5319
|
+
function promptToolsOptionsFrom(aiSDK) {
|
|
5320
|
+
if (!isRecord2(aiSDK)) return void 0;
|
|
5321
|
+
const asSchema = aiSDK["asSchema"];
|
|
5322
|
+
if (!isFunction(asSchema)) return void 0;
|
|
5323
|
+
return {
|
|
5324
|
+
schema: (schema) => {
|
|
5325
|
+
const converted = asSchema(schema);
|
|
5326
|
+
const json = isRecord2(converted) ? converted["jsonSchema"] : void 0;
|
|
5327
|
+
return isRecord2(json) ? json : void 0;
|
|
5328
|
+
}
|
|
5329
|
+
};
|
|
5330
|
+
}
|
|
4541
5331
|
var pendingStoresByShipper = /* @__PURE__ */ new WeakMap();
|
|
4542
5332
|
var PendingToolSpanStore = class _PendingToolSpanStore {
|
|
4543
5333
|
constructor() {
|
|
@@ -4594,9 +5384,9 @@ function _resetWarnedMissingUserId() {
|
|
|
4594
5384
|
warnedMissingUserId = false;
|
|
4595
5385
|
}
|
|
4596
5386
|
function extractRaindropCallOptions(options) {
|
|
4597
|
-
if (!
|
|
5387
|
+
if (!isRecord2(options)) return {};
|
|
4598
5388
|
const em = options["metadata"];
|
|
4599
|
-
if (
|
|
5389
|
+
if (isRecord2(em)) return extractRaindropMetadata(em);
|
|
4600
5390
|
const telemetry = extractExperimentalTelemetry(options);
|
|
4601
5391
|
if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
|
|
4602
5392
|
return {};
|
|
@@ -4658,20 +5448,20 @@ function mergeContexts(wrapTime, callTime) {
|
|
|
4658
5448
|
return result;
|
|
4659
5449
|
}
|
|
4660
5450
|
function detectAISDKVersion(aiSDK) {
|
|
4661
|
-
if (!
|
|
5451
|
+
if (!isRecord2(aiSDK)) return "unknown";
|
|
4662
5452
|
if (isFunction(aiSDK["jsonSchema"])) return "6";
|
|
4663
5453
|
if (isFunction(aiSDK["tool"])) return "5";
|
|
4664
5454
|
return "4";
|
|
4665
5455
|
}
|
|
4666
5456
|
function hasStructuredTelemetryEvents(aiSDK) {
|
|
4667
|
-
if (!
|
|
5457
|
+
if (!isRecord2(aiSDK)) return false;
|
|
4668
5458
|
const hasRegister = isFunction(aiSDK["registerTelemetry"]) || isFunction(aiSDK["registerTelemetryIntegration"]);
|
|
4669
5459
|
const hasV7Marker = isFunction(aiSDK["experimental_streamLanguageModelCall"]) || isFunction(aiSDK["experimental_streamModelCall"]);
|
|
4670
5460
|
return hasRegister && hasV7Marker;
|
|
4671
5461
|
}
|
|
4672
5462
|
function resolveRegisterTelemetry(aiSDK) {
|
|
4673
5463
|
var _a;
|
|
4674
|
-
if (!
|
|
5464
|
+
if (!isRecord2(aiSDK)) return void 0;
|
|
4675
5465
|
const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
|
|
4676
5466
|
return isFunction(fn) ? fn : void 0;
|
|
4677
5467
|
}
|
|
@@ -4702,18 +5492,18 @@ function isAsyncIterable(value) {
|
|
|
4702
5492
|
return value !== null && typeof value === "object" && Symbol.asyncIterator in value;
|
|
4703
5493
|
}
|
|
4704
5494
|
function resolveUsageRecord(result) {
|
|
4705
|
-
if (!
|
|
5495
|
+
if (!isRecord2(result)) return void 0;
|
|
4706
5496
|
let usage;
|
|
4707
5497
|
try {
|
|
4708
|
-
if (
|
|
5498
|
+
if (isRecord2(result["totalUsage"])) {
|
|
4709
5499
|
usage = result["totalUsage"];
|
|
4710
|
-
} else if (
|
|
5500
|
+
} else if (isRecord2(result["usage"])) {
|
|
4711
5501
|
usage = result["usage"];
|
|
4712
5502
|
}
|
|
4713
5503
|
} catch (e) {
|
|
4714
5504
|
return void 0;
|
|
4715
5505
|
}
|
|
4716
|
-
return
|
|
5506
|
+
return isRecord2(usage) ? usage : void 0;
|
|
4717
5507
|
}
|
|
4718
5508
|
function extractUsageMetrics(result) {
|
|
4719
5509
|
return extractUsageMetricsFromUsage(resolveUsageRecord(result));
|
|
@@ -4734,7 +5524,7 @@ function shouldKeepEventPending(params) {
|
|
|
4734
5524
|
}
|
|
4735
5525
|
function normalizePromptAttr(arg) {
|
|
4736
5526
|
var _a, _b;
|
|
4737
|
-
if (!
|
|
5527
|
+
if (!isRecord2(arg)) return arg;
|
|
4738
5528
|
const system = arg["system"];
|
|
4739
5529
|
const prompt = arg["prompt"];
|
|
4740
5530
|
const messages = arg["messages"];
|
|
@@ -4788,7 +5578,7 @@ async function runWithRootContextAsync(rootSpan, eventId, fn) {
|
|
|
4788
5578
|
);
|
|
4789
5579
|
}
|
|
4790
5580
|
function teeStreamObjectBaseStream(result) {
|
|
4791
|
-
if (!result || !
|
|
5581
|
+
if (!result || !isRecord2(result)) return;
|
|
4792
5582
|
const baseStream = result["baseStream"];
|
|
4793
5583
|
if (!(baseStream && typeof baseStream === "object" && "tee" in baseStream)) return;
|
|
4794
5584
|
try {
|
|
@@ -4829,7 +5619,7 @@ function setupOperation(params) {
|
|
|
4829
5619
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
4830
5620
|
const outerOperationId = `ai.${operation}`;
|
|
4831
5621
|
const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
|
|
4832
|
-
const modelInfoFromArgs =
|
|
5622
|
+
const modelInfoFromArgs = isRecord2(arg) ? extractModelInfo(arg["model"]) : {};
|
|
4833
5623
|
const rootSpan = sendTraces ? traceShipper.startSpan({
|
|
4834
5624
|
name: outerOperationId,
|
|
4835
5625
|
parent: inheritedParent,
|
|
@@ -4844,7 +5634,7 @@ function setupOperation(params) {
|
|
|
4844
5634
|
attrString("ai.model.id", modelInfoFromArgs.modelId),
|
|
4845
5635
|
attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
|
|
4846
5636
|
...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
|
|
4847
|
-
...attrsFromHeaders(
|
|
5637
|
+
...attrsFromHeaders(isRecord2(arg) ? arg["headers"] : void 0),
|
|
4848
5638
|
...attrsFromSettings(arg),
|
|
4849
5639
|
...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [attrString("ai.prompt", safeJsonWithUint8(normalizePromptAttr(arg)))]
|
|
4850
5640
|
]
|
|
@@ -4861,7 +5651,9 @@ function setupOperation(params) {
|
|
|
4861
5651
|
traceShipper,
|
|
4862
5652
|
rootParentForChildren,
|
|
4863
5653
|
selfDiagnostics: operationSelfDiagnostics,
|
|
4864
|
-
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
5654
|
+
aiSDKVersion: detectAISDKVersion(aiSDK),
|
|
5655
|
+
promptTools: options.tools,
|
|
5656
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
4865
5657
|
};
|
|
4866
5658
|
const toolCalls = [];
|
|
4867
5659
|
const argsWithWrappedTools = wrapTools(arg, wrapCtx, toolCalls);
|
|
@@ -4934,8 +5726,8 @@ function createFinalize(params) {
|
|
|
4934
5726
|
endTimeUnixNano: spanEndTimeUnixNano,
|
|
4935
5727
|
keepEventPending
|
|
4936
5728
|
});
|
|
4937
|
-
const providerMetadata =
|
|
4938
|
-
const resultToolCalls =
|
|
5729
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
5730
|
+
const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : setup.toolCalls.length ? safeJsonWithUint8(setup.toolCalls) : void 0;
|
|
4939
5731
|
traceShipper.endSpan(setup.rootSpan, {
|
|
4940
5732
|
attributes: [
|
|
4941
5733
|
...((_d = setup.telemetry) == null ? void 0 : _d.recordOutputs) === false ? [] : [
|
|
@@ -5207,6 +5999,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
5207
5999
|
sendEvents: ((_b = deps.options.send) == null ? void 0 : _b.events) !== false,
|
|
5208
6000
|
debug,
|
|
5209
6001
|
settledEventIds: deps.settledEventIds,
|
|
6002
|
+
tools: deps.options.tools,
|
|
5210
6003
|
context: {
|
|
5211
6004
|
userId: wrapTimeCtx.userId,
|
|
5212
6005
|
eventId: wrapTimeCtx.eventId,
|
|
@@ -5249,7 +6042,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
5249
6042
|
const arg = callArgs[0];
|
|
5250
6043
|
const callMetadata = readRaindropCallMetadataFromArgs(callArgs);
|
|
5251
6044
|
const callOriginal = () => original.call(aiSDK, ...callArgs);
|
|
5252
|
-
if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) &&
|
|
6045
|
+
if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord2(arg)) {
|
|
5253
6046
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
5254
6047
|
const callMeta = (telemetry == null ? void 0 : telemetry.metadata) ? extractRaindropMetadata(telemetry.metadata) : {};
|
|
5255
6048
|
const perCallEventIdExplicit = (_b2 = (_a2 = callMetadata == null ? void 0 : callMetadata.eventId) != null ? _a2 : callMeta.eventId) != null ? _b2 : wrapTimeCtx.eventId;
|
|
@@ -5261,16 +6054,18 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
5261
6054
|
eventShipper: deps.eventShipper,
|
|
5262
6055
|
traceShipper: deps.traceShipper,
|
|
5263
6056
|
selfDiagnostics: selfDiagnostics2,
|
|
5264
|
-
aiSDKVersion: "7"
|
|
6057
|
+
aiSDKVersion: "7",
|
|
6058
|
+
promptTools: deps.options.tools,
|
|
6059
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
5265
6060
|
};
|
|
5266
|
-
const tools =
|
|
6061
|
+
const tools = isRecord2(arg["tools"]) ? { ...arg["tools"] } : {};
|
|
5267
6062
|
const toolName = selfDiagnostics2.toolName;
|
|
5268
6063
|
if (!(toolName in tools)) {
|
|
5269
6064
|
const reportTool = createSelfDiagnosticsTool(perCallCtx);
|
|
5270
6065
|
if (reportTool) tools[toolName] = reportTool;
|
|
5271
6066
|
}
|
|
5272
|
-
const existingTelemetry =
|
|
5273
|
-
const existingMetadata =
|
|
6067
|
+
const existingTelemetry = isRecord2(arg["experimental_telemetry"]) ? arg["experimental_telemetry"] : {};
|
|
6068
|
+
const existingMetadata = isRecord2(existingTelemetry["metadata"]) ? existingTelemetry["metadata"] : {};
|
|
5274
6069
|
const mergedMetadata = existingMetadata["raindrop.eventId"] ? existingMetadata : {
|
|
5275
6070
|
...existingMetadata,
|
|
5276
6071
|
"raindrop.eventId": perCallEventId,
|
|
@@ -5466,7 +6261,9 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
5466
6261
|
traceShipper: deps.traceShipper,
|
|
5467
6262
|
rootParentForChildren,
|
|
5468
6263
|
selfDiagnostics,
|
|
5469
|
-
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
6264
|
+
aiSDKVersion: detectAISDKVersion(aiSDK),
|
|
6265
|
+
promptTools: deps.options.tools,
|
|
6266
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
5470
6267
|
};
|
|
5471
6268
|
const toolCalls = [];
|
|
5472
6269
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -5516,8 +6313,8 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
5516
6313
|
keepEventPending: false
|
|
5517
6314
|
});
|
|
5518
6315
|
const finishReason = extractFinishReason(result);
|
|
5519
|
-
const providerMetadata =
|
|
5520
|
-
const resultToolCalls =
|
|
6316
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
6317
|
+
const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
|
|
5521
6318
|
deps.traceShipper.endSpan(rootSpan, {
|
|
5522
6319
|
attributes: [
|
|
5523
6320
|
...(telemetry == null ? void 0 : telemetry.recordOutputs) === false ? [] : [
|
|
@@ -5686,7 +6483,9 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
5686
6483
|
traceShipper: deps.traceShipper,
|
|
5687
6484
|
rootParentForChildren,
|
|
5688
6485
|
selfDiagnostics,
|
|
5689
|
-
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
6486
|
+
aiSDKVersion: detectAISDKVersion(aiSDK),
|
|
6487
|
+
promptTools: deps.options.tools,
|
|
6488
|
+
promptToolsOptions: promptToolsOptionsFrom(aiSDK)
|
|
5690
6489
|
};
|
|
5691
6490
|
const toolCalls = [];
|
|
5692
6491
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -5736,8 +6535,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
5736
6535
|
keepEventPending: false
|
|
5737
6536
|
});
|
|
5738
6537
|
const finishReason = extractFinishReason(result);
|
|
5739
|
-
const providerMetadata =
|
|
5740
|
-
const resultToolCalls =
|
|
6538
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
6539
|
+
const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
|
|
5741
6540
|
deps.traceShipper.endSpan(rootSpan, {
|
|
5742
6541
|
attributes: [
|
|
5743
6542
|
...(telemetry == null ? void 0 : telemetry.recordOutputs) === false ? [] : [
|
|
@@ -5849,8 +6648,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
5849
6648
|
};
|
|
5850
6649
|
}
|
|
5851
6650
|
function wrapTools(args, ctx, toolCalls) {
|
|
5852
|
-
if (!
|
|
5853
|
-
const tools =
|
|
6651
|
+
if (!isRecord2(args)) return args;
|
|
6652
|
+
const tools = isRecord2(args["tools"]) ? { ...args["tools"] } : {};
|
|
5854
6653
|
if (ctx.selfDiagnostics) {
|
|
5855
6654
|
const reportToolName = ctx.selfDiagnostics.toolName;
|
|
5856
6655
|
if (!(reportToolName in tools)) {
|
|
@@ -5873,7 +6672,7 @@ function wrapTools(args, ctx, toolCalls) {
|
|
|
5873
6672
|
}
|
|
5874
6673
|
function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
5875
6674
|
var _a;
|
|
5876
|
-
if (!
|
|
6675
|
+
if (!isRecord2(tool) || !isFunction(tool["execute"])) return tool;
|
|
5877
6676
|
const originalExecute = tool["execute"];
|
|
5878
6677
|
const { operationName, resourceName } = opName("ai.toolCall", (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
|
|
5879
6678
|
const createToolSpan = (toolCallId, toolArgs, parent) => {
|
|
@@ -5934,7 +6733,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
5934
6733
|
const wrappedExecute = function(...execArgs) {
|
|
5935
6734
|
const toolArgs = execArgs[0];
|
|
5936
6735
|
const execOptions = execArgs.length > 1 ? execArgs[1] : void 0;
|
|
5937
|
-
const toolCallId =
|
|
6736
|
+
const toolCallId = isRecord2(execOptions) && typeof execOptions["toolCallId"] === "string" ? execOptions["toolCallId"] : randomUUID();
|
|
5938
6737
|
const result = originalExecute.apply(this, execArgs);
|
|
5939
6738
|
if (isAsyncIterable(result)) {
|
|
5940
6739
|
return (async function* () {
|
|
@@ -6009,20 +6808,20 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
6009
6808
|
return { ...tool, execute: wrappedExecute };
|
|
6010
6809
|
}
|
|
6011
6810
|
function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
6012
|
-
if (!
|
|
6811
|
+
if (!isRecord2(args) || !("model" in args)) return args;
|
|
6013
6812
|
let model = args["model"];
|
|
6014
6813
|
if (typeof model === "string") {
|
|
6015
6814
|
const maybeProvider = globalThis.AI_SDK_DEFAULT_PROVIDER;
|
|
6016
|
-
const gateway =
|
|
6815
|
+
const gateway = isRecord2(aiSDK) ? aiSDK["gateway"] : void 0;
|
|
6017
6816
|
const provider = maybeProvider != null ? maybeProvider : gateway;
|
|
6018
|
-
if (
|
|
6817
|
+
if (isRecord2(provider) && isFunction(provider["languageModel"])) {
|
|
6019
6818
|
try {
|
|
6020
6819
|
model = provider["languageModel"](model);
|
|
6021
6820
|
} catch (e) {
|
|
6022
6821
|
}
|
|
6023
6822
|
}
|
|
6024
6823
|
}
|
|
6025
|
-
if (!
|
|
6824
|
+
if (!isRecord2(model)) return args;
|
|
6026
6825
|
const modelInfo = extractModelInfo(model);
|
|
6027
6826
|
const doGenerateOpId = `${outerOperationId}.doGenerate`;
|
|
6028
6827
|
const doStreamOpId = `${outerOperationId}.doStream`;
|
|
@@ -6039,13 +6838,13 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6039
6838
|
try {
|
|
6040
6839
|
const result = await original.apply(target, callArgs);
|
|
6041
6840
|
if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
|
|
6042
|
-
if (localDebuggerEnabled() && ctx.rootParentForChildren &&
|
|
6841
|
+
if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord2(result)) {
|
|
6043
6842
|
const traceId = ctx.rootParentForChildren.traceIdB64;
|
|
6044
6843
|
const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
|
|
6045
6844
|
const content = result["content"];
|
|
6046
6845
|
if (Array.isArray(content)) {
|
|
6047
6846
|
for (const part of content) {
|
|
6048
|
-
if (
|
|
6847
|
+
if (isRecord2(part)) {
|
|
6049
6848
|
if ((part["type"] === "reasoning" || part["type"] === "thinking") && typeof ((_a = part["text"]) != null ? _a : part["thinking"]) === "string") {
|
|
6050
6849
|
sendLocalDebuggerLiveEvent({
|
|
6051
6850
|
traceId,
|
|
@@ -6114,7 +6913,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6114
6913
|
});
|
|
6115
6914
|
throw error;
|
|
6116
6915
|
}
|
|
6117
|
-
const stream =
|
|
6916
|
+
const stream = isRecord2(result) ? result["stream"] : void 0;
|
|
6118
6917
|
const RS = globalThis.ReadableStream;
|
|
6119
6918
|
if (!RS || !(stream instanceof RS)) {
|
|
6120
6919
|
if (span) ctx.traceShipper.endSpan(span);
|
|
@@ -6187,7 +6986,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6187
6986
|
return;
|
|
6188
6987
|
}
|
|
6189
6988
|
if (firstChunkMs === void 0) firstChunkMs = Date.now();
|
|
6190
|
-
if (
|
|
6989
|
+
if (isRecord2(value)) {
|
|
6191
6990
|
const type = value["type"];
|
|
6192
6991
|
if (type === "text-delta") {
|
|
6193
6992
|
let textDelta;
|
|
@@ -6202,7 +7001,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6202
7001
|
}
|
|
6203
7002
|
if (type === "finish") finishReason = extractFinishReason(value);
|
|
6204
7003
|
if (type === "tool-call") toolCallsLocal.push(value);
|
|
6205
|
-
if ("response" in value &&
|
|
7004
|
+
if ("response" in value && isRecord2(value["response"])) {
|
|
6206
7005
|
const response = value["response"];
|
|
6207
7006
|
if (typeof response["id"] === "string") responseId = response["id"];
|
|
6208
7007
|
if (typeof response["modelId"] === "string")
|
|
@@ -6279,10 +7078,15 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
6279
7078
|
function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
6280
7079
|
var _a, _b, _c;
|
|
6281
7080
|
const { operationName, resourceName } = opName(operationId, (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
|
|
6282
|
-
const
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
7081
|
+
const promptTools = promptToolsAttribute(
|
|
7082
|
+
resolvePromptTools({
|
|
7083
|
+
override: ctx.promptTools,
|
|
7084
|
+
inferred: isRecord2(options) ? options["tools"] : void 0,
|
|
7085
|
+
options: ctx.promptToolsOptions
|
|
7086
|
+
})
|
|
7087
|
+
);
|
|
7088
|
+
const toolChoiceJson = isRecord2(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
|
|
7089
|
+
const promptJson = isRecord2(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
|
|
6286
7090
|
return ctx.traceShipper.startSpan({
|
|
6287
7091
|
name: operationId,
|
|
6288
7092
|
parent,
|
|
@@ -6297,7 +7101,7 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
6297
7101
|
attrString("ai.model.id", modelInfo.modelId),
|
|
6298
7102
|
...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
|
|
6299
7103
|
attrString("ai.prompt.messages", promptJson),
|
|
6300
|
-
|
|
7104
|
+
promptTools,
|
|
6301
7105
|
attrString("ai.prompt.toolChoice", toolChoiceJson)
|
|
6302
7106
|
],
|
|
6303
7107
|
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, modelInfo.modelId),
|
|
@@ -6309,26 +7113,26 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
6309
7113
|
function endDoGenerateSpan(span, result, modelInfo, ctx) {
|
|
6310
7114
|
var _a;
|
|
6311
7115
|
const finishReason = extractFinishReason(result);
|
|
6312
|
-
const content =
|
|
6313
|
-
const response =
|
|
6314
|
-
const usage =
|
|
6315
|
-
const providerMetadata =
|
|
7116
|
+
const content = isRecord2(result) ? result["content"] : void 0;
|
|
7117
|
+
const response = isRecord2(result) ? result["response"] : void 0;
|
|
7118
|
+
const usage = isRecord2(result) ? result["usage"] : void 0;
|
|
7119
|
+
const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
|
|
6316
7120
|
let responseId;
|
|
6317
|
-
if (
|
|
7121
|
+
if (isRecord2(response) && typeof response["id"] === "string") {
|
|
6318
7122
|
responseId = response["id"];
|
|
6319
7123
|
} else {
|
|
6320
7124
|
responseId = randomUUID();
|
|
6321
7125
|
}
|
|
6322
7126
|
let responseModelId;
|
|
6323
|
-
if (
|
|
7127
|
+
if (isRecord2(response) && typeof response["modelId"] === "string") {
|
|
6324
7128
|
responseModelId = response["modelId"];
|
|
6325
7129
|
} else {
|
|
6326
7130
|
responseModelId = modelInfo.modelId;
|
|
6327
7131
|
}
|
|
6328
7132
|
let responseTimestampIso;
|
|
6329
|
-
if (
|
|
7133
|
+
if (isRecord2(response) && response["timestamp"] instanceof Date) {
|
|
6330
7134
|
responseTimestampIso = response["timestamp"].toISOString();
|
|
6331
|
-
} else if (
|
|
7135
|
+
} else if (isRecord2(response) && typeof response["timestamp"] === "string") {
|
|
6332
7136
|
responseTimestampIso = response["timestamp"];
|
|
6333
7137
|
} else {
|
|
6334
7138
|
responseTimestampIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -6362,10 +7166,15 @@ function endDoGenerateSpan(span, result, modelInfo, ctx) {
|
|
|
6362
7166
|
function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
6363
7167
|
var _a, _b, _c;
|
|
6364
7168
|
const { operationName, resourceName } = opName(operationId, (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
|
|
6365
|
-
const
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
7169
|
+
const promptTools = promptToolsAttribute(
|
|
7170
|
+
resolvePromptTools({
|
|
7171
|
+
override: ctx.promptTools,
|
|
7172
|
+
inferred: isRecord2(options) ? options["tools"] : void 0,
|
|
7173
|
+
options: ctx.promptToolsOptions
|
|
7174
|
+
})
|
|
7175
|
+
);
|
|
7176
|
+
const toolChoiceJson = isRecord2(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
|
|
7177
|
+
const promptJson = isRecord2(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
|
|
6369
7178
|
return ctx.traceShipper.startSpan({
|
|
6370
7179
|
name: operationId,
|
|
6371
7180
|
parent,
|
|
@@ -6380,7 +7189,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
6380
7189
|
attrString("ai.model.id", modelInfo.modelId),
|
|
6381
7190
|
...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
|
|
6382
7191
|
attrString("ai.prompt.messages", promptJson),
|
|
6383
|
-
|
|
7192
|
+
promptTools,
|
|
6384
7193
|
attrString("ai.prompt.toolChoice", toolChoiceJson)
|
|
6385
7194
|
],
|
|
6386
7195
|
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, modelInfo.modelId),
|
|
@@ -6394,7 +7203,7 @@ function resolveContext(context, info) {
|
|
|
6394
7203
|
return typeof context === "function" ? context(info) : context;
|
|
6395
7204
|
}
|
|
6396
7205
|
function wrapOnFinish(args, onFinish) {
|
|
6397
|
-
if (!
|
|
7206
|
+
if (!isRecord2(args)) return args;
|
|
6398
7207
|
const existing = args["onFinish"];
|
|
6399
7208
|
if (existing === void 0) {
|
|
6400
7209
|
return { ...args, onFinish: async (result) => onFinish(result) };
|
|
@@ -6452,14 +7261,14 @@ function mergeAttachments(...groups) {
|
|
|
6452
7261
|
// package.json
|
|
6453
7262
|
var package_default = {
|
|
6454
7263
|
name: "@raindrop-ai/ai-sdk",
|
|
6455
|
-
version: "0.3.
|
|
7264
|
+
version: "0.3.4"};
|
|
6456
7265
|
|
|
6457
7266
|
// src/internal/version.ts
|
|
6458
7267
|
var libraryName = package_default.name;
|
|
6459
7268
|
var libraryVersion = package_default.version;
|
|
6460
7269
|
|
|
6461
7270
|
// src/internal/events.ts
|
|
6462
|
-
var
|
|
7271
|
+
var EventShipper3 = class extends EventShipper2 {
|
|
6463
7272
|
constructor(opts) {
|
|
6464
7273
|
var _a, _b, _c;
|
|
6465
7274
|
super({
|
|
@@ -6472,7 +7281,7 @@ var EventShipper2 = class extends EventShipper {
|
|
|
6472
7281
|
};
|
|
6473
7282
|
|
|
6474
7283
|
// src/internal/traces.ts
|
|
6475
|
-
var
|
|
7284
|
+
var TraceShipper3 = class extends TraceShipper2 {
|
|
6476
7285
|
constructor(opts) {
|
|
6477
7286
|
var _a, _b, _c;
|
|
6478
7287
|
super({
|
|
@@ -6539,11 +7348,11 @@ function userAttrsToOtlp(attrs) {
|
|
|
6539
7348
|
function envDebugEnabled() {
|
|
6540
7349
|
var _a;
|
|
6541
7350
|
if (typeof process === "undefined") return false;
|
|
6542
|
-
const
|
|
6543
|
-
return
|
|
7351
|
+
const flag2 = (_a = process.env) == null ? void 0 : _a.RAINDROP_AI_DEBUG;
|
|
7352
|
+
return flag2 === "1" || flag2 === "true";
|
|
6544
7353
|
}
|
|
6545
7354
|
function createRaindropAISDK(opts) {
|
|
6546
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
7355
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6547
7356
|
const writeKey = opts.writeKey;
|
|
6548
7357
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
6549
7358
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
@@ -6552,37 +7361,53 @@ function createRaindropAISDK(opts) {
|
|
|
6552
7361
|
const localWorkshopInput = opts.localWorkshopUrl === false ? null : opts.localWorkshopUrl;
|
|
6553
7362
|
const resolvedLocalDebuggerUrl = resolveLocalDebuggerBaseUrl(localWorkshopInput);
|
|
6554
7363
|
const localDebuggerUrl = localWorkshopInput === null ? null : resolvedLocalDebuggerUrl != null ? resolvedLocalDebuggerUrl : void 0;
|
|
6555
|
-
const
|
|
6556
|
-
const eventsEnabled = eventsRequested &&
|
|
6557
|
-
const tracesEnabled = tracesRequested &&
|
|
6558
|
-
|
|
7364
|
+
const hasDestination2 = Boolean(writeKey == null ? void 0 : writeKey.trim()) || Boolean(resolvedLocalDebuggerUrl);
|
|
7365
|
+
const eventsEnabled = eventsRequested && hasDestination2;
|
|
7366
|
+
const tracesEnabled = tracesRequested && hasDestination2;
|
|
7367
|
+
const appGitContext = (_c = opts.appGitContext) != null ? _c : createAppGitContext2(
|
|
7368
|
+
eventsEnabled || tracesEnabled ? opts.appGit : false,
|
|
7369
|
+
{ allowLocalGit: true }
|
|
7370
|
+
);
|
|
7371
|
+
if (!hasDestination2 && (eventsRequested || tracesRequested)) {
|
|
6559
7372
|
console.warn(
|
|
6560
7373
|
"[raindrop-ai/ai-sdk] writeKey not provided and no local Workshop reachable; telemetry shipping is disabled"
|
|
6561
7374
|
);
|
|
6562
7375
|
}
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
7376
|
+
let eventShipper;
|
|
7377
|
+
let traceShipper;
|
|
7378
|
+
try {
|
|
7379
|
+
eventShipper = new EventShipper3({
|
|
7380
|
+
writeKey,
|
|
7381
|
+
endpoint: opts.endpoint,
|
|
7382
|
+
enabled: eventsEnabled,
|
|
7383
|
+
debug: ((_d = opts.events) == null ? void 0 : _d.debug) === true || envDebug,
|
|
7384
|
+
partialFlushMs: (_e = opts.events) == null ? void 0 : _e.partialFlushMs,
|
|
7385
|
+
projectId: opts.projectId,
|
|
7386
|
+
localDebuggerUrl,
|
|
7387
|
+
appGitContext
|
|
7388
|
+
});
|
|
7389
|
+
traceShipper = new TraceShipper3({
|
|
7390
|
+
writeKey,
|
|
7391
|
+
endpoint: opts.endpoint,
|
|
7392
|
+
enabled: tracesEnabled,
|
|
7393
|
+
debug: ((_f = opts.traces) == null ? void 0 : _f.debug) === true || envDebug,
|
|
7394
|
+
debugSpans: ((_g = opts.traces) == null ? void 0 : _g.debugSpans) === true || envDebug,
|
|
7395
|
+
flushIntervalMs: (_h = opts.traces) == null ? void 0 : _h.flushIntervalMs,
|
|
7396
|
+
maxBatchSize: (_i = opts.traces) == null ? void 0 : _i.maxBatchSize,
|
|
7397
|
+
maxQueueSize: (_j = opts.traces) == null ? void 0 : _j.maxQueueSize,
|
|
7398
|
+
projectId: opts.projectId,
|
|
7399
|
+
localDebuggerUrl,
|
|
7400
|
+
transformSpan: (_k = opts.traces) == null ? void 0 : _k.transformSpan,
|
|
7401
|
+
disableDefaultRedaction: (_l = opts.traces) == null ? void 0 : _l.disableDefaultRedaction,
|
|
7402
|
+
appGitContext
|
|
7403
|
+
});
|
|
7404
|
+
} catch (error) {
|
|
7405
|
+
try {
|
|
7406
|
+
appGitContext.dispose();
|
|
7407
|
+
} catch (e) {
|
|
7408
|
+
}
|
|
7409
|
+
throw error;
|
|
7410
|
+
}
|
|
6586
7411
|
const settledEventIds = /* @__PURE__ */ new Set();
|
|
6587
7412
|
const subagentApi = new SubagentApi({
|
|
6588
7413
|
traceShipper,
|
|
@@ -6620,11 +7445,16 @@ function createRaindropAISDK(opts) {
|
|
|
6620
7445
|
];
|
|
6621
7446
|
let context;
|
|
6622
7447
|
let subagentWrapping;
|
|
7448
|
+
let tools;
|
|
6623
7449
|
if (contextOrOptions === void 0) ; else if ("context" in contextOrOptions) {
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
7450
|
+
const shaped = contextOrOptions;
|
|
7451
|
+
context = shaped.context;
|
|
7452
|
+
subagentWrapping = shaped.subagentWrapping;
|
|
7453
|
+
tools = shaped.tools;
|
|
7454
|
+
} else if (("subagentWrapping" in contextOrOptions || "tools" in contextOrOptions) && !FLAT_CONTEXT_KEYS.some((k) => k in contextOrOptions)) {
|
|
7455
|
+
const shaped = contextOrOptions;
|
|
7456
|
+
subagentWrapping = shaped.subagentWrapping;
|
|
7457
|
+
tools = shaped.tools;
|
|
6628
7458
|
} else {
|
|
6629
7459
|
context = contextOrOptions;
|
|
6630
7460
|
}
|
|
@@ -6636,7 +7466,8 @@ function createRaindropAISDK(opts) {
|
|
|
6636
7466
|
subagentWrapping,
|
|
6637
7467
|
debug: envDebug,
|
|
6638
7468
|
settledEventIds,
|
|
6639
|
-
context
|
|
7469
|
+
context,
|
|
7470
|
+
tools
|
|
6640
7471
|
});
|
|
6641
7472
|
},
|
|
6642
7473
|
subagents: subagentApi,
|
|
@@ -6750,16 +7581,23 @@ function createRaindropAISDK(opts) {
|
|
|
6750
7581
|
await Promise.all([eventShipper.flush(), traceShipper.flush()]);
|
|
6751
7582
|
},
|
|
6752
7583
|
async shutdown() {
|
|
6753
|
-
|
|
7584
|
+
try {
|
|
7585
|
+
await Promise.all([eventShipper.shutdown(), traceShipper.shutdown()]);
|
|
7586
|
+
} finally {
|
|
7587
|
+
try {
|
|
7588
|
+
appGitContext.dispose();
|
|
7589
|
+
} catch (e) {
|
|
7590
|
+
}
|
|
7591
|
+
}
|
|
6754
7592
|
}
|
|
6755
7593
|
};
|
|
6756
7594
|
}
|
|
6757
7595
|
function raindrop(options = {}) {
|
|
6758
7596
|
var _a;
|
|
6759
|
-
const { context, subagentWrapping, writeKey, ...rest } = options;
|
|
7597
|
+
const { context, subagentWrapping, tools, writeKey, ...rest } = options;
|
|
6760
7598
|
const resolvedWriteKey = writeKey != null ? writeKey : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.RAINDROP_WRITE_KEY : void 0;
|
|
6761
7599
|
const client = createRaindropAISDK({ ...rest, writeKey: resolvedWriteKey });
|
|
6762
|
-
return client.createTelemetryIntegration({ context, subagentWrapping });
|
|
7600
|
+
return client.createTelemetryIntegration({ context, subagentWrapping, tools });
|
|
6763
7601
|
}
|
|
6764
7602
|
|
|
6765
|
-
export { DEFAULT_MAX_TEXT_FIELD_CHARS2 as DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, DETACHED_MODE, HANDOFF_ATTRIBUTE_PREFIXES, HANDOFF_ATTRIBUTE_SUFFIXES, HANDOFF_TERMINAL_CANCELLED, HANDOFF_TERMINAL_PROPERTY_KEY, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, SUBAGENT_ABORTED_OUTPUT, SUBAGENT_AGENT_ROLE, SUBAGENT_CANCELLED_OUTPUT, TOOL_EVENTS_ALLOW, TRUNCATION_MARKER2 as TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText2 as capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, fromHeaders, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, normalizeFeatureFlags, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, resetUnresolvedCarrierWarning, runWithParentToolContext, runWithRaindropCallMetadata, toHeaders, toLangSmithHeaders, withCurrent };
|
|
7603
|
+
export { DEFAULT_MAX_TEXT_FIELD_CHARS2 as DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, DETACHED_MODE, HANDOFF_ATTRIBUTE_PREFIXES, HANDOFF_ATTRIBUTE_SUFFIXES, HANDOFF_TERMINAL_CANCELLED, HANDOFF_TERMINAL_PROPERTY_KEY, PROMPT_TOOLS_ATTRIBUTE, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, SUBAGENT_ABORTED_OUTPUT, SUBAGENT_AGENT_ROLE, SUBAGENT_CANCELLED_OUTPUT, TOOL_EVENTS_ALLOW, TRUNCATION_MARKER2 as TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText2 as capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, fromHeaders, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, normalizeFeatureFlags, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, resetUnresolvedCarrierWarning, runWithParentToolContext, runWithRaindropCallMetadata, toHeaders, toLangSmithHeaders, withCurrent };
|