netra-sdk 1.10.1 → 1.11.0
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/dist/index.cjs +164 -1107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +117 -1060
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7390,14 +7390,14 @@ var require_otel = __commonJS({
|
|
|
7390
7390
|
getActiveSpan() {
|
|
7391
7391
|
return void 0;
|
|
7392
7392
|
}
|
|
7393
|
-
setSpan(
|
|
7394
|
-
return
|
|
7393
|
+
setSpan(context17, _span) {
|
|
7394
|
+
return context17;
|
|
7395
7395
|
}
|
|
7396
7396
|
getSpan(_context) {
|
|
7397
7397
|
return void 0;
|
|
7398
7398
|
}
|
|
7399
|
-
setSpanContext(
|
|
7400
|
-
return
|
|
7399
|
+
setSpanContext(context17, _spanContext) {
|
|
7400
|
+
return context17;
|
|
7401
7401
|
}
|
|
7402
7402
|
getTracerProvider() {
|
|
7403
7403
|
return void 0;
|
|
@@ -7984,17 +7984,17 @@ var require_p_retry = __commonJS({
|
|
|
7984
7984
|
}
|
|
7985
7985
|
const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
|
|
7986
7986
|
const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
|
|
7987
|
-
const
|
|
7987
|
+
const context17 = Object.freeze({
|
|
7988
7988
|
error: normalizedError,
|
|
7989
7989
|
attemptNumber,
|
|
7990
7990
|
retriesLeft,
|
|
7991
7991
|
retriesConsumed
|
|
7992
7992
|
});
|
|
7993
|
-
await options.onFailedAttempt(
|
|
7993
|
+
await options.onFailedAttempt(context17);
|
|
7994
7994
|
if (calculateRemainingTime2(startTime, maxRetryTime) <= 0) {
|
|
7995
7995
|
throw normalizedError;
|
|
7996
7996
|
}
|
|
7997
|
-
const consumeRetry = await options.shouldConsumeRetry(
|
|
7997
|
+
const consumeRetry = await options.shouldConsumeRetry(context17);
|
|
7998
7998
|
const remainingTime = calculateRemainingTime2(startTime, maxRetryTime);
|
|
7999
7999
|
if (remainingTime <= 0 || retriesLeft <= 0) {
|
|
8000
8000
|
throw normalizedError;
|
|
@@ -8006,7 +8006,7 @@ var require_p_retry = __commonJS({
|
|
|
8006
8006
|
options.signal?.throwIfAborted();
|
|
8007
8007
|
return false;
|
|
8008
8008
|
}
|
|
8009
|
-
if (!await options.shouldRetry(
|
|
8009
|
+
if (!await options.shouldRetry(context17)) {
|
|
8010
8010
|
throw normalizedError;
|
|
8011
8011
|
}
|
|
8012
8012
|
if (!consumeRetry) {
|
|
@@ -8114,16 +8114,16 @@ var require_eventemitter3 = __commonJS({
|
|
|
8114
8114
|
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
8115
8115
|
if (!new Events().__proto__) prefix = false;
|
|
8116
8116
|
}
|
|
8117
|
-
function EE(fn,
|
|
8117
|
+
function EE(fn, context17, once) {
|
|
8118
8118
|
this.fn = fn;
|
|
8119
|
-
this.context =
|
|
8119
|
+
this.context = context17;
|
|
8120
8120
|
this.once = once || false;
|
|
8121
8121
|
}
|
|
8122
|
-
function addListener(emitter, event, fn,
|
|
8122
|
+
function addListener(emitter, event, fn, context17, once) {
|
|
8123
8123
|
if (typeof fn !== "function") {
|
|
8124
8124
|
throw new TypeError("The listener must be a function");
|
|
8125
8125
|
}
|
|
8126
|
-
var listener = new EE(fn,
|
|
8126
|
+
var listener = new EE(fn, context17 || emitter, once), evt = prefix ? prefix + event : event;
|
|
8127
8127
|
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
8128
8128
|
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
8129
8129
|
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
@@ -8214,13 +8214,13 @@ var require_eventemitter3 = __commonJS({
|
|
|
8214
8214
|
}
|
|
8215
8215
|
return true;
|
|
8216
8216
|
};
|
|
8217
|
-
EventEmitter.prototype.on = function on(event, fn,
|
|
8218
|
-
return addListener(this, event, fn,
|
|
8217
|
+
EventEmitter.prototype.on = function on(event, fn, context17) {
|
|
8218
|
+
return addListener(this, event, fn, context17, false);
|
|
8219
8219
|
};
|
|
8220
|
-
EventEmitter.prototype.once = function once(event, fn,
|
|
8221
|
-
return addListener(this, event, fn,
|
|
8220
|
+
EventEmitter.prototype.once = function once(event, fn, context17) {
|
|
8221
|
+
return addListener(this, event, fn, context17, true);
|
|
8222
8222
|
};
|
|
8223
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn,
|
|
8223
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context17, once) {
|
|
8224
8224
|
var evt = prefix ? prefix + event : event;
|
|
8225
8225
|
if (!this._events[evt]) return this;
|
|
8226
8226
|
if (!fn) {
|
|
@@ -8229,12 +8229,12 @@ var require_eventemitter3 = __commonJS({
|
|
|
8229
8229
|
}
|
|
8230
8230
|
var listeners = this._events[evt];
|
|
8231
8231
|
if (listeners.fn) {
|
|
8232
|
-
if (listeners.fn === fn && (!once || listeners.once) && (!
|
|
8232
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context17 || listeners.context === context17)) {
|
|
8233
8233
|
clearEvent(this, evt);
|
|
8234
8234
|
}
|
|
8235
8235
|
} else {
|
|
8236
8236
|
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
8237
|
-
if (listeners[i].fn !== fn || once && !listeners[i].once ||
|
|
8237
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context17 && listeners[i].context !== context17) {
|
|
8238
8238
|
events.push(listeners[i]);
|
|
8239
8239
|
}
|
|
8240
8240
|
}
|
|
@@ -13145,7 +13145,7 @@ var require_error2 = __commonJS({
|
|
|
13145
13145
|
function isLangSmithConflictError2(error) {
|
|
13146
13146
|
return error != null && typeof error === "object" && "name" in error && error?.name === "LangSmithConflictError";
|
|
13147
13147
|
}
|
|
13148
|
-
async function raiseForStatus2(response,
|
|
13148
|
+
async function raiseForStatus2(response, context17, consumeOnSuccess) {
|
|
13149
13149
|
let errorBody;
|
|
13150
13150
|
if (response.ok) {
|
|
13151
13151
|
if (consumeOnSuccess) {
|
|
@@ -13168,7 +13168,7 @@ var require_error2 = __commonJS({
|
|
|
13168
13168
|
errorBody = "This API key is org-scoped and requires workspace specification. Please provide 'workspaceId' parameter, or set LANGSMITH_WORKSPACE_ID environment variable.";
|
|
13169
13169
|
}
|
|
13170
13170
|
}
|
|
13171
|
-
const fullMessage = `Failed to ${
|
|
13171
|
+
const fullMessage = `Failed to ${context17}. Received status [${response.status}]: ${response.statusText}. Message: ${errorBody}`;
|
|
13172
13172
|
if (response.status === 404) {
|
|
13173
13173
|
throw new LangSmithNotFoundError2(fullMessage);
|
|
13174
13174
|
}
|
|
@@ -16262,7 +16262,7 @@ var require_client2 = __commonJS({
|
|
|
16262
16262
|
});
|
|
16263
16263
|
return stream;
|
|
16264
16264
|
}
|
|
16265
|
-
async _sendMultipartRequest(parts,
|
|
16265
|
+
async _sendMultipartRequest(parts, context17, options) {
|
|
16266
16266
|
const boundary = "----LangSmithFormBoundary" + Math.random().toString(36).slice(2);
|
|
16267
16267
|
const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
|
|
16268
16268
|
const buildStream = () => this._createMultipartStream(parts, boundary);
|
|
@@ -16307,7 +16307,7 @@ var require_client2 = __commonJS({
|
|
|
16307
16307
|
res = await sendWithRetry(buildBuffered);
|
|
16308
16308
|
}
|
|
16309
16309
|
if ((!this.multipartStreamingDisabled || streamedAttempt) && res.status === 422 && (options?.apiUrl ?? this.apiUrl) !== profiles_js_1.DEFAULT_API_URL) {
|
|
16310
|
-
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. This usually means the host does not support chunked uploads. Retrying with a buffered upload for operation "${
|
|
16310
|
+
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. This usually means the host does not support chunked uploads. Retrying with a buffered upload for operation "${context17}".`);
|
|
16311
16311
|
this.multipartStreamingDisabled = true;
|
|
16312
16312
|
res = await sendWithRetry(buildBuffered);
|
|
16313
16313
|
}
|
|
@@ -16317,7 +16317,7 @@ var require_client2 = __commonJS({
|
|
|
16317
16317
|
}
|
|
16318
16318
|
console.warn(`${e.message.trim()}
|
|
16319
16319
|
|
|
16320
|
-
Context: ${
|
|
16320
|
+
Context: ${context17}`);
|
|
16321
16321
|
if (this.failedTracesDir) {
|
|
16322
16322
|
const bodyBuffer = await this._createNodeFetchBody(parts, boundary).catch(() => null);
|
|
16323
16323
|
if (bodyBuffer) {
|
|
@@ -16827,7 +16827,7 @@ Context: ${context18}`);
|
|
|
16827
16827
|
const withLimit = limit2 !== void 0 ? withOffset.slice(0, limit2) : withOffset;
|
|
16828
16828
|
return withLimit;
|
|
16829
16829
|
}
|
|
16830
|
-
async getRunStats({ id, trace:
|
|
16830
|
+
async getRunStats({ id, trace: trace24, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType }) {
|
|
16831
16831
|
let projectIds_ = projectIds || [];
|
|
16832
16832
|
if (projectNames) {
|
|
16833
16833
|
projectIds_ = [
|
|
@@ -16840,7 +16840,7 @@ Context: ${context18}`);
|
|
|
16840
16840
|
}
|
|
16841
16841
|
const payload = {
|
|
16842
16842
|
id,
|
|
16843
|
-
trace:
|
|
16843
|
+
trace: trace24,
|
|
16844
16844
|
parent_run: parentRun,
|
|
16845
16845
|
run_type: runType,
|
|
16846
16846
|
session: projectIds_,
|
|
@@ -17721,7 +17721,7 @@ Message: ${Array.isArray(result.detail) ? result.detail.join("\n") : "Unspecifie
|
|
|
17721
17721
|
params.append("filter", filter);
|
|
17722
17722
|
}
|
|
17723
17723
|
if (includeAttachments === true) {
|
|
17724
|
-
["attachment_urls", "outputs", "metadata"].forEach((
|
|
17724
|
+
["attachment_urls", "outputs", "metadata"].forEach((field) => params.append("select", field));
|
|
17725
17725
|
}
|
|
17726
17726
|
let i = 0;
|
|
17727
17727
|
for await (const rawExamples of this._getPaginated("/examples", params)) {
|
|
@@ -26286,14 +26286,14 @@ var init_otel = __esm({
|
|
|
26286
26286
|
getActiveSpan() {
|
|
26287
26287
|
return void 0;
|
|
26288
26288
|
}
|
|
26289
|
-
setSpan(
|
|
26290
|
-
return
|
|
26289
|
+
setSpan(context17, _span) {
|
|
26290
|
+
return context17;
|
|
26291
26291
|
}
|
|
26292
26292
|
getSpan(_context) {
|
|
26293
26293
|
return void 0;
|
|
26294
26294
|
}
|
|
26295
|
-
setSpanContext(
|
|
26296
|
-
return
|
|
26295
|
+
setSpanContext(context17, _spanContext) {
|
|
26296
|
+
return context17;
|
|
26297
26297
|
}
|
|
26298
26298
|
getTracerProvider() {
|
|
26299
26299
|
return void 0;
|
|
@@ -26800,17 +26800,17 @@ async function onAttemptFailure({ error, attemptNumber, retriesConsumed, startTi
|
|
|
26800
26800
|
}
|
|
26801
26801
|
const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
|
|
26802
26802
|
const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
|
|
26803
|
-
const
|
|
26803
|
+
const context17 = Object.freeze({
|
|
26804
26804
|
error: normalizedError,
|
|
26805
26805
|
attemptNumber,
|
|
26806
26806
|
retriesLeft,
|
|
26807
26807
|
retriesConsumed
|
|
26808
26808
|
});
|
|
26809
|
-
await options.onFailedAttempt(
|
|
26809
|
+
await options.onFailedAttempt(context17);
|
|
26810
26810
|
if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
|
|
26811
26811
|
throw normalizedError;
|
|
26812
26812
|
}
|
|
26813
|
-
const consumeRetry = await options.shouldConsumeRetry(
|
|
26813
|
+
const consumeRetry = await options.shouldConsumeRetry(context17);
|
|
26814
26814
|
const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
|
|
26815
26815
|
if (remainingTime <= 0 || retriesLeft <= 0) {
|
|
26816
26816
|
throw normalizedError;
|
|
@@ -26822,7 +26822,7 @@ async function onAttemptFailure({ error, attemptNumber, retriesConsumed, startTi
|
|
|
26822
26822
|
options.signal?.throwIfAborted();
|
|
26823
26823
|
return false;
|
|
26824
26824
|
}
|
|
26825
|
-
if (!await options.shouldRetry(
|
|
26825
|
+
if (!await options.shouldRetry(context17)) {
|
|
26826
26826
|
throw normalizedError;
|
|
26827
26827
|
}
|
|
26828
26828
|
if (!consumeRetry) {
|
|
@@ -30376,7 +30376,7 @@ function isLangSmithNotFoundError(error) {
|
|
|
30376
30376
|
function isLangSmithConflictError(error) {
|
|
30377
30377
|
return error != null && typeof error === "object" && "name" in error && error?.name === "LangSmithConflictError";
|
|
30378
30378
|
}
|
|
30379
|
-
async function raiseForStatus(response,
|
|
30379
|
+
async function raiseForStatus(response, context17, consumeOnSuccess) {
|
|
30380
30380
|
let errorBody;
|
|
30381
30381
|
if (response.ok) {
|
|
30382
30382
|
if (consumeOnSuccess) {
|
|
@@ -30399,7 +30399,7 @@ async function raiseForStatus(response, context18, consumeOnSuccess) {
|
|
|
30399
30399
|
errorBody = "This API key is org-scoped and requires workspace specification. Please provide 'workspaceId' parameter, or set LANGSMITH_WORKSPACE_ID environment variable.";
|
|
30400
30400
|
}
|
|
30401
30401
|
}
|
|
30402
|
-
const fullMessage = `Failed to ${
|
|
30402
|
+
const fullMessage = `Failed to ${context17}. Received status [${response.status}]: ${response.statusText}. Message: ${errorBody}`;
|
|
30403
30403
|
if (response.status === 404) {
|
|
30404
30404
|
throw new LangSmithNotFoundError(fullMessage);
|
|
30405
30405
|
}
|
|
@@ -33378,7 +33378,7 @@ var init_client2 = __esm({
|
|
|
33378
33378
|
});
|
|
33379
33379
|
return stream;
|
|
33380
33380
|
}
|
|
33381
|
-
async _sendMultipartRequest(parts,
|
|
33381
|
+
async _sendMultipartRequest(parts, context17, options) {
|
|
33382
33382
|
const boundary = "----LangSmithFormBoundary" + Math.random().toString(36).slice(2);
|
|
33383
33383
|
const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
|
|
33384
33384
|
const buildStream = () => this._createMultipartStream(parts, boundary);
|
|
@@ -33423,7 +33423,7 @@ var init_client2 = __esm({
|
|
|
33423
33423
|
res = await sendWithRetry(buildBuffered);
|
|
33424
33424
|
}
|
|
33425
33425
|
if ((!this.multipartStreamingDisabled || streamedAttempt) && res.status === 422 && (options?.apiUrl ?? this.apiUrl) !== DEFAULT_API_URL) {
|
|
33426
|
-
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. This usually means the host does not support chunked uploads. Retrying with a buffered upload for operation "${
|
|
33426
|
+
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. This usually means the host does not support chunked uploads. Retrying with a buffered upload for operation "${context17}".`);
|
|
33427
33427
|
this.multipartStreamingDisabled = true;
|
|
33428
33428
|
res = await sendWithRetry(buildBuffered);
|
|
33429
33429
|
}
|
|
@@ -33433,7 +33433,7 @@ var init_client2 = __esm({
|
|
|
33433
33433
|
}
|
|
33434
33434
|
console.warn(`${e.message.trim()}
|
|
33435
33435
|
|
|
33436
|
-
Context: ${
|
|
33436
|
+
Context: ${context17}`);
|
|
33437
33437
|
if (this.failedTracesDir) {
|
|
33438
33438
|
const bodyBuffer = await this._createNodeFetchBody(parts, boundary).catch(() => null);
|
|
33439
33439
|
if (bodyBuffer) {
|
|
@@ -33943,7 +33943,7 @@ Context: ${context18}`);
|
|
|
33943
33943
|
const withLimit = limit2 !== void 0 ? withOffset.slice(0, limit2) : withOffset;
|
|
33944
33944
|
return withLimit;
|
|
33945
33945
|
}
|
|
33946
|
-
async getRunStats({ id, trace:
|
|
33946
|
+
async getRunStats({ id, trace: trace24, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType }) {
|
|
33947
33947
|
let projectIds_ = projectIds || [];
|
|
33948
33948
|
if (projectNames) {
|
|
33949
33949
|
projectIds_ = [
|
|
@@ -33956,7 +33956,7 @@ Context: ${context18}`);
|
|
|
33956
33956
|
}
|
|
33957
33957
|
const payload = {
|
|
33958
33958
|
id,
|
|
33959
|
-
trace:
|
|
33959
|
+
trace: trace24,
|
|
33960
33960
|
parent_run: parentRun,
|
|
33961
33961
|
run_type: runType,
|
|
33962
33962
|
session: projectIds_,
|
|
@@ -34837,7 +34837,7 @@ Message: ${Array.isArray(result.detail) ? result.detail.join("\n") : "Unspecifie
|
|
|
34837
34837
|
params.append("filter", filter);
|
|
34838
34838
|
}
|
|
34839
34839
|
if (includeAttachments === true) {
|
|
34840
|
-
["attachment_urls", "outputs", "metadata"].forEach((
|
|
34840
|
+
["attachment_urls", "outputs", "metadata"].forEach((field) => params.append("select", field));
|
|
34841
34841
|
}
|
|
34842
34842
|
let i = 0;
|
|
34843
34843
|
for await (const rawExamples of this._getPaginated("/examples", params)) {
|
|
@@ -39514,7 +39514,7 @@ var init_dist2 = __esm({
|
|
|
39514
39514
|
span2.setAttribute(ATTR_GEN_AI_REQUEST_MODEL, requestModel);
|
|
39515
39515
|
}
|
|
39516
39516
|
if (this.traceContent && flatMessages.length > 0) {
|
|
39517
|
-
const
|
|
39517
|
+
const inputMessages = flatMessages.map((message) => {
|
|
39518
39518
|
const role = this.mapMessageTypeToRole(message.type);
|
|
39519
39519
|
const content = typeof message.content === "string" ? message.content : JSON.stringify(message.content);
|
|
39520
39520
|
return {
|
|
@@ -39522,7 +39522,7 @@ var init_dist2 = __esm({
|
|
|
39522
39522
|
parts: [{ type: "text", content }]
|
|
39523
39523
|
};
|
|
39524
39524
|
});
|
|
39525
|
-
span2.setAttribute(ATTR_GEN_AI_INPUT_MESSAGES, JSON.stringify(
|
|
39525
|
+
span2.setAttribute(ATTR_GEN_AI_INPUT_MESSAGES, JSON.stringify(inputMessages));
|
|
39526
39526
|
}
|
|
39527
39527
|
this.spans.set(runId, { span: span2, runId, operationType, requestModel });
|
|
39528
39528
|
});
|
|
@@ -39546,11 +39546,11 @@ var init_dist2 = __esm({
|
|
|
39546
39546
|
span2.setAttribute(ATTR_GEN_AI_REQUEST_MODEL, requestModel);
|
|
39547
39547
|
}
|
|
39548
39548
|
if (this.traceContent && prompts.length > 0) {
|
|
39549
|
-
const
|
|
39549
|
+
const inputMessages = prompts.map((prompt) => ({
|
|
39550
39550
|
role: "user",
|
|
39551
39551
|
parts: [{ type: "text", content: prompt }]
|
|
39552
39552
|
}));
|
|
39553
|
-
span2.setAttribute(ATTR_GEN_AI_INPUT_MESSAGES, JSON.stringify(
|
|
39553
|
+
span2.setAttribute(ATTR_GEN_AI_INPUT_MESSAGES, JSON.stringify(inputMessages));
|
|
39554
39554
|
}
|
|
39555
39555
|
this.spans.set(runId, { span: span2, runId, operationType, requestModel });
|
|
39556
39556
|
});
|
|
@@ -40157,10 +40157,10 @@ var UsageHttpClient = class extends NetraHttpClient {
|
|
|
40157
40157
|
user_id: params.userId,
|
|
40158
40158
|
tenant_id: params.tenantId
|
|
40159
40159
|
};
|
|
40160
|
-
for (const [
|
|
40160
|
+
for (const [field, value] of Object.entries(filterMapping)) {
|
|
40161
40161
|
if (value !== void 0) {
|
|
40162
40162
|
filters.push({
|
|
40163
|
-
field
|
|
40163
|
+
field,
|
|
40164
40164
|
operator: "equals",
|
|
40165
40165
|
type: "string",
|
|
40166
40166
|
value
|
|
@@ -40369,8 +40369,8 @@ var Usage = class {
|
|
|
40369
40369
|
if (!page) {
|
|
40370
40370
|
break;
|
|
40371
40371
|
}
|
|
40372
|
-
for (const
|
|
40373
|
-
yield
|
|
40372
|
+
for (const trace24 of page.traces) {
|
|
40373
|
+
yield trace24;
|
|
40374
40374
|
}
|
|
40375
40375
|
if (!page.hasNextPage || !page.nextCursor) {
|
|
40376
40376
|
break;
|
|
@@ -40483,7 +40483,7 @@ var Usage = class {
|
|
|
40483
40483
|
};
|
|
40484
40484
|
|
|
40485
40485
|
// src/version.ts
|
|
40486
|
-
var SDK_VERSION = "1.
|
|
40486
|
+
var SDK_VERSION = "1.11.0";
|
|
40487
40487
|
|
|
40488
40488
|
// src/config.ts
|
|
40489
40489
|
var NetraInstruments = /* @__PURE__ */ ((NetraInstruments2) => {
|
|
@@ -41847,13 +41847,13 @@ async function runSingleEvaluator(params) {
|
|
|
41847
41847
|
if (config) {
|
|
41848
41848
|
expectedName = config.name;
|
|
41849
41849
|
}
|
|
41850
|
-
const
|
|
41850
|
+
const context17 = {
|
|
41851
41851
|
input: itemInput,
|
|
41852
41852
|
taskOutput,
|
|
41853
41853
|
expectedOutput,
|
|
41854
41854
|
metadata
|
|
41855
41855
|
};
|
|
41856
|
-
let result = evaluator.evaluate(
|
|
41856
|
+
let result = evaluator.evaluate(context17);
|
|
41857
41857
|
if (result instanceof Promise) {
|
|
41858
41858
|
result = await result;
|
|
41859
41859
|
}
|
|
@@ -43850,14 +43850,14 @@ var SpanIOProcessor = class {
|
|
|
43850
43850
|
if (promptMatch) {
|
|
43851
43851
|
original(key, value);
|
|
43852
43852
|
const idx = parseInt(promptMatch[1], 10);
|
|
43853
|
-
const
|
|
43853
|
+
const field = promptMatch[2];
|
|
43854
43854
|
if (!prompts) prompts = /* @__PURE__ */ new Map();
|
|
43855
43855
|
let entry = prompts.get(idx);
|
|
43856
43856
|
if (!entry) {
|
|
43857
43857
|
entry = {};
|
|
43858
43858
|
prompts.set(idx, entry);
|
|
43859
43859
|
}
|
|
43860
|
-
entry[
|
|
43860
|
+
entry[field] = String(value);
|
|
43861
43861
|
if (!inputLocked() && (inputIsEmpty() || genAiOwnsInput)) {
|
|
43862
43862
|
original("input", buildMessages(prompts));
|
|
43863
43863
|
genAiOwnsInput = true;
|
|
@@ -43868,14 +43868,14 @@ var SpanIOProcessor = class {
|
|
|
43868
43868
|
if (completionMatch) {
|
|
43869
43869
|
original(key, value);
|
|
43870
43870
|
const idx = parseInt(completionMatch[1], 10);
|
|
43871
|
-
const
|
|
43871
|
+
const field = completionMatch[2];
|
|
43872
43872
|
if (!completions) completions = /* @__PURE__ */ new Map();
|
|
43873
43873
|
let entry = completions.get(idx);
|
|
43874
43874
|
if (!entry) {
|
|
43875
43875
|
entry = {};
|
|
43876
43876
|
completions.set(idx, entry);
|
|
43877
43877
|
}
|
|
43878
|
-
entry[
|
|
43878
|
+
entry[field] = String(value);
|
|
43879
43879
|
if (!outputLocked() && (outputIsEmpty() || genAiOwnsOutput)) {
|
|
43880
43880
|
original("output", buildMessages(completions));
|
|
43881
43881
|
genAiOwnsOutput = true;
|
|
@@ -44135,6 +44135,8 @@ var SpanAttributes2 = {
|
|
|
44135
44135
|
LLM_USAGE_COMPLETION_TOKENS: "gen_ai.usage.completion_tokens",
|
|
44136
44136
|
LLM_USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read_input_tokens",
|
|
44137
44137
|
LLM_USAGE_CACHE_CREATION_INPUT_TOKENS: "gen_ai.usage.cache_creation_input_tokens",
|
|
44138
|
+
LLM_USAGE_CACHE_CREATION_INPUT_TOKENS_30M: "gen_ai.usage.cache_creation_input_tokens_30m",
|
|
44139
|
+
LLM_USAGE_CACHE_CREATION_INPUT_TOKENS_12H: "gen_ai.usage.cache_creation_input_tokens_12h",
|
|
44138
44140
|
LLM_USAGE_REASONING_TOKENS: "gen_ai.usage.reasoning_tokens",
|
|
44139
44141
|
LLM_USAGE_TOTAL_TOKENS: "llm.usage.total_tokens",
|
|
44140
44142
|
LLM_FREQUENCY_PENALTY: "llm.frequency_penalty",
|
|
@@ -44142,33 +44144,7 @@ var SpanAttributes2 = {
|
|
|
44142
44144
|
LLM_CHAT_STOP_SEQUENCES: "llm.chat.stop_sequences",
|
|
44143
44145
|
LLM_IS_STREAMING: "llm.is_streaming",
|
|
44144
44146
|
LLM_COMPLETIONS: "gen_ai.completion",
|
|
44145
|
-
LLM_PROMPTS: "gen_ai.prompt"
|
|
44146
|
-
// Google GenAI Interactions API. Its request is flat snake_case and its
|
|
44147
|
-
// response is a multi-step Interaction, so it needs names the chat/embedding
|
|
44148
|
-
// surfaces have no equivalent for.
|
|
44149
|
-
LLM_REQUEST_AGENT: "gen_ai.request.agent",
|
|
44150
|
-
LLM_REQUEST_AGENT_CONFIG: "gen_ai.request.agent_config",
|
|
44151
|
-
LLM_REQUEST_SEED: "gen_ai.request.seed",
|
|
44152
|
-
LLM_REQUEST_THINKING_SUMMARIES: "gen_ai.request.thinking_summaries",
|
|
44153
|
-
LLM_REQUEST_TOOL_CHOICE: "llm.request.tool_choice",
|
|
44154
|
-
LLM_REQUEST_TOOLS: "llm.request.functions",
|
|
44155
|
-
LLM_REQUEST_STORE: "gen_ai.request.store",
|
|
44156
|
-
LLM_REQUEST_BACKGROUND: "gen_ai.request.background",
|
|
44157
|
-
LLM_REQUEST_PREVIOUS_INTERACTION_ID: "gen_ai.request.previous_interaction_id",
|
|
44158
|
-
LLM_REQUEST_RESPONSE_FORMAT: "gen_ai.request.response_format",
|
|
44159
|
-
LLM_REQUEST_RESPONSE_MIME_TYPE: "gen_ai.request.response_mime_type",
|
|
44160
|
-
LLM_REQUEST_RESPONSE_MODALITIES: "gen_ai.request.response_modalities",
|
|
44161
|
-
LLM_REQUEST_SERVICE_TIER: "gen_ai.request.service_tier",
|
|
44162
|
-
LLM_RESPONSE_ID: "gen_ai.response.id",
|
|
44163
|
-
LLM_RESPONSE_STATUS: "gen_ai.response.status",
|
|
44164
|
-
LLM_RESPONSE_PREVIOUS_INTERACTION_ID: "gen_ai.response.previous_interaction_id",
|
|
44165
|
-
LLM_RESPONSE_REASONING: "llm.response.reasoning",
|
|
44166
|
-
LLM_INTERACTION_STEP_COUNT: "gen_ai.interaction.step_count",
|
|
44167
|
-
LLM_USAGE_TOOL_USE_TOKENS: "gen_ai.usage.tool_use_tokens",
|
|
44168
|
-
LLM_USAGE_GROUNDING_TOOL_COUNT: "gen_ai.usage.grounding_tool_count",
|
|
44169
|
-
// Set when a stream is consumed through a path we cannot observe
|
|
44170
|
-
// (getReader/pipeTo/pipeThrough/tee), so the span closes instead of leaking.
|
|
44171
|
-
STREAM_UNOBSERVED: "netra.stream.unobserved"
|
|
44147
|
+
LLM_PROMPTS: "gen_ai.prompt"
|
|
44172
44148
|
};
|
|
44173
44149
|
var VALID_NATIVE_TRACING_MODES = /* @__PURE__ */ new Set(["both", "netra", "netra-strict"]);
|
|
44174
44150
|
function parseNativeTracingEnv(name) {
|
|
@@ -44498,6 +44474,19 @@ function setFinishReason(span2, response) {
|
|
|
44498
44474
|
}
|
|
44499
44475
|
}
|
|
44500
44476
|
}
|
|
44477
|
+
var CACHE_WRITE_TTL_ATTRIBUTES = {
|
|
44478
|
+
ttl_30m_tokens: SpanAttributes2.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS_30M,
|
|
44479
|
+
ttl_12h_tokens: SpanAttributes2.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS_12H
|
|
44480
|
+
};
|
|
44481
|
+
function setCacheWriteTtlAttributes(span2, inputTokensDetails) {
|
|
44482
|
+
if (!isDict(inputTokensDetails)) return;
|
|
44483
|
+
const breakdown = inputTokensDetails.cache_write_tokens_details;
|
|
44484
|
+
if (!isDict(breakdown)) return;
|
|
44485
|
+
for (const [field, attribute] of Object.entries(CACHE_WRITE_TTL_ATTRIBUTES)) {
|
|
44486
|
+
const tokens = breakdown[field];
|
|
44487
|
+
if (typeof tokens === "number") span2.setAttribute(attribute, tokens);
|
|
44488
|
+
}
|
|
44489
|
+
}
|
|
44501
44490
|
function setUsageAttributes(span2, response) {
|
|
44502
44491
|
const usage = response.usage ?? response.usage_metadata;
|
|
44503
44492
|
if (!usage) return;
|
|
@@ -44536,6 +44525,10 @@ function setUsageAttributes(span2, response) {
|
|
|
44536
44525
|
Number(cacheCreationTokens)
|
|
44537
44526
|
);
|
|
44538
44527
|
}
|
|
44528
|
+
setCacheWriteTtlAttributes(
|
|
44529
|
+
span2,
|
|
44530
|
+
usage.prompt_tokens_details ?? usage.input_tokens_details
|
|
44531
|
+
);
|
|
44539
44532
|
const reasoningTokens = (usage.completion_tokens_details ?? usage.output_tokens_details)?.reasoning_tokens;
|
|
44540
44533
|
if (reasoningTokens !== void 0) {
|
|
44541
44534
|
span2.setAttribute(
|
|
@@ -45685,6 +45678,15 @@ var BaseInstrumentor = class {
|
|
|
45685
45678
|
}
|
|
45686
45679
|
};
|
|
45687
45680
|
|
|
45681
|
+
// src/instrumentation/google-genai/version.ts
|
|
45682
|
+
var __version__2 = "1.0.0";
|
|
45683
|
+
|
|
45684
|
+
// src/instrumentation/google-genai/types.ts
|
|
45685
|
+
var SPAN_NAMES2 = {
|
|
45686
|
+
CHAT: "google_genai.chat",
|
|
45687
|
+
EMBEDDING: "google_genai.embedding"
|
|
45688
|
+
};
|
|
45689
|
+
|
|
45688
45690
|
// src/instrumentation/google-genai/utils.ts
|
|
45689
45691
|
var LOG_PREFIX = "netra.instrumentation.google_genai";
|
|
45690
45692
|
function setRequestAttributes3(span2, params, requestType) {
|
|
@@ -46067,880 +46069,8 @@ function buildAccumulatedResponse(accumulated) {
|
|
|
46067
46069
|
return response;
|
|
46068
46070
|
}
|
|
46069
46071
|
|
|
46070
|
-
// src/instrumentation/google-genai/
|
|
46072
|
+
// src/instrumentation/google-genai/wrappers.ts
|
|
46071
46073
|
var LOG_PREFIX2 = "netra.instrumentation.google_genai";
|
|
46072
|
-
var CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
46073
|
-
"text",
|
|
46074
|
-
"image",
|
|
46075
|
-
"audio",
|
|
46076
|
-
"document",
|
|
46077
|
-
"video"
|
|
46078
|
-
]);
|
|
46079
|
-
var SERVER_TOOL_CALL_STEPS = /* @__PURE__ */ new Set([
|
|
46080
|
-
"code_execution_call",
|
|
46081
|
-
"url_context_call",
|
|
46082
|
-
"google_search_call",
|
|
46083
|
-
"google_maps_call",
|
|
46084
|
-
"file_search_call",
|
|
46085
|
-
"mcp_server_tool_call"
|
|
46086
|
-
]);
|
|
46087
|
-
var SERVER_TOOL_RESULT_STEPS = /* @__PURE__ */ new Set([
|
|
46088
|
-
"code_execution_result",
|
|
46089
|
-
"url_context_result",
|
|
46090
|
-
"google_search_result",
|
|
46091
|
-
"google_maps_result",
|
|
46092
|
-
"file_search_result",
|
|
46093
|
-
"mcp_server_tool_result"
|
|
46094
|
-
]);
|
|
46095
|
-
var STEP_TYPES = /* @__PURE__ */ new Set([
|
|
46096
|
-
"user_input",
|
|
46097
|
-
"model_output",
|
|
46098
|
-
"thought",
|
|
46099
|
-
"function_call",
|
|
46100
|
-
"function_result",
|
|
46101
|
-
...SERVER_TOOL_CALL_STEPS,
|
|
46102
|
-
...SERVER_TOOL_RESULT_STEPS
|
|
46103
|
-
]);
|
|
46104
|
-
function field(obj, name) {
|
|
46105
|
-
if (!isDict(obj)) return void 0;
|
|
46106
|
-
return obj[name];
|
|
46107
|
-
}
|
|
46108
|
-
function asArray(value) {
|
|
46109
|
-
if (value === null || value === void 0) return [];
|
|
46110
|
-
return Array.isArray(value) ? value : [value];
|
|
46111
|
-
}
|
|
46112
|
-
function contentText(items) {
|
|
46113
|
-
const parts = [];
|
|
46114
|
-
for (const item of asArray(items)) {
|
|
46115
|
-
const itemType = field(item, "type");
|
|
46116
|
-
if (itemType === "text") {
|
|
46117
|
-
const text = field(item, "text");
|
|
46118
|
-
if (typeof text === "string") parts.push(text);
|
|
46119
|
-
} else if (typeof itemType === "string" && CONTENT_TYPES.has(itemType)) {
|
|
46120
|
-
parts.push(`<${itemType}>`);
|
|
46121
|
-
}
|
|
46122
|
-
}
|
|
46123
|
-
return parts.join("");
|
|
46124
|
-
}
|
|
46125
|
-
function contentModalities(items) {
|
|
46126
|
-
const modalities = [];
|
|
46127
|
-
for (const item of asArray(items)) {
|
|
46128
|
-
const itemType = field(item, "type");
|
|
46129
|
-
if (typeof itemType === "string" && CONTENT_TYPES.has(itemType) && itemType !== "text" && !modalities.includes(itemType)) {
|
|
46130
|
-
modalities.push(itemType);
|
|
46131
|
-
}
|
|
46132
|
-
}
|
|
46133
|
-
return modalities;
|
|
46134
|
-
}
|
|
46135
|
-
function stepMessage(step) {
|
|
46136
|
-
const stepType = field(step, "type");
|
|
46137
|
-
if (typeof stepType !== "string") return null;
|
|
46138
|
-
if (stepType === "user_input") {
|
|
46139
|
-
return {
|
|
46140
|
-
role: "user",
|
|
46141
|
-
content: contentText(field(step, "content")),
|
|
46142
|
-
stepType
|
|
46143
|
-
};
|
|
46144
|
-
}
|
|
46145
|
-
if (stepType === "model_output") {
|
|
46146
|
-
const content = field(step, "content");
|
|
46147
|
-
return {
|
|
46148
|
-
role: "assistant",
|
|
46149
|
-
content: contentText(content),
|
|
46150
|
-
stepType,
|
|
46151
|
-
modalities: contentModalities(content)
|
|
46152
|
-
};
|
|
46153
|
-
}
|
|
46154
|
-
if (stepType === "thought") {
|
|
46155
|
-
return {
|
|
46156
|
-
role: "assistant",
|
|
46157
|
-
content: contentText(field(step, "summary")),
|
|
46158
|
-
stepType
|
|
46159
|
-
};
|
|
46160
|
-
}
|
|
46161
|
-
if (stepType === "function_call") {
|
|
46162
|
-
const toolCall = {
|
|
46163
|
-
name: field(step, "name"),
|
|
46164
|
-
id: field(step, "id"),
|
|
46165
|
-
arguments: field(step, "arguments")
|
|
46166
|
-
};
|
|
46167
|
-
return {
|
|
46168
|
-
role: "assistant",
|
|
46169
|
-
content: safeStringify(toolCall),
|
|
46170
|
-
stepType,
|
|
46171
|
-
toolCall
|
|
46172
|
-
};
|
|
46173
|
-
}
|
|
46174
|
-
if (stepType === "function_result") {
|
|
46175
|
-
const name = field(step, "name");
|
|
46176
|
-
return {
|
|
46177
|
-
role: "tool",
|
|
46178
|
-
content: safeStringify({
|
|
46179
|
-
call_id: field(step, "call_id"),
|
|
46180
|
-
name,
|
|
46181
|
-
result: field(step, "result"),
|
|
46182
|
-
is_error: field(step, "is_error")
|
|
46183
|
-
}),
|
|
46184
|
-
stepType,
|
|
46185
|
-
toolCall: { name }
|
|
46186
|
-
};
|
|
46187
|
-
}
|
|
46188
|
-
if (SERVER_TOOL_CALL_STEPS.has(stepType)) {
|
|
46189
|
-
return {
|
|
46190
|
-
role: "tool",
|
|
46191
|
-
content: safeStringify({
|
|
46192
|
-
name: stepType,
|
|
46193
|
-
arguments: field(step, "arguments")
|
|
46194
|
-
}),
|
|
46195
|
-
stepType,
|
|
46196
|
-
toolCall: { name: stepType }
|
|
46197
|
-
};
|
|
46198
|
-
}
|
|
46199
|
-
if (SERVER_TOOL_RESULT_STEPS.has(stepType)) {
|
|
46200
|
-
return {
|
|
46201
|
-
role: "tool",
|
|
46202
|
-
content: safeStringify({ name: stepType, result: field(step, "result") }),
|
|
46203
|
-
stepType,
|
|
46204
|
-
toolCall: { name: stepType }
|
|
46205
|
-
};
|
|
46206
|
-
}
|
|
46207
|
-
return { role: "assistant", content: safeStringify(step), stepType };
|
|
46208
|
-
}
|
|
46209
|
-
function inputMessages(value) {
|
|
46210
|
-
if (value === null || value === void 0) return [];
|
|
46211
|
-
if (typeof value === "string") {
|
|
46212
|
-
return [{ role: "user", content: value }];
|
|
46213
|
-
}
|
|
46214
|
-
if (Array.isArray(value)) {
|
|
46215
|
-
if (value.length === 0) return [];
|
|
46216
|
-
const types = value.map((item) => field(item, "type"));
|
|
46217
|
-
if (types.every((t) => typeof t === "string" && STEP_TYPES.has(t))) {
|
|
46218
|
-
const messages = [];
|
|
46219
|
-
for (const item of value) {
|
|
46220
|
-
const message = stepMessage(item);
|
|
46221
|
-
if (message && message.stepType !== "thought" && message.content) {
|
|
46222
|
-
messages.push(message);
|
|
46223
|
-
}
|
|
46224
|
-
}
|
|
46225
|
-
return messages;
|
|
46226
|
-
}
|
|
46227
|
-
if (types.every((t) => typeof t === "string" && CONTENT_TYPES.has(t))) {
|
|
46228
|
-
return [{ role: "user", content: contentText(value) }];
|
|
46229
|
-
}
|
|
46230
|
-
return [{ role: "user", content: safeStringify(value) }];
|
|
46231
|
-
}
|
|
46232
|
-
const valueType = field(value, "type");
|
|
46233
|
-
if (typeof valueType === "string" && CONTENT_TYPES.has(valueType)) {
|
|
46234
|
-
return [{ role: "user", content: contentText([value]) }];
|
|
46235
|
-
}
|
|
46236
|
-
if (typeof valueType === "string" && STEP_TYPES.has(valueType)) {
|
|
46237
|
-
const message = stepMessage(value);
|
|
46238
|
-
return message && message.content ? [message] : [];
|
|
46239
|
-
}
|
|
46240
|
-
return [{ role: "user", content: safeStringify(value) }];
|
|
46241
|
-
}
|
|
46242
|
-
function setToolDefinitions(span2, tools) {
|
|
46243
|
-
if (!Array.isArray(tools)) return;
|
|
46244
|
-
tools.forEach((tool, index) => {
|
|
46245
|
-
const toolType = field(tool, "type");
|
|
46246
|
-
const prefix = `${SpanAttributes2.LLM_REQUEST_TOOLS}.${index}`;
|
|
46247
|
-
if (toolType === "function") {
|
|
46248
|
-
const fn = field(tool, "function") ?? tool;
|
|
46249
|
-
span2.setAttribute(`${prefix}.name`, String(field(fn, "name") ?? ""));
|
|
46250
|
-
const description = field(fn, "description");
|
|
46251
|
-
if (description !== void 0) {
|
|
46252
|
-
span2.setAttribute(`${prefix}.description`, String(description));
|
|
46253
|
-
}
|
|
46254
|
-
const parameters = field(fn, "parameters");
|
|
46255
|
-
if (parameters !== void 0) {
|
|
46256
|
-
span2.setAttribute(`${prefix}.parameters`, safeStringify(parameters));
|
|
46257
|
-
}
|
|
46258
|
-
} else if (typeof toolType === "string") {
|
|
46259
|
-
span2.setAttribute(`${prefix}.name`, toolType);
|
|
46260
|
-
}
|
|
46261
|
-
});
|
|
46262
|
-
}
|
|
46263
|
-
function setInteractionRequestAttributes(span2, params) {
|
|
46264
|
-
try {
|
|
46265
|
-
if (!span2.isRecording()) return;
|
|
46266
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_TYPE, "chat");
|
|
46267
|
-
span2.setAttribute(SpanAttributes2.LLM_SYSTEM, "google_genai");
|
|
46268
|
-
if (params.model) {
|
|
46269
|
-
span2.setAttribute(
|
|
46270
|
-
SpanAttributes2.LLM_REQUEST_MODEL,
|
|
46271
|
-
extractModelName(String(params.model))
|
|
46272
|
-
);
|
|
46273
|
-
}
|
|
46274
|
-
if (params.agent !== void 0) {
|
|
46275
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_AGENT, String(params.agent));
|
|
46276
|
-
}
|
|
46277
|
-
if (params.agent_config !== void 0) {
|
|
46278
|
-
span2.setAttribute(
|
|
46279
|
-
SpanAttributes2.LLM_REQUEST_AGENT_CONFIG,
|
|
46280
|
-
safeStringify(params.agent_config)
|
|
46281
|
-
);
|
|
46282
|
-
}
|
|
46283
|
-
const cfg = params.generation_config;
|
|
46284
|
-
if (isDict(cfg)) {
|
|
46285
|
-
if (cfg.temperature !== void 0) {
|
|
46286
|
-
span2.setAttribute(
|
|
46287
|
-
SpanAttributes2.LLM_REQUEST_TEMPERATURE,
|
|
46288
|
-
Number(cfg.temperature)
|
|
46289
|
-
);
|
|
46290
|
-
}
|
|
46291
|
-
if (cfg.top_p !== void 0) {
|
|
46292
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_TOP_P, Number(cfg.top_p));
|
|
46293
|
-
}
|
|
46294
|
-
if (cfg.max_output_tokens !== void 0) {
|
|
46295
|
-
span2.setAttribute(
|
|
46296
|
-
SpanAttributes2.LLM_REQUEST_MAX_TOKENS,
|
|
46297
|
-
Number(cfg.max_output_tokens)
|
|
46298
|
-
);
|
|
46299
|
-
}
|
|
46300
|
-
if (cfg.seed !== void 0) {
|
|
46301
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_SEED, Number(cfg.seed));
|
|
46302
|
-
}
|
|
46303
|
-
if (cfg.stop_sequences !== void 0) {
|
|
46304
|
-
span2.setAttribute(
|
|
46305
|
-
SpanAttributes2.LLM_CHAT_STOP_SEQUENCES,
|
|
46306
|
-
safeStringify(cfg.stop_sequences)
|
|
46307
|
-
);
|
|
46308
|
-
}
|
|
46309
|
-
if (cfg.thinking_level !== void 0) {
|
|
46310
|
-
span2.setAttribute(
|
|
46311
|
-
SpanAttributes2.LLM_REQUEST_REASONING_EFFORT,
|
|
46312
|
-
String(cfg.thinking_level)
|
|
46313
|
-
);
|
|
46314
|
-
}
|
|
46315
|
-
if (cfg.thinking_summaries !== void 0) {
|
|
46316
|
-
span2.setAttribute(
|
|
46317
|
-
SpanAttributes2.LLM_REQUEST_THINKING_SUMMARIES,
|
|
46318
|
-
String(cfg.thinking_summaries)
|
|
46319
|
-
);
|
|
46320
|
-
}
|
|
46321
|
-
if (cfg.tool_choice !== void 0) {
|
|
46322
|
-
span2.setAttribute(
|
|
46323
|
-
SpanAttributes2.LLM_REQUEST_TOOL_CHOICE,
|
|
46324
|
-
safeStringify(cfg.tool_choice)
|
|
46325
|
-
);
|
|
46326
|
-
}
|
|
46327
|
-
}
|
|
46328
|
-
setToolDefinitions(span2, params.tools);
|
|
46329
|
-
if (typeof params.store === "boolean") {
|
|
46330
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_STORE, params.store);
|
|
46331
|
-
}
|
|
46332
|
-
if (typeof params.background === "boolean") {
|
|
46333
|
-
span2.setAttribute(
|
|
46334
|
-
SpanAttributes2.LLM_REQUEST_BACKGROUND,
|
|
46335
|
-
params.background
|
|
46336
|
-
);
|
|
46337
|
-
}
|
|
46338
|
-
if (params.previous_interaction_id !== void 0) {
|
|
46339
|
-
span2.setAttribute(
|
|
46340
|
-
SpanAttributes2.LLM_REQUEST_PREVIOUS_INTERACTION_ID,
|
|
46341
|
-
String(params.previous_interaction_id)
|
|
46342
|
-
);
|
|
46343
|
-
}
|
|
46344
|
-
if (params.response_mime_type !== void 0) {
|
|
46345
|
-
span2.setAttribute(
|
|
46346
|
-
SpanAttributes2.LLM_REQUEST_RESPONSE_MIME_TYPE,
|
|
46347
|
-
String(params.response_mime_type)
|
|
46348
|
-
);
|
|
46349
|
-
}
|
|
46350
|
-
if (params.service_tier !== void 0) {
|
|
46351
|
-
span2.setAttribute(
|
|
46352
|
-
SpanAttributes2.LLM_REQUEST_SERVICE_TIER,
|
|
46353
|
-
String(params.service_tier)
|
|
46354
|
-
);
|
|
46355
|
-
}
|
|
46356
|
-
if (params.response_format !== void 0) {
|
|
46357
|
-
span2.setAttribute(
|
|
46358
|
-
SpanAttributes2.LLM_REQUEST_RESPONSE_FORMAT,
|
|
46359
|
-
safeStringify(params.response_format)
|
|
46360
|
-
);
|
|
46361
|
-
}
|
|
46362
|
-
if (Array.isArray(params.response_modalities)) {
|
|
46363
|
-
span2.setAttribute(
|
|
46364
|
-
SpanAttributes2.LLM_REQUEST_RESPONSE_MODALITIES,
|
|
46365
|
-
params.response_modalities.map((m) => String(m))
|
|
46366
|
-
);
|
|
46367
|
-
}
|
|
46368
|
-
if (!isTraceContentEnabled()) return;
|
|
46369
|
-
const messages = [];
|
|
46370
|
-
if (params.system_instruction !== void 0) {
|
|
46371
|
-
messages.push({
|
|
46372
|
-
role: "system",
|
|
46373
|
-
content: String(params.system_instruction)
|
|
46374
|
-
});
|
|
46375
|
-
}
|
|
46376
|
-
messages.push(...inputMessages(params.input));
|
|
46377
|
-
writePromptAttributes(
|
|
46378
|
-
span2,
|
|
46379
|
-
messages.filter((m) => m.content)
|
|
46380
|
-
);
|
|
46381
|
-
} catch (e) {
|
|
46382
|
-
Logger.error(`${LOG_PREFIX2}: setInteractionRequestAttributes error`, e);
|
|
46383
|
-
}
|
|
46384
|
-
}
|
|
46385
|
-
var MODALITY_USAGE_PREFIXES = {
|
|
46386
|
-
input_tokens_by_modality: "gen_ai.usage.input_tokens_by_modality",
|
|
46387
|
-
output_tokens_by_modality: "gen_ai.usage.output_tokens_by_modality",
|
|
46388
|
-
cached_tokens_by_modality: "gen_ai.usage.cached_tokens_by_modality",
|
|
46389
|
-
tool_use_tokens_by_modality: "gen_ai.usage.tool_use_tokens_by_modality"
|
|
46390
|
-
};
|
|
46391
|
-
function setUsageAttributes3(span2, usage) {
|
|
46392
|
-
if (!isDict(usage)) return;
|
|
46393
|
-
const totals = [
|
|
46394
|
-
["total_input_tokens", SpanAttributes2.LLM_USAGE_PROMPT_TOKENS],
|
|
46395
|
-
["total_tokens", SpanAttributes2.LLM_USAGE_TOTAL_TOKENS],
|
|
46396
|
-
["total_cached_tokens", SpanAttributes2.LLM_USAGE_CACHE_READ_INPUT_TOKENS],
|
|
46397
|
-
["total_thought_tokens", SpanAttributes2.LLM_USAGE_REASONING_TOKENS],
|
|
46398
|
-
["total_tool_use_tokens", SpanAttributes2.LLM_USAGE_TOOL_USE_TOKENS]
|
|
46399
|
-
];
|
|
46400
|
-
for (const [field_, attribute] of totals) {
|
|
46401
|
-
const value = usage[field_];
|
|
46402
|
-
if (typeof value === "number") span2.setAttribute(attribute, value);
|
|
46403
|
-
}
|
|
46404
|
-
let completion = 0;
|
|
46405
|
-
let hasCompletion = false;
|
|
46406
|
-
for (const field_ of ["total_output_tokens", "total_thought_tokens"]) {
|
|
46407
|
-
const value = usage[field_];
|
|
46408
|
-
if (typeof value === "number") {
|
|
46409
|
-
completion += value;
|
|
46410
|
-
hasCompletion = true;
|
|
46411
|
-
}
|
|
46412
|
-
}
|
|
46413
|
-
if (hasCompletion) {
|
|
46414
|
-
span2.setAttribute(SpanAttributes2.LLM_USAGE_COMPLETION_TOKENS, completion);
|
|
46415
|
-
}
|
|
46416
|
-
for (const [field_, prefix] of Object.entries(MODALITY_USAGE_PREFIXES)) {
|
|
46417
|
-
const entries = usage[field_];
|
|
46418
|
-
if (!Array.isArray(entries)) continue;
|
|
46419
|
-
for (const entry of entries) {
|
|
46420
|
-
const modality = field(entry, "modality");
|
|
46421
|
-
const tokens = field(entry, "tokens");
|
|
46422
|
-
if (modality && typeof tokens === "number") {
|
|
46423
|
-
span2.setAttribute(`${prefix}.${String(modality)}`, tokens);
|
|
46424
|
-
}
|
|
46425
|
-
}
|
|
46426
|
-
}
|
|
46427
|
-
const grounding = usage.grounding_tool_count;
|
|
46428
|
-
if (Array.isArray(grounding)) {
|
|
46429
|
-
for (const entry of grounding) {
|
|
46430
|
-
const toolType = field(entry, "type");
|
|
46431
|
-
const count = field(entry, "count");
|
|
46432
|
-
if (toolType && typeof count === "number") {
|
|
46433
|
-
span2.setAttribute(
|
|
46434
|
-
`${SpanAttributes2.LLM_USAGE_GROUNDING_TOOL_COUNT}.${String(toolType)}`,
|
|
46435
|
-
count
|
|
46436
|
-
);
|
|
46437
|
-
}
|
|
46438
|
-
}
|
|
46439
|
-
}
|
|
46440
|
-
}
|
|
46441
|
-
function outputSteps(steps) {
|
|
46442
|
-
if (!Array.isArray(steps)) return [];
|
|
46443
|
-
let firstOutput = 0;
|
|
46444
|
-
steps.forEach((step, index) => {
|
|
46445
|
-
if (field(step, "type") === "user_input") firstOutput = index + 1;
|
|
46446
|
-
});
|
|
46447
|
-
return steps.slice(firstOutput);
|
|
46448
|
-
}
|
|
46449
|
-
function interactionOutputText(steps) {
|
|
46450
|
-
return outputSteps(steps).filter((step) => field(step, "type") === "model_output").map((step) => contentText(field(step, "content"))).join("");
|
|
46451
|
-
}
|
|
46452
|
-
function setInteractionResponseAttributes(span2, interaction) {
|
|
46453
|
-
try {
|
|
46454
|
-
if (!span2.isRecording() || !isDict(interaction)) return;
|
|
46455
|
-
if (interaction.id !== void 0 && interaction.id !== null) {
|
|
46456
|
-
const id = String(interaction.id);
|
|
46457
|
-
span2.setAttribute(SpanAttributes2.LLM_RESPONSE_ID, id);
|
|
46458
|
-
span2.setAttribute("llm.response.id", id);
|
|
46459
|
-
}
|
|
46460
|
-
if (interaction.model !== void 0 && interaction.model !== null) {
|
|
46461
|
-
span2.setAttribute(
|
|
46462
|
-
SpanAttributes2.LLM_RESPONSE_MODEL,
|
|
46463
|
-
String(interaction.model)
|
|
46464
|
-
);
|
|
46465
|
-
}
|
|
46466
|
-
if (interaction.status !== void 0 && interaction.status !== null) {
|
|
46467
|
-
const status = String(interaction.status);
|
|
46468
|
-
span2.setAttribute(SpanAttributes2.LLM_RESPONSE_STATUS, status);
|
|
46469
|
-
span2.setAttribute(SpanAttributes2.LLM_RESPONSE_FINISH_REASON, status);
|
|
46470
|
-
span2.setAttribute("gen_ai.response.finish_reason", status);
|
|
46471
|
-
}
|
|
46472
|
-
if (interaction.previous_interaction_id !== void 0 && interaction.previous_interaction_id !== null) {
|
|
46473
|
-
span2.setAttribute(
|
|
46474
|
-
SpanAttributes2.LLM_RESPONSE_PREVIOUS_INTERACTION_ID,
|
|
46475
|
-
String(interaction.previous_interaction_id)
|
|
46476
|
-
);
|
|
46477
|
-
}
|
|
46478
|
-
setUsageAttributes3(span2, interaction.usage);
|
|
46479
|
-
if (Array.isArray(interaction.steps)) {
|
|
46480
|
-
span2.setAttribute(
|
|
46481
|
-
SpanAttributes2.LLM_INTERACTION_STEP_COUNT,
|
|
46482
|
-
interaction.steps.length
|
|
46483
|
-
);
|
|
46484
|
-
}
|
|
46485
|
-
if (!isTraceContentEnabled()) return;
|
|
46486
|
-
const reasoning = [];
|
|
46487
|
-
const emitted = [];
|
|
46488
|
-
let index = 0;
|
|
46489
|
-
for (const step of outputSteps(interaction.steps)) {
|
|
46490
|
-
const message = stepMessage(step);
|
|
46491
|
-
if (!message) continue;
|
|
46492
|
-
if (message.stepType === "thought") {
|
|
46493
|
-
if (message.content) reasoning.push(message.content);
|
|
46494
|
-
continue;
|
|
46495
|
-
}
|
|
46496
|
-
if (!message.content) continue;
|
|
46497
|
-
const prefix = `${SpanAttributes2.LLM_COMPLETIONS}.${index}`;
|
|
46498
|
-
span2.setAttribute(`${prefix}.role`, message.role);
|
|
46499
|
-
span2.setAttribute(`${prefix}.content`, message.content);
|
|
46500
|
-
span2.setAttribute(`${prefix}.step_type`, message.stepType ?? "");
|
|
46501
|
-
if (message.toolCall) {
|
|
46502
|
-
span2.setAttribute(
|
|
46503
|
-
`${prefix}.tool_calls.0.name`,
|
|
46504
|
-
String(message.toolCall.name ?? "")
|
|
46505
|
-
);
|
|
46506
|
-
if (message.toolCall.id !== void 0) {
|
|
46507
|
-
span2.setAttribute(
|
|
46508
|
-
`${prefix}.tool_calls.0.id`,
|
|
46509
|
-
String(message.toolCall.id)
|
|
46510
|
-
);
|
|
46511
|
-
}
|
|
46512
|
-
if (message.toolCall.arguments !== void 0) {
|
|
46513
|
-
span2.setAttribute(
|
|
46514
|
-
`${prefix}.tool_calls.0.arguments`,
|
|
46515
|
-
safeStringify(message.toolCall.arguments)
|
|
46516
|
-
);
|
|
46517
|
-
}
|
|
46518
|
-
}
|
|
46519
|
-
if (message.modalities && message.modalities.length > 0) {
|
|
46520
|
-
span2.setAttribute(`${prefix}.modality`, message.modalities);
|
|
46521
|
-
}
|
|
46522
|
-
emitted.push(message);
|
|
46523
|
-
index += 1;
|
|
46524
|
-
}
|
|
46525
|
-
if (emitted.length > 0) {
|
|
46526
|
-
span2.setAttribute(
|
|
46527
|
-
"output",
|
|
46528
|
-
JSON.stringify(
|
|
46529
|
-
emitted.map((m) => ({ role: m.role, content: m.content }))
|
|
46530
|
-
)
|
|
46531
|
-
);
|
|
46532
|
-
}
|
|
46533
|
-
if (reasoning.length > 0) {
|
|
46534
|
-
span2.setAttribute(
|
|
46535
|
-
SpanAttributes2.LLM_RESPONSE_REASONING,
|
|
46536
|
-
reasoning.join("")
|
|
46537
|
-
);
|
|
46538
|
-
}
|
|
46539
|
-
} catch (e) {
|
|
46540
|
-
Logger.error(`${LOG_PREFIX2}: setInteractionResponseAttributes error`, e);
|
|
46541
|
-
}
|
|
46542
|
-
}
|
|
46543
|
-
|
|
46544
|
-
// src/instrumentation/google-genai/types.ts
|
|
46545
|
-
var SPAN_NAMES2 = {
|
|
46546
|
-
CHAT: "google_genai.chat",
|
|
46547
|
-
EMBEDDING: "google_genai.embedding",
|
|
46548
|
-
INTERACTION: "google_genai.interaction"
|
|
46549
|
-
};
|
|
46550
|
-
|
|
46551
|
-
// src/instrumentation/google-genai/interactions-wrapper.ts
|
|
46552
|
-
var LOG_PREFIX3 = "netra.instrumentation.google_genai";
|
|
46553
|
-
var NETRA_STREAM = /* @__PURE__ */ Symbol.for("netra.googlegenai.interactions.stream");
|
|
46554
|
-
var INTERACTION_CREATED = "interaction.created";
|
|
46555
|
-
var INTERACTION_COMPLETED = "interaction.completed";
|
|
46556
|
-
var INTERACTION_STATUS_UPDATE = "interaction.status_update";
|
|
46557
|
-
var STEP_START = "step.start";
|
|
46558
|
-
var STEP_DELTA = "step.delta";
|
|
46559
|
-
var ERROR_EVENT = "error";
|
|
46560
|
-
function field2(obj, name) {
|
|
46561
|
-
if (obj === null || obj === void 0) return void 0;
|
|
46562
|
-
return obj[name];
|
|
46563
|
-
}
|
|
46564
|
-
var InteractionStreamAccumulator = class {
|
|
46565
|
-
constructor(span2, startTime) {
|
|
46566
|
-
this.span = span2;
|
|
46567
|
-
this.startTime = startTime;
|
|
46568
|
-
this.finalized = false;
|
|
46569
|
-
this.unobserved = null;
|
|
46570
|
-
this.firstTextRecorded = false;
|
|
46571
|
-
this.stepTypes = /* @__PURE__ */ new Map();
|
|
46572
|
-
this.stepText = /* @__PURE__ */ new Map();
|
|
46573
|
-
this.stepThoughts = /* @__PURE__ */ new Map();
|
|
46574
|
-
this.stepArguments = /* @__PURE__ */ new Map();
|
|
46575
|
-
this.stepMeta = /* @__PURE__ */ new Map();
|
|
46576
|
-
this.completedSteps = null;
|
|
46577
|
-
this.output = "";
|
|
46578
|
-
}
|
|
46579
|
-
processEvent(event) {
|
|
46580
|
-
try {
|
|
46581
|
-
this.reduce(event);
|
|
46582
|
-
} catch (e) {
|
|
46583
|
-
Logger.error(`${LOG_PREFIX3}: interaction event error`, e);
|
|
46584
|
-
}
|
|
46585
|
-
}
|
|
46586
|
-
reduce(event) {
|
|
46587
|
-
this.absorbUsage(event);
|
|
46588
|
-
const eventType = field2(event, "event_type");
|
|
46589
|
-
switch (eventType) {
|
|
46590
|
-
case INTERACTION_CREATED: {
|
|
46591
|
-
const interaction = field2(event, "interaction");
|
|
46592
|
-
this.id = field2(interaction, "id") ?? this.id;
|
|
46593
|
-
this.model = field2(interaction, "model") ?? this.model;
|
|
46594
|
-
this.status = field2(interaction, "status") ?? this.status;
|
|
46595
|
-
break;
|
|
46596
|
-
}
|
|
46597
|
-
case STEP_START: {
|
|
46598
|
-
const index = field2(event, "index");
|
|
46599
|
-
const step = field2(event, "step");
|
|
46600
|
-
if (typeof index !== "number") break;
|
|
46601
|
-
const stepType = field2(step, "type");
|
|
46602
|
-
if (typeof stepType === "string") this.stepTypes.set(index, stepType);
|
|
46603
|
-
if (stepType === "function_call") {
|
|
46604
|
-
this.stepMeta.set(index, {
|
|
46605
|
-
id: field2(step, "id"),
|
|
46606
|
-
name: field2(step, "name")
|
|
46607
|
-
});
|
|
46608
|
-
}
|
|
46609
|
-
break;
|
|
46610
|
-
}
|
|
46611
|
-
case STEP_DELTA:
|
|
46612
|
-
this.reduceDelta(field2(event, "index"), field2(event, "delta"));
|
|
46613
|
-
break;
|
|
46614
|
-
case INTERACTION_STATUS_UPDATE:
|
|
46615
|
-
this.status = field2(event, "status") ?? this.status;
|
|
46616
|
-
break;
|
|
46617
|
-
case INTERACTION_COMPLETED: {
|
|
46618
|
-
const interaction = field2(event, "interaction");
|
|
46619
|
-
this.id = field2(interaction, "id") ?? this.id;
|
|
46620
|
-
this.model = field2(interaction, "model") ?? this.model;
|
|
46621
|
-
this.status = field2(interaction, "status") ?? this.status;
|
|
46622
|
-
const steps = field2(interaction, "steps");
|
|
46623
|
-
if (Array.isArray(steps) && steps.length > 0) this.completedSteps = steps;
|
|
46624
|
-
break;
|
|
46625
|
-
}
|
|
46626
|
-
case ERROR_EVENT:
|
|
46627
|
-
this.error = field2(event, "error");
|
|
46628
|
-
break;
|
|
46629
|
-
}
|
|
46630
|
-
}
|
|
46631
|
-
reduceDelta(index, delta) {
|
|
46632
|
-
if (typeof index !== "number" || delta === null || delta === void 0) return;
|
|
46633
|
-
const deltaType = field2(delta, "type");
|
|
46634
|
-
if (deltaType === "text") {
|
|
46635
|
-
const text = field2(delta, "text");
|
|
46636
|
-
if (typeof text === "string" && text.length > 0) {
|
|
46637
|
-
push(this.stepText, index, text);
|
|
46638
|
-
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "model_output");
|
|
46639
|
-
this.recordFirstText();
|
|
46640
|
-
}
|
|
46641
|
-
} else if (deltaType === "thought_summary") {
|
|
46642
|
-
const text = deltaContentText(field2(delta, "content"));
|
|
46643
|
-
if (text) {
|
|
46644
|
-
push(this.stepThoughts, index, text);
|
|
46645
|
-
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "thought");
|
|
46646
|
-
}
|
|
46647
|
-
} else if (deltaType === "arguments_delta") {
|
|
46648
|
-
const fragment = field2(delta, "arguments") ?? field2(delta, "delta");
|
|
46649
|
-
if (typeof fragment === "string" && fragment.length > 0) {
|
|
46650
|
-
push(this.stepArguments, index, fragment);
|
|
46651
|
-
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "function_call");
|
|
46652
|
-
}
|
|
46653
|
-
} else if (deltaType === "image" || deltaType === "audio" || deltaType === "document" || deltaType === "video") {
|
|
46654
|
-
push(this.stepText, index, `<${deltaType}>`);
|
|
46655
|
-
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "model_output");
|
|
46656
|
-
}
|
|
46657
|
-
}
|
|
46658
|
-
recordFirstText() {
|
|
46659
|
-
if (this.firstTextRecorded) return;
|
|
46660
|
-
this.firstTextRecorded = true;
|
|
46661
|
-
this.span.setAttribute(
|
|
46662
|
-
"gen_ai.performance.time_to_first_token",
|
|
46663
|
-
(Date.now() - this.startTime) / 1e3
|
|
46664
|
-
);
|
|
46665
|
-
}
|
|
46666
|
-
absorbUsage(event) {
|
|
46667
|
-
const metadata = field2(event, "metadata");
|
|
46668
|
-
const candidates = [
|
|
46669
|
-
field2(metadata, "total_usage"),
|
|
46670
|
-
field2(metadata, "usage"),
|
|
46671
|
-
field2(event, "usage"),
|
|
46672
|
-
field2(field2(event, "interaction"), "usage")
|
|
46673
|
-
];
|
|
46674
|
-
for (const candidate of candidates) {
|
|
46675
|
-
if (candidate !== void 0 && candidate !== null) {
|
|
46676
|
-
this.usage = candidate;
|
|
46677
|
-
return;
|
|
46678
|
-
}
|
|
46679
|
-
}
|
|
46680
|
-
}
|
|
46681
|
-
/** Mark the stream as consumed through a path we cannot observe. */
|
|
46682
|
-
abandon(via) {
|
|
46683
|
-
this.unobserved = via;
|
|
46684
|
-
this.finalize();
|
|
46685
|
-
}
|
|
46686
|
-
buildInteraction() {
|
|
46687
|
-
const steps = this.completedSteps && this.stepText.size === 0 ? this.completedSteps : this.buildSteps();
|
|
46688
|
-
return {
|
|
46689
|
-
id: this.id,
|
|
46690
|
-
model: this.model,
|
|
46691
|
-
status: this.status,
|
|
46692
|
-
usage: this.usage,
|
|
46693
|
-
steps
|
|
46694
|
-
};
|
|
46695
|
-
}
|
|
46696
|
-
buildSteps() {
|
|
46697
|
-
const indices = /* @__PURE__ */ new Set([
|
|
46698
|
-
...this.stepTypes.keys(),
|
|
46699
|
-
...this.stepText.keys(),
|
|
46700
|
-
...this.stepThoughts.keys()
|
|
46701
|
-
]);
|
|
46702
|
-
return [...indices].sort((a, b) => a - b).map((index) => {
|
|
46703
|
-
const stepType = this.stepTypes.get(index) ?? "model_output";
|
|
46704
|
-
if (stepType === "thought") {
|
|
46705
|
-
return {
|
|
46706
|
-
type: "thought",
|
|
46707
|
-
summary: [
|
|
46708
|
-
{ type: "text", text: (this.stepThoughts.get(index) ?? []).join("") }
|
|
46709
|
-
]
|
|
46710
|
-
};
|
|
46711
|
-
}
|
|
46712
|
-
if (stepType === "function_call") {
|
|
46713
|
-
const meta = this.stepMeta.get(index) ?? {};
|
|
46714
|
-
return {
|
|
46715
|
-
type: "function_call",
|
|
46716
|
-
id: meta.id,
|
|
46717
|
-
name: meta.name,
|
|
46718
|
-
arguments: parseArguments(
|
|
46719
|
-
(this.stepArguments.get(index) ?? []).join("")
|
|
46720
|
-
)
|
|
46721
|
-
};
|
|
46722
|
-
}
|
|
46723
|
-
return {
|
|
46724
|
-
type: stepType,
|
|
46725
|
-
content: [
|
|
46726
|
-
{ type: "text", text: (this.stepText.get(index) ?? []).join("") }
|
|
46727
|
-
]
|
|
46728
|
-
};
|
|
46729
|
-
});
|
|
46730
|
-
}
|
|
46731
|
-
/** Close the span. Safe to call more than once. */
|
|
46732
|
-
finalize() {
|
|
46733
|
-
if (this.finalized) return;
|
|
46734
|
-
this.finalized = true;
|
|
46735
|
-
try {
|
|
46736
|
-
const interaction = this.buildInteraction();
|
|
46737
|
-
setInteractionResponseAttributes(this.span, interaction);
|
|
46738
|
-
this.output = interactionOutputText(interaction.steps);
|
|
46739
|
-
this.span.setAttribute(
|
|
46740
|
-
SpanAttributes2.LLM_RESPONSE_DURATION,
|
|
46741
|
-
(Date.now() - this.startTime) / 1e3
|
|
46742
|
-
);
|
|
46743
|
-
if (this.unobserved) {
|
|
46744
|
-
this.span.setAttribute(SpanAttributes2.STREAM_UNOBSERVED, this.unobserved);
|
|
46745
|
-
}
|
|
46746
|
-
if (this.error) {
|
|
46747
|
-
this.span.setAttribute(
|
|
46748
|
-
"error.type",
|
|
46749
|
-
String(field2(this.error, "code") ?? "error")
|
|
46750
|
-
);
|
|
46751
|
-
this.span.setStatus({
|
|
46752
|
-
code: api.SpanStatusCode.ERROR,
|
|
46753
|
-
message: String(field2(this.error, "message") ?? "interaction failed")
|
|
46754
|
-
});
|
|
46755
|
-
} else {
|
|
46756
|
-
this.span.setStatus({ code: api.SpanStatusCode.OK });
|
|
46757
|
-
}
|
|
46758
|
-
} catch (e) {
|
|
46759
|
-
Logger.error(`${LOG_PREFIX3}: interaction finalize error`, e);
|
|
46760
|
-
} finally {
|
|
46761
|
-
this.span.end();
|
|
46762
|
-
}
|
|
46763
|
-
}
|
|
46764
|
-
fail(error) {
|
|
46765
|
-
if (this.finalized) return;
|
|
46766
|
-
this.span.setStatus({
|
|
46767
|
-
code: api.SpanStatusCode.ERROR,
|
|
46768
|
-
message: error instanceof Error ? error.message : String(error)
|
|
46769
|
-
});
|
|
46770
|
-
this.span.recordException(error);
|
|
46771
|
-
this.finalize();
|
|
46772
|
-
}
|
|
46773
|
-
};
|
|
46774
|
-
function push(map, index, value) {
|
|
46775
|
-
const existing = map.get(index);
|
|
46776
|
-
if (existing) existing.push(value);
|
|
46777
|
-
else map.set(index, [value]);
|
|
46778
|
-
}
|
|
46779
|
-
function deltaContentText(content) {
|
|
46780
|
-
if (content === null || content === void 0) return "";
|
|
46781
|
-
if (typeof content === "string") return content;
|
|
46782
|
-
const items = Array.isArray(content) ? content : [content];
|
|
46783
|
-
return items.map((item) => String(field2(item, "text") ?? "")).join("");
|
|
46784
|
-
}
|
|
46785
|
-
function parseArguments(raw) {
|
|
46786
|
-
if (!raw) return {};
|
|
46787
|
-
try {
|
|
46788
|
-
return JSON.parse(raw);
|
|
46789
|
-
} catch {
|
|
46790
|
-
return raw;
|
|
46791
|
-
}
|
|
46792
|
-
}
|
|
46793
|
-
function isInteractionStream(value) {
|
|
46794
|
-
return value !== null && value !== void 0 && typeof value[Symbol.asyncIterator] === "function";
|
|
46795
|
-
}
|
|
46796
|
-
function wrapIterator(iterator, accumulator, withContext) {
|
|
46797
|
-
return {
|
|
46798
|
-
async next(value) {
|
|
46799
|
-
try {
|
|
46800
|
-
const result = await withContext(() => iterator.next(value));
|
|
46801
|
-
if (result.done) accumulator.finalize();
|
|
46802
|
-
else accumulator.processEvent(result.value);
|
|
46803
|
-
return result;
|
|
46804
|
-
} catch (e) {
|
|
46805
|
-
accumulator.fail(e);
|
|
46806
|
-
throw e;
|
|
46807
|
-
}
|
|
46808
|
-
},
|
|
46809
|
-
async return(value) {
|
|
46810
|
-
try {
|
|
46811
|
-
const result = await withContext(
|
|
46812
|
-
() => iterator.return?.(value) ?? { done: true, value }
|
|
46813
|
-
);
|
|
46814
|
-
accumulator.finalize();
|
|
46815
|
-
return result;
|
|
46816
|
-
} catch (e) {
|
|
46817
|
-
accumulator.fail(e);
|
|
46818
|
-
throw e;
|
|
46819
|
-
}
|
|
46820
|
-
},
|
|
46821
|
-
async throw(e) {
|
|
46822
|
-
try {
|
|
46823
|
-
const result = await withContext(() => {
|
|
46824
|
-
if (iterator.throw) return iterator.throw(e);
|
|
46825
|
-
throw e;
|
|
46826
|
-
});
|
|
46827
|
-
if (result.done) accumulator.finalize();
|
|
46828
|
-
return result;
|
|
46829
|
-
} catch (err) {
|
|
46830
|
-
accumulator.fail(err);
|
|
46831
|
-
throw err;
|
|
46832
|
-
}
|
|
46833
|
-
}
|
|
46834
|
-
};
|
|
46835
|
-
}
|
|
46836
|
-
var UNOBSERVED_METHODS = /* @__PURE__ */ new Set(["getReader", "pipeTo", "pipeThrough", "tee"]);
|
|
46837
|
-
function instrumentInteractionStream(stream, accumulator, withContext) {
|
|
46838
|
-
if (stream[NETRA_STREAM]) return stream;
|
|
46839
|
-
const makeIterator = (options) => wrapIterator(stream[Symbol.asyncIterator](options), accumulator, withContext);
|
|
46840
|
-
return new Proxy(stream, {
|
|
46841
|
-
get(target, property) {
|
|
46842
|
-
if (property === NETRA_STREAM) return true;
|
|
46843
|
-
if (property === Symbol.asyncIterator || property === "values") {
|
|
46844
|
-
return (options) => makeIterator(options);
|
|
46845
|
-
}
|
|
46846
|
-
if (typeof property === "string" && UNOBSERVED_METHODS.has(property)) {
|
|
46847
|
-
const original = Reflect.get(target, property, target);
|
|
46848
|
-
if (typeof original !== "function") return original;
|
|
46849
|
-
return (...args) => {
|
|
46850
|
-
accumulator.abandon(property);
|
|
46851
|
-
return original.apply(target, args);
|
|
46852
|
-
};
|
|
46853
|
-
}
|
|
46854
|
-
const value = Reflect.get(target, property, target);
|
|
46855
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
46856
|
-
}
|
|
46857
|
-
});
|
|
46858
|
-
}
|
|
46859
|
-
function interactionsWrapper(tracer) {
|
|
46860
|
-
return function wrapper(original) {
|
|
46861
|
-
return function(...args) {
|
|
46862
|
-
if (shouldSuppressInstrumentation()) {
|
|
46863
|
-
return original.apply(this, args);
|
|
46864
|
-
}
|
|
46865
|
-
const params = args[0] ?? {};
|
|
46866
|
-
const currentContext = api.context.active();
|
|
46867
|
-
return tracer.startActiveSpan(
|
|
46868
|
-
SPAN_NAMES2.INTERACTION,
|
|
46869
|
-
{ kind: api.SpanKind.CLIENT },
|
|
46870
|
-
(span2) => {
|
|
46871
|
-
const startTime = Date.now();
|
|
46872
|
-
try {
|
|
46873
|
-
setInteractionRequestAttributes(span2, params);
|
|
46874
|
-
const spanContext = api.trace.setSpan(currentContext, span2);
|
|
46875
|
-
const withContext = (fn) => api.context.with(spanContext, fn);
|
|
46876
|
-
const suppressedCtx = createSuppressedContext(spanContext);
|
|
46877
|
-
const response = api.context.with(
|
|
46878
|
-
suppressedCtx,
|
|
46879
|
-
() => original.apply(this, args)
|
|
46880
|
-
);
|
|
46881
|
-
if (!isPromise(response)) {
|
|
46882
|
-
return finishNonStreaming(span2, response, startTime);
|
|
46883
|
-
}
|
|
46884
|
-
return response.then(
|
|
46885
|
-
(value) => {
|
|
46886
|
-
if (isInteractionStream(value)) {
|
|
46887
|
-
span2.setAttribute(SpanAttributes2.LLM_IS_STREAMING, true);
|
|
46888
|
-
const accumulator = new InteractionStreamAccumulator(
|
|
46889
|
-
span2,
|
|
46890
|
-
startTime
|
|
46891
|
-
);
|
|
46892
|
-
return instrumentInteractionStream(
|
|
46893
|
-
value,
|
|
46894
|
-
accumulator,
|
|
46895
|
-
withContext
|
|
46896
|
-
);
|
|
46897
|
-
}
|
|
46898
|
-
return finishNonStreaming(span2, value, startTime);
|
|
46899
|
-
},
|
|
46900
|
-
(error) => {
|
|
46901
|
-
span2.setStatus({
|
|
46902
|
-
code: api.SpanStatusCode.ERROR,
|
|
46903
|
-
message: error instanceof Error ? error.message : String(error)
|
|
46904
|
-
});
|
|
46905
|
-
span2.recordException(error);
|
|
46906
|
-
span2.end();
|
|
46907
|
-
throw error;
|
|
46908
|
-
}
|
|
46909
|
-
);
|
|
46910
|
-
} catch (error) {
|
|
46911
|
-
span2.setStatus({
|
|
46912
|
-
code: api.SpanStatusCode.ERROR,
|
|
46913
|
-
message: error instanceof Error ? error.message : String(error)
|
|
46914
|
-
});
|
|
46915
|
-
span2.recordException(error);
|
|
46916
|
-
span2.end();
|
|
46917
|
-
throw error;
|
|
46918
|
-
}
|
|
46919
|
-
}
|
|
46920
|
-
);
|
|
46921
|
-
};
|
|
46922
|
-
};
|
|
46923
|
-
}
|
|
46924
|
-
function finishNonStreaming(span2, value, startTime) {
|
|
46925
|
-
try {
|
|
46926
|
-
span2.setAttribute(SpanAttributes2.LLM_IS_STREAMING, false);
|
|
46927
|
-
setInteractionResponseAttributes(span2, value);
|
|
46928
|
-
span2.setAttribute(
|
|
46929
|
-
SpanAttributes2.LLM_RESPONSE_DURATION,
|
|
46930
|
-
(Date.now() - startTime) / 1e3
|
|
46931
|
-
);
|
|
46932
|
-
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
46933
|
-
} catch (e) {
|
|
46934
|
-
Logger.error(`${LOG_PREFIX3}: interaction response error`, e);
|
|
46935
|
-
} finally {
|
|
46936
|
-
span2.end();
|
|
46937
|
-
}
|
|
46938
|
-
return value;
|
|
46939
|
-
}
|
|
46940
|
-
|
|
46941
|
-
// src/instrumentation/google-genai/version.ts
|
|
46942
|
-
var __version__2 = "1.0.0";
|
|
46943
|
-
var LOG_PREFIX4 = "netra.instrumentation.google_genai";
|
|
46944
46074
|
function buildParams(args, self) {
|
|
46945
46075
|
const raw = args[0];
|
|
46946
46076
|
const params = typeof raw === "object" && raw !== null ? { ...raw } : { message: raw };
|
|
@@ -47080,7 +46210,7 @@ function streamWrapperFactory(tracer, spanName, requestType) {
|
|
|
47080
46210
|
(endTime - startTime) / 1e3
|
|
47081
46211
|
);
|
|
47082
46212
|
} catch (e) {
|
|
47083
|
-
Logger.error(`${
|
|
46213
|
+
Logger.error(`${LOG_PREFIX2}: stream finalize error`, e);
|
|
47084
46214
|
}
|
|
47085
46215
|
if (status === "ok") {
|
|
47086
46216
|
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
@@ -47109,9 +46239,6 @@ var chatStreamWrapper2 = (tracer) => streamWrapperFactory(tracer, SPAN_NAMES2.CH
|
|
|
47109
46239
|
var embeddingsWrapper = (tracer) => genericWrapperFactory(tracer, SPAN_NAMES2.EMBEDDING, "embedding");
|
|
47110
46240
|
|
|
47111
46241
|
// src/instrumentation/google-genai/index.ts
|
|
47112
|
-
var INTERACTIONS_PATCHED = /* @__PURE__ */ Symbol.for(
|
|
47113
|
-
"netra.googlegenai.interactions.patched"
|
|
47114
|
-
);
|
|
47115
46242
|
var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
47116
46243
|
constructor() {
|
|
47117
46244
|
super(...arguments);
|
|
@@ -47119,15 +46246,11 @@ var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
|
47119
46246
|
this.instrumentationVersion = __version__2;
|
|
47120
46247
|
this.packageName = "@google/genai";
|
|
47121
46248
|
this.displayName = "Google GenAI";
|
|
47122
|
-
/** Original `interactions` descriptors, for an exact restore on unpatch. */
|
|
47123
|
-
this.interactionsDescriptors = [];
|
|
47124
|
-
/** Resource prototypes whose `create` we wrapped. */
|
|
47125
|
-
this.patchedInteractionProtos = [];
|
|
47126
46249
|
}
|
|
47127
46250
|
extractClasses(mod) {
|
|
47128
46251
|
const root = mod.default ?? mod;
|
|
47129
46252
|
if (!root.Models) return null;
|
|
47130
|
-
return { Models: root.Models, Chat: root.Chat
|
|
46253
|
+
return { Models: root.Models, Chat: root.Chat };
|
|
47131
46254
|
}
|
|
47132
46255
|
isSameClasses(a, b) {
|
|
47133
46256
|
return a.Models === b.Models;
|
|
@@ -47162,57 +46285,8 @@ var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
|
47162
46285
|
wrapped = true;
|
|
47163
46286
|
}
|
|
47164
46287
|
}
|
|
47165
|
-
if (this.patchInteractions(classes.GoogleGenAI, tracer)) {
|
|
47166
|
-
wrapped = true;
|
|
47167
|
-
}
|
|
47168
46288
|
return wrapped;
|
|
47169
46289
|
}
|
|
47170
|
-
/**
|
|
47171
|
-
* Redefine the `interactions` accessor so the resource prototype gets patched
|
|
47172
|
-
* on first access.
|
|
47173
|
-
*
|
|
47174
|
-
* shimmer cannot be used on the accessor itself -- it does a plain property
|
|
47175
|
-
* assignment, which would clobber the getter. Nothing is constructed here
|
|
47176
|
-
* either: `new GoogleGenAI({})` writes an API-key warning to the console.
|
|
47177
|
-
*
|
|
47178
|
-
* A client that read `.interactions` before instrumentation finished keeps
|
|
47179
|
-
* its cached resource, but the prototype is shared, so the patch still
|
|
47180
|
-
* applies the next time any instance reads the accessor. Netra.init() is
|
|
47181
|
-
* awaited before user code, so this is an edge case rather than a hole.
|
|
47182
|
-
*/
|
|
47183
|
-
patchInteractions(GoogleGenAI, tracer) {
|
|
47184
|
-
if (!GoogleGenAI?.prototype) return false;
|
|
47185
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
47186
|
-
GoogleGenAI.prototype,
|
|
47187
|
-
"interactions"
|
|
47188
|
-
);
|
|
47189
|
-
if (!descriptor?.get || !descriptor.configurable) return false;
|
|
47190
|
-
const originalGet = descriptor.get;
|
|
47191
|
-
const patchedProtos = this.patchedInteractionProtos;
|
|
47192
|
-
this.interactionsDescriptors.push([GoogleGenAI, descriptor]);
|
|
47193
|
-
Object.defineProperty(GoogleGenAI.prototype, "interactions", {
|
|
47194
|
-
configurable: true,
|
|
47195
|
-
enumerable: descriptor.enumerable,
|
|
47196
|
-
get() {
|
|
47197
|
-
const resource = originalGet.call(this);
|
|
47198
|
-
try {
|
|
47199
|
-
const proto = resource && Object.getPrototypeOf(resource);
|
|
47200
|
-
if (proto && !proto[INTERACTIONS_PATCHED] && typeof proto.create === "function") {
|
|
47201
|
-
Object.defineProperty(proto, INTERACTIONS_PATCHED, {
|
|
47202
|
-
value: true,
|
|
47203
|
-
configurable: true
|
|
47204
|
-
});
|
|
47205
|
-
shimmer__default.default.wrap(proto, "create", interactionsWrapper(tracer));
|
|
47206
|
-
patchedProtos.push(proto);
|
|
47207
|
-
}
|
|
47208
|
-
} catch (error) {
|
|
47209
|
-
Logger.error(`Google GenAI: failed to patch interactions: ${error}`);
|
|
47210
|
-
}
|
|
47211
|
-
return resource;
|
|
47212
|
-
}
|
|
47213
|
-
});
|
|
47214
|
-
return true;
|
|
47215
|
-
}
|
|
47216
46290
|
removePatches(classes) {
|
|
47217
46291
|
const modelsProto = classes.Models?.prototype;
|
|
47218
46292
|
if (modelsProto) {
|
|
@@ -47231,25 +46305,6 @@ var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
|
47231
46305
|
shimmer__default.default.unwrap(chatProto, "sendMessageStream");
|
|
47232
46306
|
}
|
|
47233
46307
|
}
|
|
47234
|
-
onUninstrument() {
|
|
47235
|
-
for (const proto of this.patchedInteractionProtos) {
|
|
47236
|
-
try {
|
|
47237
|
-
shimmer__default.default.unwrap(proto, "create");
|
|
47238
|
-
delete proto[INTERACTIONS_PATCHED];
|
|
47239
|
-
} catch (error) {
|
|
47240
|
-
Logger.error(`Google GenAI: failed to unwrap interactions.create: ${error}`);
|
|
47241
|
-
}
|
|
47242
|
-
}
|
|
47243
|
-
this.patchedInteractionProtos = [];
|
|
47244
|
-
for (const [GoogleGenAI, descriptor] of this.interactionsDescriptors) {
|
|
47245
|
-
try {
|
|
47246
|
-
Object.defineProperty(GoogleGenAI.prototype, "interactions", descriptor);
|
|
47247
|
-
} catch (error) {
|
|
47248
|
-
Logger.error(`Google GenAI: failed to restore interactions accessor: ${error}`);
|
|
47249
|
-
}
|
|
47250
|
-
}
|
|
47251
|
-
this.interactionsDescriptors = [];
|
|
47252
|
-
}
|
|
47253
46308
|
};
|
|
47254
46309
|
var googleGenAIInstrumentor = new NetraGoogleGenAIInstrumentor();
|
|
47255
46310
|
|
|
@@ -47653,7 +46708,7 @@ function _setEmbeddingResponseAttributes(span2, response) {
|
|
|
47653
46708
|
}
|
|
47654
46709
|
|
|
47655
46710
|
// src/instrumentation/google-generative-ai/wrappers.ts
|
|
47656
|
-
var
|
|
46711
|
+
var LOG_PREFIX3 = "netra.instrumentation.google_generative_ai";
|
|
47657
46712
|
var CHAT_SPAN_NAME = "google_generative_ai.chat";
|
|
47658
46713
|
var EMBEDDING_SPAN_NAME = "google_generative_ai.embedding";
|
|
47659
46714
|
function buildKwargs(instance) {
|
|
@@ -47698,7 +46753,7 @@ function googleGenerativeAIWrapper(tracer, spanName, requestType) {
|
|
|
47698
46753
|
try {
|
|
47699
46754
|
setRequestAttributes4(span2, kwargs, requestType, args[0]);
|
|
47700
46755
|
} catch (e) {
|
|
47701
|
-
Logger.error(`${
|
|
46756
|
+
Logger.error(`${LOG_PREFIX3}:`, e);
|
|
47702
46757
|
}
|
|
47703
46758
|
const startTime = Date.now();
|
|
47704
46759
|
const response = original.apply(this, args);
|
|
@@ -47719,7 +46774,7 @@ function googleGenerativeAIWrapper(tracer, spanName, requestType) {
|
|
|
47719
46774
|
);
|
|
47720
46775
|
}
|
|
47721
46776
|
} catch (e) {
|
|
47722
|
-
Logger.error(`${
|
|
46777
|
+
Logger.error(`${LOG_PREFIX3}:`, e);
|
|
47723
46778
|
}
|
|
47724
46779
|
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
47725
46780
|
span2.end();
|
|
@@ -47744,7 +46799,7 @@ function googleGenerativeAIWrapper(tracer, spanName, requestType) {
|
|
|
47744
46799
|
(endTime - startTime) / 1e3
|
|
47745
46800
|
);
|
|
47746
46801
|
} catch (e) {
|
|
47747
|
-
Logger.error(`${
|
|
46802
|
+
Logger.error(`${LOG_PREFIX3}:`, e);
|
|
47748
46803
|
}
|
|
47749
46804
|
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
47750
46805
|
span2.end();
|
|
@@ -47786,7 +46841,7 @@ function googleGenerativeAIStreamWrapper(tracer, spanName, requestType) {
|
|
|
47786
46841
|
try {
|
|
47787
46842
|
setRequestAttributes4(span2, kwargs, requestType, args[0]);
|
|
47788
46843
|
} catch (e) {
|
|
47789
|
-
Logger.error(`${
|
|
46844
|
+
Logger.error(`${LOG_PREFIX3}:`, e);
|
|
47790
46845
|
}
|
|
47791
46846
|
const response = original.apply(this, args);
|
|
47792
46847
|
if (!isPromise(response)) {
|
|
@@ -47810,7 +46865,7 @@ function googleGenerativeAIStreamWrapper(tracer, spanName, requestType) {
|
|
|
47810
46865
|
duration
|
|
47811
46866
|
);
|
|
47812
46867
|
} catch (e) {
|
|
47813
|
-
Logger.error(`${
|
|
46868
|
+
Logger.error(`${LOG_PREFIX3}:`, e);
|
|
47814
46869
|
}
|
|
47815
46870
|
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
47816
46871
|
span2.end();
|
|
@@ -47846,7 +46901,7 @@ function googleGenerativeAIStreamWrapper(tracer, spanName, requestType) {
|
|
|
47846
46901
|
duration
|
|
47847
46902
|
);
|
|
47848
46903
|
} catch (e) {
|
|
47849
|
-
Logger.error(`${
|
|
46904
|
+
Logger.error(`${LOG_PREFIX3}:`, e);
|
|
47850
46905
|
}
|
|
47851
46906
|
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
47852
46907
|
span2.end();
|
|
@@ -50644,11 +49699,11 @@ function setGenerationAttributes(span2, data, systemName) {
|
|
|
50644
49699
|
}
|
|
50645
49700
|
const effectiveOutput = unwrapGenerationOutput(data.output);
|
|
50646
49701
|
if (data.usage) {
|
|
50647
|
-
|
|
49702
|
+
setUsageAttributes3(span2, data.usage);
|
|
50648
49703
|
} else if (effectiveOutput && typeof effectiveOutput === "object" && !Array.isArray(effectiveOutput)) {
|
|
50649
49704
|
const respUsage = effectiveOutput.usage;
|
|
50650
49705
|
if (respUsage && typeof respUsage === "object") {
|
|
50651
|
-
|
|
49706
|
+
setUsageAttributes3(span2, respUsage);
|
|
50652
49707
|
}
|
|
50653
49708
|
}
|
|
50654
49709
|
if (data.input !== void 0) {
|
|
@@ -50687,7 +49742,7 @@ function setResponseAttributes8(span2, agentSpan, systemName) {
|
|
|
50687
49742
|
}
|
|
50688
49743
|
const resp = data._response;
|
|
50689
49744
|
if (data.usage && !(resp && typeof resp === "object" && resp.usage)) {
|
|
50690
|
-
|
|
49745
|
+
setUsageAttributes3(span2, data.usage);
|
|
50691
49746
|
}
|
|
50692
49747
|
}
|
|
50693
49748
|
function setFunctionAttributes(span2, data) {
|
|
@@ -50736,7 +49791,7 @@ function setCustomAttributes(span2, data) {
|
|
|
50736
49791
|
span2.setAttribute(NETRA_CUSTOM_DATA, safeStringify(data.data));
|
|
50737
49792
|
}
|
|
50738
49793
|
}
|
|
50739
|
-
function
|
|
49794
|
+
function setUsageAttributes3(span2, usage) {
|
|
50740
49795
|
const promptTokens = usage.input_tokens ?? usage.prompt_tokens;
|
|
50741
49796
|
const completionTokens = usage.output_tokens ?? usage.completion_tokens;
|
|
50742
49797
|
const totalTokens = usage.total_tokens;
|
|
@@ -50771,6 +49826,7 @@ function setUsageAttributes4(span2, usage) {
|
|
|
50771
49826
|
if (inputDetails.cache_write_tokens !== void 0) {
|
|
50772
49827
|
span2.setAttribute(SpanAttributes2.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS, Number(inputDetails.cache_write_tokens));
|
|
50773
49828
|
}
|
|
49829
|
+
setCacheWriteTtlAttributes(span2, inputDetails);
|
|
50774
49830
|
}
|
|
50775
49831
|
const outputDetails = usage.output_tokens_details ?? usage.completion_tokens_details;
|
|
50776
49832
|
if (outputDetails) {
|
|
@@ -50823,6 +49879,7 @@ function setResponseObjectUsageAttributes(span2, usage) {
|
|
|
50823
49879
|
if (usage.input_tokens_details?.cache_write_tokens !== void 0) {
|
|
50824
49880
|
span2.setAttribute(SpanAttributes2.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS, usage.input_tokens_details.cache_write_tokens);
|
|
50825
49881
|
}
|
|
49882
|
+
setCacheWriteTtlAttributes(span2, usage.input_tokens_details);
|
|
50826
49883
|
if (usage.output_tokens_details?.reasoning_tokens !== void 0) {
|
|
50827
49884
|
span2.setAttribute(SpanAttributes2.LLM_USAGE_REASONING_TOKENS, usage.output_tokens_details.reasoning_tokens);
|
|
50828
49885
|
}
|
|
@@ -52872,17 +51929,17 @@ var BaseTask = class {
|
|
|
52872
51929
|
};
|
|
52873
51930
|
|
|
52874
51931
|
// src/simulation/utils.ts
|
|
52875
|
-
var
|
|
51932
|
+
var LOG_PREFIX4 = "netra.simulation";
|
|
52876
51933
|
var DEFAULT_FILE_DOWNLOAD_TIMEOUT_S = 30;
|
|
52877
51934
|
var MAX_FILE_DOWNLOAD_WORKERS = 8;
|
|
52878
51935
|
var _cachedFileDownloadTimeoutMs = null;
|
|
52879
51936
|
function validateSimulationInputs(datasetId, task2) {
|
|
52880
51937
|
if (!datasetId) {
|
|
52881
|
-
Logger.error(`${
|
|
51938
|
+
Logger.error(`${LOG_PREFIX4}: dataset_id is required`);
|
|
52882
51939
|
return false;
|
|
52883
51940
|
}
|
|
52884
51941
|
if (!(task2 instanceof BaseTask)) {
|
|
52885
|
-
Logger.error(`${
|
|
51942
|
+
Logger.error(`${LOG_PREFIX4}: task must be a BaseTask instance`);
|
|
52886
51943
|
return false;
|
|
52887
51944
|
}
|
|
52888
51945
|
return true;
|
|
@@ -52899,7 +51956,7 @@ function _getFileDownloadTimeout() {
|
|
|
52899
51956
|
return _cachedFileDownloadTimeoutMs;
|
|
52900
51957
|
}
|
|
52901
51958
|
Logger.warn(
|
|
52902
|
-
`${
|
|
51959
|
+
`${LOG_PREFIX4}: Invalid file download timeout '${envVal}', using default ${DEFAULT_FILE_DOWNLOAD_TIMEOUT_S}s`
|
|
52903
51960
|
);
|
|
52904
51961
|
}
|
|
52905
51962
|
_cachedFileDownloadTimeoutMs = DEFAULT_FILE_DOWNLOAD_TIMEOUT_S * 1e3;
|
|
@@ -52928,7 +51985,7 @@ async function _downloadSingleFile(fileData, timeoutMs, signal) {
|
|
|
52928
51985
|
const status = axios__default.default.isAxiosError(error) ? error.response?.status : void 0;
|
|
52929
51986
|
const reason = status ? `HTTP ${status}` : error instanceof Error ? error.message : String(error);
|
|
52930
51987
|
Logger.error(
|
|
52931
|
-
`${
|
|
51988
|
+
`${LOG_PREFIX4}: Failed to download file '${fileData.fileName}': ${reason}`
|
|
52932
51989
|
);
|
|
52933
51990
|
throw new Error(
|
|
52934
51991
|
`Failed to download file '${fileData.fileName}': ${reason}`
|
|
@@ -52945,7 +52002,7 @@ function parseFiles(rawFiles) {
|
|
|
52945
52002
|
const downloadUrl = entry.downloadUrl || "";
|
|
52946
52003
|
if (!fileName || !downloadUrl) {
|
|
52947
52004
|
Logger.warn(
|
|
52948
|
-
`${
|
|
52005
|
+
`${LOG_PREFIX4}: Skipping malformed file attachment (missing fileName or downloadUrl)`
|
|
52949
52006
|
);
|
|
52950
52007
|
continue;
|
|
52951
52008
|
}
|
|
@@ -52989,7 +52046,7 @@ async function executeTask2(task2, message, sessionId, rawFiles, setupContext) {
|
|
|
52989
52046
|
}
|
|
52990
52047
|
|
|
52991
52048
|
// src/simulation/client.ts
|
|
52992
|
-
var
|
|
52049
|
+
var LOG_PREFIX5 = "netra.simulation";
|
|
52993
52050
|
var DEFAULT_TIMEOUT = 1e4;
|
|
52994
52051
|
var SimulationHttpClient = class {
|
|
52995
52052
|
constructor(config) {
|
|
@@ -53002,7 +52059,7 @@ var SimulationHttpClient = class {
|
|
|
53002
52059
|
_createClient(config) {
|
|
53003
52060
|
const endpoint = (config.otlpEndpoint || "").trim();
|
|
53004
52061
|
if (!endpoint) {
|
|
53005
|
-
Logger.error(`${
|
|
52062
|
+
Logger.error(`${LOG_PREFIX5}: NETRA_OTLP_ENDPOINT is required`);
|
|
53006
52063
|
return null;
|
|
53007
52064
|
}
|
|
53008
52065
|
const baseURL = this._resolveBaseUrl(endpoint);
|
|
@@ -53024,7 +52081,7 @@ var SimulationHttpClient = class {
|
|
|
53024
52081
|
);
|
|
53025
52082
|
return instance;
|
|
53026
52083
|
} catch (error) {
|
|
53027
|
-
Logger.error(`${
|
|
52084
|
+
Logger.error(`${LOG_PREFIX5}: Failed to create HTTP client:`, error);
|
|
53028
52085
|
return null;
|
|
53029
52086
|
}
|
|
53030
52087
|
}
|
|
@@ -53059,7 +52116,7 @@ var SimulationHttpClient = class {
|
|
|
53059
52116
|
const timeout = parseFloat(timeoutStr);
|
|
53060
52117
|
if (isNaN(timeout)) {
|
|
53061
52118
|
Logger.warn(
|
|
53062
|
-
`${
|
|
52119
|
+
`${LOG_PREFIX5}: Invalid timeout '${timeoutStr}', using default ${DEFAULT_TIMEOUT}ms`
|
|
53063
52120
|
);
|
|
53064
52121
|
return DEFAULT_TIMEOUT;
|
|
53065
52122
|
}
|
|
@@ -53071,9 +52128,9 @@ var SimulationHttpClient = class {
|
|
|
53071
52128
|
* Used in the two-phase flow so that beforeAll/before hooks can run
|
|
53072
52129
|
* before any LLM spend.
|
|
53073
52130
|
*/
|
|
53074
|
-
async initializeRun(name, datasetId,
|
|
52131
|
+
async initializeRun(name, datasetId, context17, hooksMeta) {
|
|
53075
52132
|
if (!this.client) {
|
|
53076
|
-
Logger.error(`${
|
|
52133
|
+
Logger.error(`${LOG_PREFIX5}: Client not initialized`);
|
|
53077
52134
|
return null;
|
|
53078
52135
|
}
|
|
53079
52136
|
try {
|
|
@@ -53081,7 +52138,7 @@ var SimulationHttpClient = class {
|
|
|
53081
52138
|
const payload = {
|
|
53082
52139
|
name,
|
|
53083
52140
|
datasetId,
|
|
53084
|
-
context:
|
|
52141
|
+
context: context17 || {}
|
|
53085
52142
|
};
|
|
53086
52143
|
if (hooksMeta) {
|
|
53087
52144
|
payload.lifecycleHooks = hooksMeta;
|
|
@@ -53091,7 +52148,7 @@ var SimulationHttpClient = class {
|
|
|
53091
52148
|
const responseData = data.data || {};
|
|
53092
52149
|
const items = responseData.items || [];
|
|
53093
52150
|
if (items.length === 0) {
|
|
53094
|
-
Logger.warn(`${
|
|
52151
|
+
Logger.warn(`${LOG_PREFIX5}: No items returned from initialize_run`);
|
|
53095
52152
|
return null;
|
|
53096
52153
|
}
|
|
53097
52154
|
const runId = responseData.id || "";
|
|
@@ -53104,7 +52161,7 @@ var SimulationHttpClient = class {
|
|
|
53104
52161
|
};
|
|
53105
52162
|
} catch (error) {
|
|
53106
52163
|
const errorMsg = this._extractErrorMessage(error);
|
|
53107
|
-
Logger.error(`${
|
|
52164
|
+
Logger.error(`${LOG_PREFIX5}: Failed to initialize run:`, errorMsg);
|
|
53108
52165
|
return null;
|
|
53109
52166
|
}
|
|
53110
52167
|
}
|
|
@@ -53115,7 +52172,7 @@ var SimulationHttpClient = class {
|
|
|
53115
52172
|
*/
|
|
53116
52173
|
async generateFirstTurn(runId, runItemId) {
|
|
53117
52174
|
if (!this.client) {
|
|
53118
|
-
Logger.error(`${
|
|
52175
|
+
Logger.error(`${LOG_PREFIX5}: Client not initialized`);
|
|
53119
52176
|
return null;
|
|
53120
52177
|
}
|
|
53121
52178
|
try {
|
|
@@ -53133,7 +52190,7 @@ var SimulationHttpClient = class {
|
|
|
53133
52190
|
} catch (error) {
|
|
53134
52191
|
const errorMsg = this._extractErrorMessage(error);
|
|
53135
52192
|
Logger.error(
|
|
53136
|
-
`${
|
|
52193
|
+
`${LOG_PREFIX5}: Failed to generate first turn for item ${runItemId}:`,
|
|
53137
52194
|
errorMsg
|
|
53138
52195
|
);
|
|
53139
52196
|
return null;
|
|
@@ -53144,7 +52201,7 @@ var SimulationHttpClient = class {
|
|
|
53144
52201
|
*/
|
|
53145
52202
|
async triggerConversation(message, turnId, sessionId, traceId) {
|
|
53146
52203
|
if (!this.client) {
|
|
53147
|
-
Logger.error(`${
|
|
52204
|
+
Logger.error(`${LOG_PREFIX5}: Client not initialized`);
|
|
53148
52205
|
return null;
|
|
53149
52206
|
}
|
|
53150
52207
|
try {
|
|
@@ -53167,7 +52224,7 @@ var SimulationHttpClient = class {
|
|
|
53167
52224
|
}
|
|
53168
52225
|
const userMessages = responseData.userMessages || [];
|
|
53169
52226
|
if (userMessages.length === 0) {
|
|
53170
|
-
Logger.warn(`${
|
|
52227
|
+
Logger.warn(`${LOG_PREFIX5}: No user messages in continue response`);
|
|
53171
52228
|
return null;
|
|
53172
52229
|
}
|
|
53173
52230
|
const nextMsg = userMessages[0];
|
|
@@ -53180,7 +52237,7 @@ var SimulationHttpClient = class {
|
|
|
53180
52237
|
};
|
|
53181
52238
|
} catch (error) {
|
|
53182
52239
|
const errorMsg = this._extractErrorMessage(error);
|
|
53183
|
-
Logger.error(`${
|
|
52240
|
+
Logger.error(`${LOG_PREFIX5}: Failed to trigger conversation:`, errorMsg);
|
|
53184
52241
|
return null;
|
|
53185
52242
|
}
|
|
53186
52243
|
}
|
|
@@ -53199,17 +52256,17 @@ var SimulationHttpClient = class {
|
|
|
53199
52256
|
*/
|
|
53200
52257
|
async reportFailure(runId, runItemId, error, status = "failed") {
|
|
53201
52258
|
if (!this.client) {
|
|
53202
|
-
Logger.error(`${
|
|
52259
|
+
Logger.error(`${LOG_PREFIX5}: Client not initialized`);
|
|
53203
52260
|
return;
|
|
53204
52261
|
}
|
|
53205
52262
|
try {
|
|
53206
52263
|
const url = `/evaluations/run/${runId}/item/${runItemId}/status`;
|
|
53207
52264
|
const payload = { status, failureReason: error };
|
|
53208
52265
|
await this.client.patch(url, payload);
|
|
53209
|
-
Logger.info(`${
|
|
52266
|
+
Logger.info(`${LOG_PREFIX5}: Reported failure - ${error}`);
|
|
53210
52267
|
} catch (err) {
|
|
53211
52268
|
const errorMsg = this._extractErrorMessage(err);
|
|
53212
|
-
Logger.error(`${
|
|
52269
|
+
Logger.error(`${LOG_PREFIX5}: Failed to report failure:`, errorMsg);
|
|
53213
52270
|
}
|
|
53214
52271
|
}
|
|
53215
52272
|
/**
|
|
@@ -53218,7 +52275,7 @@ var SimulationHttpClient = class {
|
|
|
53218
52275
|
async postRunStatus(runId, status) {
|
|
53219
52276
|
if (!this.client) {
|
|
53220
52277
|
Logger.error(
|
|
53221
|
-
`${
|
|
52278
|
+
`${LOG_PREFIX5}: Client not initialized; cannot post run status`
|
|
53222
52279
|
);
|
|
53223
52280
|
return { success: false };
|
|
53224
52281
|
}
|
|
@@ -53228,14 +52285,14 @@ var SimulationHttpClient = class {
|
|
|
53228
52285
|
const response = await this.client.post(url, payload);
|
|
53229
52286
|
const data = response.data;
|
|
53230
52287
|
if (data && typeof data === "object" && "data" in data) {
|
|
53231
|
-
Logger.info(`${
|
|
52288
|
+
Logger.info(`${LOG_PREFIX5}: Completed test run successfully`);
|
|
53232
52289
|
return data.data || {};
|
|
53233
52290
|
}
|
|
53234
52291
|
return data;
|
|
53235
52292
|
} catch (error) {
|
|
53236
52293
|
const errorMsg = this._extractErrorMessage(error);
|
|
53237
52294
|
Logger.error(
|
|
53238
|
-
`${
|
|
52295
|
+
`${LOG_PREFIX5}: Failed to post run status for run '${runId}':`,
|
|
53239
52296
|
errorMsg
|
|
53240
52297
|
);
|
|
53241
52298
|
return { success: false };
|
|
@@ -53260,7 +52317,7 @@ var SimulationHttpClient = class {
|
|
|
53260
52317
|
};
|
|
53261
52318
|
|
|
53262
52319
|
// src/simulation/hooks.ts
|
|
53263
|
-
var
|
|
52320
|
+
var LOG_PREFIX6 = "netra.simulation";
|
|
53264
52321
|
function describeHooks(hooks) {
|
|
53265
52322
|
const descFn = (fn) => {
|
|
53266
52323
|
if (!fn) return null;
|
|
@@ -53304,11 +52361,11 @@ function describeHooks(hooks) {
|
|
|
53304
52361
|
}
|
|
53305
52362
|
async function runBeforeAll(hooks) {
|
|
53306
52363
|
if (!hooks?.beforeAll) return null;
|
|
53307
|
-
Logger.info(`${
|
|
52364
|
+
Logger.info(`${LOG_PREFIX6}: running beforeAll hook`);
|
|
53308
52365
|
const result = await hooks.beforeAll();
|
|
53309
52366
|
if (result !== null && result !== void 0 && typeof result !== "object") {
|
|
53310
52367
|
Logger.warn(
|
|
53311
|
-
`${
|
|
52368
|
+
`${LOG_PREFIX6}: beforeAll returned ${typeof result} (expected object or null); ignoring value`
|
|
53312
52369
|
);
|
|
53313
52370
|
return null;
|
|
53314
52371
|
}
|
|
@@ -53317,7 +52374,7 @@ async function runBeforeAll(hooks) {
|
|
|
53317
52374
|
async function runBefore(hooks, datasetItemId, sharedContext) {
|
|
53318
52375
|
if (hooks?.before && datasetItemId in hooks.before) {
|
|
53319
52376
|
Logger.info(
|
|
53320
|
-
`${
|
|
52377
|
+
`${LOG_PREFIX6}: running before hook for datasetItemId=${datasetItemId}`
|
|
53321
52378
|
);
|
|
53322
52379
|
const itemHook = hooks.before[datasetItemId];
|
|
53323
52380
|
const result = await itemHook(sharedContext);
|
|
@@ -53327,7 +52384,7 @@ async function runBefore(hooks, datasetItemId, sharedContext) {
|
|
|
53327
52384
|
Object.assign(base, result);
|
|
53328
52385
|
} else {
|
|
53329
52386
|
Logger.warn(
|
|
53330
|
-
`${
|
|
52387
|
+
`${LOG_PREFIX6}: before hook returned ${typeof result} (expected object or null); ignoring value`
|
|
53331
52388
|
);
|
|
53332
52389
|
}
|
|
53333
52390
|
}
|
|
@@ -53338,7 +52395,7 @@ async function runBefore(hooks, datasetItemId, sharedContext) {
|
|
|
53338
52395
|
async function runBeforeEach(hooks, datasetItemId, sharedContext) {
|
|
53339
52396
|
if (!hooks?.beforeEach) return sharedContext;
|
|
53340
52397
|
Logger.info(
|
|
53341
|
-
`${
|
|
52398
|
+
`${LOG_PREFIX6}: running beforeEach hook for datasetItemId=${datasetItemId}`
|
|
53342
52399
|
);
|
|
53343
52400
|
const result = await hooks.beforeEach(sharedContext);
|
|
53344
52401
|
const base = { ...sharedContext || {} };
|
|
@@ -53347,7 +52404,7 @@ async function runBeforeEach(hooks, datasetItemId, sharedContext) {
|
|
|
53347
52404
|
Object.assign(base, result);
|
|
53348
52405
|
} else {
|
|
53349
52406
|
Logger.warn(
|
|
53350
|
-
`${
|
|
52407
|
+
`${LOG_PREFIX6}: beforeEach hook returned ${typeof result} (expected object or null); ignoring value`
|
|
53351
52408
|
);
|
|
53352
52409
|
}
|
|
53353
52410
|
}
|
|
@@ -53356,7 +52413,7 @@ async function runBeforeEach(hooks, datasetItemId, sharedContext) {
|
|
|
53356
52413
|
async function runAfter(hooks, datasetItemId, itemResult, setupContext) {
|
|
53357
52414
|
if (hooks?.after && datasetItemId in hooks.after) {
|
|
53358
52415
|
Logger.info(
|
|
53359
|
-
`${
|
|
52416
|
+
`${LOG_PREFIX6}: running after hook for datasetItemId=${datasetItemId}`
|
|
53360
52417
|
);
|
|
53361
52418
|
await hooks.after[datasetItemId](itemResult, setupContext);
|
|
53362
52419
|
}
|
|
@@ -53364,18 +52421,18 @@ async function runAfter(hooks, datasetItemId, itemResult, setupContext) {
|
|
|
53364
52421
|
async function runAfterEach(hooks, datasetItemId, itemResult, setupContext) {
|
|
53365
52422
|
if (!hooks?.afterEach) return;
|
|
53366
52423
|
Logger.info(
|
|
53367
|
-
`${
|
|
52424
|
+
`${LOG_PREFIX6}: running afterEach hook for datasetItemId=${datasetItemId}`
|
|
53368
52425
|
);
|
|
53369
52426
|
await hooks.afterEach(itemResult, setupContext);
|
|
53370
52427
|
}
|
|
53371
52428
|
async function runAfterAll(hooks, results, sharedContext) {
|
|
53372
52429
|
if (!hooks?.afterAll) return;
|
|
53373
|
-
Logger.info(`${
|
|
52430
|
+
Logger.info(`${LOG_PREFIX6}: running afterAll hook`);
|
|
53374
52431
|
await hooks.afterAll(results, sharedContext);
|
|
53375
52432
|
}
|
|
53376
52433
|
|
|
53377
52434
|
// src/simulation/api.ts
|
|
53378
|
-
var
|
|
52435
|
+
var LOG_PREFIX7 = "netra.simulation";
|
|
53379
52436
|
var SPAN_NAME = "Netra.Simulation.TestRun";
|
|
53380
52437
|
var Simulation = class {
|
|
53381
52438
|
constructor(config) {
|
|
@@ -53399,7 +52456,7 @@ var Simulation = class {
|
|
|
53399
52456
|
name,
|
|
53400
52457
|
datasetId,
|
|
53401
52458
|
task: task2,
|
|
53402
|
-
context:
|
|
52459
|
+
context: context17,
|
|
53403
52460
|
maxConcurrency = 5,
|
|
53404
52461
|
hooks
|
|
53405
52462
|
} = options;
|
|
@@ -53411,7 +52468,7 @@ var Simulation = class {
|
|
|
53411
52468
|
const initResult = await this._client.initializeRun(
|
|
53412
52469
|
name,
|
|
53413
52470
|
datasetId,
|
|
53414
|
-
|
|
52471
|
+
context17,
|
|
53415
52472
|
hooksMeta && Object.keys(hooksMeta).length > 0 ? hooksMeta : null
|
|
53416
52473
|
);
|
|
53417
52474
|
if (!initResult) {
|
|
@@ -53419,7 +52476,7 @@ var Simulation = class {
|
|
|
53419
52476
|
}
|
|
53420
52477
|
const { runId, items } = initResult;
|
|
53421
52478
|
if (!items || items.length === 0) {
|
|
53422
|
-
Logger.error(`${
|
|
52479
|
+
Logger.error(`${LOG_PREFIX7}: No items returned from initialize_run`);
|
|
53423
52480
|
return null;
|
|
53424
52481
|
}
|
|
53425
52482
|
let interrupted = false;
|
|
@@ -53461,7 +52518,7 @@ var Simulation = class {
|
|
|
53461
52518
|
sharedContext = await runBeforeAll(hooks);
|
|
53462
52519
|
} catch (error) {
|
|
53463
52520
|
const errorMsg = `beforeAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
53464
|
-
Logger.error(`${
|
|
52521
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg} \u2014 aborting run (no LLM spent)`);
|
|
53465
52522
|
await this._reportFailures(
|
|
53466
52523
|
runId,
|
|
53467
52524
|
items.map((item) => item.runItemId),
|
|
@@ -53483,7 +52540,7 @@ var Simulation = class {
|
|
|
53483
52540
|
await runAfterAll(hooks, results, null);
|
|
53484
52541
|
} catch (afterAllError) {
|
|
53485
52542
|
const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
|
|
53486
|
-
Logger.error(`${
|
|
52543
|
+
Logger.error(`${LOG_PREFIX7}: ${afterAllMsg}`);
|
|
53487
52544
|
}
|
|
53488
52545
|
await this._client.postRunStatus(runId, "completed");
|
|
53489
52546
|
return results;
|
|
@@ -53506,7 +52563,7 @@ var Simulation = class {
|
|
|
53506
52563
|
setupContexts.set(runItemId, setupContext);
|
|
53507
52564
|
} catch (error) {
|
|
53508
52565
|
const errorMsg = `before hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
53509
|
-
Logger.error(`${
|
|
52566
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
|
|
53510
52567
|
await this._client.reportFailure(runId, runItemId, errorMsg, "prescript_failed");
|
|
53511
52568
|
const itemResult = {
|
|
53512
52569
|
runItemId,
|
|
@@ -53522,7 +52579,7 @@ var Simulation = class {
|
|
|
53522
52579
|
}
|
|
53523
52580
|
const simItem = await this._client.generateFirstTurn(runId, runItemId);
|
|
53524
52581
|
if (!simItem) {
|
|
53525
|
-
Logger.warn(`${
|
|
52582
|
+
Logger.warn(`${LOG_PREFIX7}: Failed to generate first turn for item ${runItemId}, marking failed`);
|
|
53526
52583
|
await this._client.reportFailure(runId, runItemId, "Failed to generate first user message");
|
|
53527
52584
|
const itemResult = {
|
|
53528
52585
|
runItemId,
|
|
@@ -53538,7 +52595,7 @@ var Simulation = class {
|
|
|
53538
52595
|
);
|
|
53539
52596
|
await Promise.all(setupPromises);
|
|
53540
52597
|
if (simulationItems.length === 0) {
|
|
53541
|
-
Logger.error(`${
|
|
52598
|
+
Logger.error(`${LOG_PREFIX7}: All items failed during setup/generation`);
|
|
53542
52599
|
const results = {
|
|
53543
52600
|
success: false,
|
|
53544
52601
|
completed: [],
|
|
@@ -53549,12 +52606,12 @@ var Simulation = class {
|
|
|
53549
52606
|
await runAfterAll(hooks, results, sharedContext);
|
|
53550
52607
|
} catch (afterAllError) {
|
|
53551
52608
|
const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
|
|
53552
|
-
Logger.error(`${
|
|
52609
|
+
Logger.error(`${LOG_PREFIX7}: ${afterAllMsg}`);
|
|
53553
52610
|
}
|
|
53554
52611
|
await this._client.postRunStatus(runId, "completed");
|
|
53555
52612
|
return results;
|
|
53556
52613
|
}
|
|
53557
|
-
Logger.info(`${
|
|
52614
|
+
Logger.info(`${LOG_PREFIX7}: Starting simulation with ${simulationItems.length} items`);
|
|
53558
52615
|
try {
|
|
53559
52616
|
const result = await this._runSimulationAsync(
|
|
53560
52617
|
runId,
|
|
@@ -53567,11 +52624,11 @@ var Simulation = class {
|
|
|
53567
52624
|
failedItems
|
|
53568
52625
|
);
|
|
53569
52626
|
const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
|
|
53570
|
-
Logger.info(`${
|
|
52627
|
+
Logger.info(`${LOG_PREFIX7}: Simulation completed in ${elapsedTime} seconds`);
|
|
53571
52628
|
await this._client.postRunStatus(runId, "completed");
|
|
53572
52629
|
return result;
|
|
53573
52630
|
} catch (error) {
|
|
53574
|
-
Logger.error(`${
|
|
52631
|
+
Logger.error(`${LOG_PREFIX7}: Run simulation failed`);
|
|
53575
52632
|
await this._client.postRunStatus(runId, "failed");
|
|
53576
52633
|
throw error;
|
|
53577
52634
|
}
|
|
@@ -53613,7 +52670,7 @@ var Simulation = class {
|
|
|
53613
52670
|
}
|
|
53614
52671
|
processedCount++;
|
|
53615
52672
|
Logger.info(
|
|
53616
|
-
`${
|
|
52673
|
+
`${LOG_PREFIX7}: ${processedCount}/${runItems.length} processed (run_item_id=${runItem.runItemId})`
|
|
53617
52674
|
);
|
|
53618
52675
|
return result;
|
|
53619
52676
|
})
|
|
@@ -53624,7 +52681,7 @@ var Simulation = class {
|
|
|
53624
52681
|
await runAfterAll(hooks, results, sharedContext);
|
|
53625
52682
|
} catch (error) {
|
|
53626
52683
|
const errorMsg = `afterAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
53627
|
-
Logger.error(`${
|
|
52684
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg}`);
|
|
53628
52685
|
const completed = results.completed;
|
|
53629
52686
|
const successfulIds = completed.map((item) => item.runItemId);
|
|
53630
52687
|
await this._reportFailures(
|
|
@@ -53644,7 +52701,7 @@ var Simulation = class {
|
|
|
53644
52701
|
}
|
|
53645
52702
|
results.success = results.failed.length === 0;
|
|
53646
52703
|
Logger.info(
|
|
53647
|
-
`${
|
|
52704
|
+
`${LOG_PREFIX7}: Completed=${results.completed.length}, Failed=${results.failed.length}`
|
|
53648
52705
|
);
|
|
53649
52706
|
return results;
|
|
53650
52707
|
}
|
|
@@ -53675,14 +52732,14 @@ var Simulation = class {
|
|
|
53675
52732
|
await runAfter(hooks, datasetItemId, itemResult, setupContext);
|
|
53676
52733
|
} catch (error) {
|
|
53677
52734
|
const errorMsg = `after hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
53678
|
-
Logger.error(`${
|
|
52735
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
|
|
53679
52736
|
errors.push(errorMsg);
|
|
53680
52737
|
}
|
|
53681
52738
|
try {
|
|
53682
52739
|
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
53683
52740
|
} catch (error) {
|
|
53684
52741
|
const errorMsg = `afterEach hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
53685
|
-
Logger.error(`${
|
|
52742
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
|
|
53686
52743
|
errors.push(errorMsg);
|
|
53687
52744
|
}
|
|
53688
52745
|
if (errors.length > 0 && itemResult.success) {
|
|
@@ -53715,7 +52772,7 @@ var Simulation = class {
|
|
|
53715
52772
|
const span2 = new SpanWrapper(
|
|
53716
52773
|
SPAN_NAME,
|
|
53717
52774
|
{ [Config.TRACE_ORIGIN_KEY]: Config.TRACE_ORIGIN_EVALUATION },
|
|
53718
|
-
|
|
52775
|
+
LOG_PREFIX7
|
|
53719
52776
|
);
|
|
53720
52777
|
span2.start();
|
|
53721
52778
|
try {
|
|
@@ -53746,7 +52803,7 @@ var Simulation = class {
|
|
|
53746
52803
|
}
|
|
53747
52804
|
if (response.decision === "stop") {
|
|
53748
52805
|
Logger.info(
|
|
53749
|
-
`${
|
|
52806
|
+
`${LOG_PREFIX7}: Completed run_item_id=${runItemId} reason=${response.reason}`
|
|
53750
52807
|
);
|
|
53751
52808
|
const itemResult = {
|
|
53752
52809
|
runItemId,
|
|
@@ -53762,7 +52819,7 @@ var Simulation = class {
|
|
|
53762
52819
|
} catch (error) {
|
|
53763
52820
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
53764
52821
|
Logger.error(
|
|
53765
|
-
`${
|
|
52822
|
+
`${LOG_PREFIX7}: Task failed run_item_id=${runItemId}, turn_id=${turnId}: ${errorMsg}`
|
|
53766
52823
|
);
|
|
53767
52824
|
await this._client.reportFailure(runId, runItemId, errorMsg);
|
|
53768
52825
|
const itemResult = {
|
|
@@ -53779,7 +52836,7 @@ var Simulation = class {
|
|
|
53779
52836
|
}
|
|
53780
52837
|
}
|
|
53781
52838
|
};
|
|
53782
|
-
var
|
|
52839
|
+
var Tracer18 = class {
|
|
53783
52840
|
constructor(cfg, effectiveProvider) {
|
|
53784
52841
|
if (effectiveProvider && typeof effectiveProvider.getTracer === "function") {
|
|
53785
52842
|
this.tracer = effectiveProvider.getTracer(Config.LIBRARY_NAME, Config.LIBRARY_VERSION);
|
|
@@ -53790,8 +52847,8 @@ var Tracer19 = class {
|
|
|
53790
52847
|
};
|
|
53791
52848
|
function spanHasOutput(span2) {
|
|
53792
52849
|
try {
|
|
53793
|
-
for (const
|
|
53794
|
-
const attrs = span2[
|
|
52850
|
+
for (const field of ["attributes", "_attributes"]) {
|
|
52851
|
+
const attrs = span2[field];
|
|
53795
52852
|
if (attrs && typeof attrs === "object" && attrs["output"]) return true;
|
|
53796
52853
|
}
|
|
53797
52854
|
} catch (e) {
|
|
@@ -53994,7 +53051,7 @@ var Netra = class {
|
|
|
53994
53051
|
config.blockInstruments,
|
|
53995
53052
|
config.rootInstruments
|
|
53996
53053
|
);
|
|
53997
|
-
const tracer = new
|
|
53054
|
+
const tracer = new Tracer18(cfg, effectiveProvider);
|
|
53998
53055
|
this._tracer = tracer.tracer;
|
|
53999
53056
|
try {
|
|
54000
53057
|
this.usage = new Usage(cfg);
|