netra-sdk 1.10.0 → 1.10.1
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/chunk-LRCHNZDG.js +419 -0
- package/dist/chunk-LRCHNZDG.js.map +1 -0
- package/dist/chunk-TFPEWHM4.js +564 -0
- package/dist/chunk-TFPEWHM4.js.map +1 -0
- package/dist/dist-4UBY6Q6Z.js +21658 -0
- package/dist/dist-4UBY6Q6Z.js.map +1 -0
- package/dist/index.cjs +39376 -13319
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1061 -441
- package/dist/index.js.map +1 -1
- package/dist/manager-BKZT7MYF.js +15991 -0
- package/dist/manager-BKZT7MYF.js.map +1 -0
- package/package.json +17 -8
- package/dist/chunk-WMQRYJGR.js +0 -649
- package/dist/chunk-WMQRYJGR.js.map +0 -1
- package/dist/dist-GIPRCO2C.js +0 -13704
- package/dist/dist-GIPRCO2C.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __require, BaseCallbackHandler } from './chunk-LRCHNZDG.js';
|
|
2
2
|
import { createContextKey, propagation, trace, context, SpanKind, SpanStatusCode, ROOT_CONTEXT } from '@opentelemetry/api';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
@@ -253,10 +253,10 @@ var UsageHttpClient = class extends NetraHttpClient {
|
|
|
253
253
|
user_id: params.userId,
|
|
254
254
|
tenant_id: params.tenantId
|
|
255
255
|
};
|
|
256
|
-
for (const [
|
|
256
|
+
for (const [field3, value] of Object.entries(filterMapping)) {
|
|
257
257
|
if (value !== void 0) {
|
|
258
258
|
filters.push({
|
|
259
|
-
field,
|
|
259
|
+
field: field3,
|
|
260
260
|
operator: "equals",
|
|
261
261
|
type: "string",
|
|
262
262
|
value
|
|
@@ -465,8 +465,8 @@ var Usage = class {
|
|
|
465
465
|
if (!page) {
|
|
466
466
|
break;
|
|
467
467
|
}
|
|
468
|
-
for (const
|
|
469
|
-
yield
|
|
468
|
+
for (const trace25 of page.traces) {
|
|
469
|
+
yield trace25;
|
|
470
470
|
}
|
|
471
471
|
if (!page.hasNextPage || !page.nextCursor) {
|
|
472
472
|
break;
|
|
@@ -1943,13 +1943,13 @@ async function runSingleEvaluator(params) {
|
|
|
1943
1943
|
if (config) {
|
|
1944
1944
|
expectedName = config.name;
|
|
1945
1945
|
}
|
|
1946
|
-
const
|
|
1946
|
+
const context17 = {
|
|
1947
1947
|
input: itemInput,
|
|
1948
1948
|
taskOutput,
|
|
1949
1949
|
expectedOutput,
|
|
1950
1950
|
metadata
|
|
1951
1951
|
};
|
|
1952
|
-
let result = evaluator.evaluate(
|
|
1952
|
+
let result = evaluator.evaluate(context17);
|
|
1953
1953
|
if (result instanceof Promise) {
|
|
1954
1954
|
result = await result;
|
|
1955
1955
|
}
|
|
@@ -3946,14 +3946,14 @@ var SpanIOProcessor = class {
|
|
|
3946
3946
|
if (promptMatch) {
|
|
3947
3947
|
original(key, value);
|
|
3948
3948
|
const idx = parseInt(promptMatch[1], 10);
|
|
3949
|
-
const
|
|
3949
|
+
const field3 = promptMatch[2];
|
|
3950
3950
|
if (!prompts) prompts = /* @__PURE__ */ new Map();
|
|
3951
3951
|
let entry = prompts.get(idx);
|
|
3952
3952
|
if (!entry) {
|
|
3953
3953
|
entry = {};
|
|
3954
3954
|
prompts.set(idx, entry);
|
|
3955
3955
|
}
|
|
3956
|
-
entry[
|
|
3956
|
+
entry[field3] = String(value);
|
|
3957
3957
|
if (!inputLocked() && (inputIsEmpty() || genAiOwnsInput)) {
|
|
3958
3958
|
original("input", buildMessages(prompts));
|
|
3959
3959
|
genAiOwnsInput = true;
|
|
@@ -3964,14 +3964,14 @@ var SpanIOProcessor = class {
|
|
|
3964
3964
|
if (completionMatch) {
|
|
3965
3965
|
original(key, value);
|
|
3966
3966
|
const idx = parseInt(completionMatch[1], 10);
|
|
3967
|
-
const
|
|
3967
|
+
const field3 = completionMatch[2];
|
|
3968
3968
|
if (!completions) completions = /* @__PURE__ */ new Map();
|
|
3969
3969
|
let entry = completions.get(idx);
|
|
3970
3970
|
if (!entry) {
|
|
3971
3971
|
entry = {};
|
|
3972
3972
|
completions.set(idx, entry);
|
|
3973
3973
|
}
|
|
3974
|
-
entry[
|
|
3974
|
+
entry[field3] = String(value);
|
|
3975
3975
|
if (!outputLocked() && (outputIsEmpty() || genAiOwnsOutput)) {
|
|
3976
3976
|
original("output", buildMessages(completions));
|
|
3977
3977
|
genAiOwnsOutput = true;
|
|
@@ -4238,7 +4238,33 @@ var SpanAttributes2 = {
|
|
|
4238
4238
|
LLM_CHAT_STOP_SEQUENCES: "llm.chat.stop_sequences",
|
|
4239
4239
|
LLM_IS_STREAMING: "llm.is_streaming",
|
|
4240
4240
|
LLM_COMPLETIONS: "gen_ai.completion",
|
|
4241
|
-
LLM_PROMPTS: "gen_ai.prompt"
|
|
4241
|
+
LLM_PROMPTS: "gen_ai.prompt",
|
|
4242
|
+
// Google GenAI Interactions API. Its request is flat snake_case and its
|
|
4243
|
+
// response is a multi-step Interaction, so it needs names the chat/embedding
|
|
4244
|
+
// surfaces have no equivalent for.
|
|
4245
|
+
LLM_REQUEST_AGENT: "gen_ai.request.agent",
|
|
4246
|
+
LLM_REQUEST_AGENT_CONFIG: "gen_ai.request.agent_config",
|
|
4247
|
+
LLM_REQUEST_SEED: "gen_ai.request.seed",
|
|
4248
|
+
LLM_REQUEST_THINKING_SUMMARIES: "gen_ai.request.thinking_summaries",
|
|
4249
|
+
LLM_REQUEST_TOOL_CHOICE: "llm.request.tool_choice",
|
|
4250
|
+
LLM_REQUEST_TOOLS: "llm.request.functions",
|
|
4251
|
+
LLM_REQUEST_STORE: "gen_ai.request.store",
|
|
4252
|
+
LLM_REQUEST_BACKGROUND: "gen_ai.request.background",
|
|
4253
|
+
LLM_REQUEST_PREVIOUS_INTERACTION_ID: "gen_ai.request.previous_interaction_id",
|
|
4254
|
+
LLM_REQUEST_RESPONSE_FORMAT: "gen_ai.request.response_format",
|
|
4255
|
+
LLM_REQUEST_RESPONSE_MIME_TYPE: "gen_ai.request.response_mime_type",
|
|
4256
|
+
LLM_REQUEST_RESPONSE_MODALITIES: "gen_ai.request.response_modalities",
|
|
4257
|
+
LLM_REQUEST_SERVICE_TIER: "gen_ai.request.service_tier",
|
|
4258
|
+
LLM_RESPONSE_ID: "gen_ai.response.id",
|
|
4259
|
+
LLM_RESPONSE_STATUS: "gen_ai.response.status",
|
|
4260
|
+
LLM_RESPONSE_PREVIOUS_INTERACTION_ID: "gen_ai.response.previous_interaction_id",
|
|
4261
|
+
LLM_RESPONSE_REASONING: "llm.response.reasoning",
|
|
4262
|
+
LLM_INTERACTION_STEP_COUNT: "gen_ai.interaction.step_count",
|
|
4263
|
+
LLM_USAGE_TOOL_USE_TOKENS: "gen_ai.usage.tool_use_tokens",
|
|
4264
|
+
LLM_USAGE_GROUNDING_TOOL_COUNT: "gen_ai.usage.grounding_tool_count",
|
|
4265
|
+
// Set when a stream is consumed through a path we cannot observe
|
|
4266
|
+
// (getReader/pipeTo/pipeThrough/tee), so the span closes instead of leaking.
|
|
4267
|
+
STREAM_UNOBSERVED: "netra.stream.unobserved"
|
|
4242
4268
|
};
|
|
4243
4269
|
var VALID_NATIVE_TRACING_MODES = /* @__PURE__ */ new Set(["both", "netra", "netra-strict"]);
|
|
4244
4270
|
function parseNativeTracingEnv(name) {
|
|
@@ -5755,15 +5781,6 @@ var BaseInstrumentor = class {
|
|
|
5755
5781
|
}
|
|
5756
5782
|
};
|
|
5757
5783
|
|
|
5758
|
-
// src/instrumentation/google-genai/version.ts
|
|
5759
|
-
var __version__2 = "1.0.0";
|
|
5760
|
-
|
|
5761
|
-
// src/instrumentation/google-genai/types.ts
|
|
5762
|
-
var SPAN_NAMES2 = {
|
|
5763
|
-
CHAT: "google_genai.chat",
|
|
5764
|
-
EMBEDDING: "google_genai.embedding"
|
|
5765
|
-
};
|
|
5766
|
-
|
|
5767
5784
|
// src/instrumentation/google-genai/utils.ts
|
|
5768
5785
|
var LOG_PREFIX = "netra.instrumentation.google_genai";
|
|
5769
5786
|
function setRequestAttributes3(span2, params, requestType) {
|
|
@@ -6146,8 +6163,880 @@ function buildAccumulatedResponse(accumulated) {
|
|
|
6146
6163
|
return response;
|
|
6147
6164
|
}
|
|
6148
6165
|
|
|
6149
|
-
// src/instrumentation/google-genai/
|
|
6166
|
+
// src/instrumentation/google-genai/interactions-utils.ts
|
|
6150
6167
|
var LOG_PREFIX2 = "netra.instrumentation.google_genai";
|
|
6168
|
+
var CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
6169
|
+
"text",
|
|
6170
|
+
"image",
|
|
6171
|
+
"audio",
|
|
6172
|
+
"document",
|
|
6173
|
+
"video"
|
|
6174
|
+
]);
|
|
6175
|
+
var SERVER_TOOL_CALL_STEPS = /* @__PURE__ */ new Set([
|
|
6176
|
+
"code_execution_call",
|
|
6177
|
+
"url_context_call",
|
|
6178
|
+
"google_search_call",
|
|
6179
|
+
"google_maps_call",
|
|
6180
|
+
"file_search_call",
|
|
6181
|
+
"mcp_server_tool_call"
|
|
6182
|
+
]);
|
|
6183
|
+
var SERVER_TOOL_RESULT_STEPS = /* @__PURE__ */ new Set([
|
|
6184
|
+
"code_execution_result",
|
|
6185
|
+
"url_context_result",
|
|
6186
|
+
"google_search_result",
|
|
6187
|
+
"google_maps_result",
|
|
6188
|
+
"file_search_result",
|
|
6189
|
+
"mcp_server_tool_result"
|
|
6190
|
+
]);
|
|
6191
|
+
var STEP_TYPES = /* @__PURE__ */ new Set([
|
|
6192
|
+
"user_input",
|
|
6193
|
+
"model_output",
|
|
6194
|
+
"thought",
|
|
6195
|
+
"function_call",
|
|
6196
|
+
"function_result",
|
|
6197
|
+
...SERVER_TOOL_CALL_STEPS,
|
|
6198
|
+
...SERVER_TOOL_RESULT_STEPS
|
|
6199
|
+
]);
|
|
6200
|
+
function field(obj, name) {
|
|
6201
|
+
if (!isDict(obj)) return void 0;
|
|
6202
|
+
return obj[name];
|
|
6203
|
+
}
|
|
6204
|
+
function asArray(value) {
|
|
6205
|
+
if (value === null || value === void 0) return [];
|
|
6206
|
+
return Array.isArray(value) ? value : [value];
|
|
6207
|
+
}
|
|
6208
|
+
function contentText(items) {
|
|
6209
|
+
const parts = [];
|
|
6210
|
+
for (const item of asArray(items)) {
|
|
6211
|
+
const itemType = field(item, "type");
|
|
6212
|
+
if (itemType === "text") {
|
|
6213
|
+
const text = field(item, "text");
|
|
6214
|
+
if (typeof text === "string") parts.push(text);
|
|
6215
|
+
} else if (typeof itemType === "string" && CONTENT_TYPES.has(itemType)) {
|
|
6216
|
+
parts.push(`<${itemType}>`);
|
|
6217
|
+
}
|
|
6218
|
+
}
|
|
6219
|
+
return parts.join("");
|
|
6220
|
+
}
|
|
6221
|
+
function contentModalities(items) {
|
|
6222
|
+
const modalities = [];
|
|
6223
|
+
for (const item of asArray(items)) {
|
|
6224
|
+
const itemType = field(item, "type");
|
|
6225
|
+
if (typeof itemType === "string" && CONTENT_TYPES.has(itemType) && itemType !== "text" && !modalities.includes(itemType)) {
|
|
6226
|
+
modalities.push(itemType);
|
|
6227
|
+
}
|
|
6228
|
+
}
|
|
6229
|
+
return modalities;
|
|
6230
|
+
}
|
|
6231
|
+
function stepMessage(step) {
|
|
6232
|
+
const stepType = field(step, "type");
|
|
6233
|
+
if (typeof stepType !== "string") return null;
|
|
6234
|
+
if (stepType === "user_input") {
|
|
6235
|
+
return {
|
|
6236
|
+
role: "user",
|
|
6237
|
+
content: contentText(field(step, "content")),
|
|
6238
|
+
stepType
|
|
6239
|
+
};
|
|
6240
|
+
}
|
|
6241
|
+
if (stepType === "model_output") {
|
|
6242
|
+
const content = field(step, "content");
|
|
6243
|
+
return {
|
|
6244
|
+
role: "assistant",
|
|
6245
|
+
content: contentText(content),
|
|
6246
|
+
stepType,
|
|
6247
|
+
modalities: contentModalities(content)
|
|
6248
|
+
};
|
|
6249
|
+
}
|
|
6250
|
+
if (stepType === "thought") {
|
|
6251
|
+
return {
|
|
6252
|
+
role: "assistant",
|
|
6253
|
+
content: contentText(field(step, "summary")),
|
|
6254
|
+
stepType
|
|
6255
|
+
};
|
|
6256
|
+
}
|
|
6257
|
+
if (stepType === "function_call") {
|
|
6258
|
+
const toolCall = {
|
|
6259
|
+
name: field(step, "name"),
|
|
6260
|
+
id: field(step, "id"),
|
|
6261
|
+
arguments: field(step, "arguments")
|
|
6262
|
+
};
|
|
6263
|
+
return {
|
|
6264
|
+
role: "assistant",
|
|
6265
|
+
content: safeStringify(toolCall),
|
|
6266
|
+
stepType,
|
|
6267
|
+
toolCall
|
|
6268
|
+
};
|
|
6269
|
+
}
|
|
6270
|
+
if (stepType === "function_result") {
|
|
6271
|
+
const name = field(step, "name");
|
|
6272
|
+
return {
|
|
6273
|
+
role: "tool",
|
|
6274
|
+
content: safeStringify({
|
|
6275
|
+
call_id: field(step, "call_id"),
|
|
6276
|
+
name,
|
|
6277
|
+
result: field(step, "result"),
|
|
6278
|
+
is_error: field(step, "is_error")
|
|
6279
|
+
}),
|
|
6280
|
+
stepType,
|
|
6281
|
+
toolCall: { name }
|
|
6282
|
+
};
|
|
6283
|
+
}
|
|
6284
|
+
if (SERVER_TOOL_CALL_STEPS.has(stepType)) {
|
|
6285
|
+
return {
|
|
6286
|
+
role: "tool",
|
|
6287
|
+
content: safeStringify({
|
|
6288
|
+
name: stepType,
|
|
6289
|
+
arguments: field(step, "arguments")
|
|
6290
|
+
}),
|
|
6291
|
+
stepType,
|
|
6292
|
+
toolCall: { name: stepType }
|
|
6293
|
+
};
|
|
6294
|
+
}
|
|
6295
|
+
if (SERVER_TOOL_RESULT_STEPS.has(stepType)) {
|
|
6296
|
+
return {
|
|
6297
|
+
role: "tool",
|
|
6298
|
+
content: safeStringify({ name: stepType, result: field(step, "result") }),
|
|
6299
|
+
stepType,
|
|
6300
|
+
toolCall: { name: stepType }
|
|
6301
|
+
};
|
|
6302
|
+
}
|
|
6303
|
+
return { role: "assistant", content: safeStringify(step), stepType };
|
|
6304
|
+
}
|
|
6305
|
+
function inputMessages(value) {
|
|
6306
|
+
if (value === null || value === void 0) return [];
|
|
6307
|
+
if (typeof value === "string") {
|
|
6308
|
+
return [{ role: "user", content: value }];
|
|
6309
|
+
}
|
|
6310
|
+
if (Array.isArray(value)) {
|
|
6311
|
+
if (value.length === 0) return [];
|
|
6312
|
+
const types = value.map((item) => field(item, "type"));
|
|
6313
|
+
if (types.every((t) => typeof t === "string" && STEP_TYPES.has(t))) {
|
|
6314
|
+
const messages = [];
|
|
6315
|
+
for (const item of value) {
|
|
6316
|
+
const message = stepMessage(item);
|
|
6317
|
+
if (message && message.stepType !== "thought" && message.content) {
|
|
6318
|
+
messages.push(message);
|
|
6319
|
+
}
|
|
6320
|
+
}
|
|
6321
|
+
return messages;
|
|
6322
|
+
}
|
|
6323
|
+
if (types.every((t) => typeof t === "string" && CONTENT_TYPES.has(t))) {
|
|
6324
|
+
return [{ role: "user", content: contentText(value) }];
|
|
6325
|
+
}
|
|
6326
|
+
return [{ role: "user", content: safeStringify(value) }];
|
|
6327
|
+
}
|
|
6328
|
+
const valueType = field(value, "type");
|
|
6329
|
+
if (typeof valueType === "string" && CONTENT_TYPES.has(valueType)) {
|
|
6330
|
+
return [{ role: "user", content: contentText([value]) }];
|
|
6331
|
+
}
|
|
6332
|
+
if (typeof valueType === "string" && STEP_TYPES.has(valueType)) {
|
|
6333
|
+
const message = stepMessage(value);
|
|
6334
|
+
return message && message.content ? [message] : [];
|
|
6335
|
+
}
|
|
6336
|
+
return [{ role: "user", content: safeStringify(value) }];
|
|
6337
|
+
}
|
|
6338
|
+
function setToolDefinitions(span2, tools) {
|
|
6339
|
+
if (!Array.isArray(tools)) return;
|
|
6340
|
+
tools.forEach((tool, index) => {
|
|
6341
|
+
const toolType = field(tool, "type");
|
|
6342
|
+
const prefix = `${SpanAttributes2.LLM_REQUEST_TOOLS}.${index}`;
|
|
6343
|
+
if (toolType === "function") {
|
|
6344
|
+
const fn = field(tool, "function") ?? tool;
|
|
6345
|
+
span2.setAttribute(`${prefix}.name`, String(field(fn, "name") ?? ""));
|
|
6346
|
+
const description = field(fn, "description");
|
|
6347
|
+
if (description !== void 0) {
|
|
6348
|
+
span2.setAttribute(`${prefix}.description`, String(description));
|
|
6349
|
+
}
|
|
6350
|
+
const parameters = field(fn, "parameters");
|
|
6351
|
+
if (parameters !== void 0) {
|
|
6352
|
+
span2.setAttribute(`${prefix}.parameters`, safeStringify(parameters));
|
|
6353
|
+
}
|
|
6354
|
+
} else if (typeof toolType === "string") {
|
|
6355
|
+
span2.setAttribute(`${prefix}.name`, toolType);
|
|
6356
|
+
}
|
|
6357
|
+
});
|
|
6358
|
+
}
|
|
6359
|
+
function setInteractionRequestAttributes(span2, params) {
|
|
6360
|
+
try {
|
|
6361
|
+
if (!span2.isRecording()) return;
|
|
6362
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_TYPE, "chat");
|
|
6363
|
+
span2.setAttribute(SpanAttributes2.LLM_SYSTEM, "google_genai");
|
|
6364
|
+
if (params.model) {
|
|
6365
|
+
span2.setAttribute(
|
|
6366
|
+
SpanAttributes2.LLM_REQUEST_MODEL,
|
|
6367
|
+
extractModelName(String(params.model))
|
|
6368
|
+
);
|
|
6369
|
+
}
|
|
6370
|
+
if (params.agent !== void 0) {
|
|
6371
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_AGENT, String(params.agent));
|
|
6372
|
+
}
|
|
6373
|
+
if (params.agent_config !== void 0) {
|
|
6374
|
+
span2.setAttribute(
|
|
6375
|
+
SpanAttributes2.LLM_REQUEST_AGENT_CONFIG,
|
|
6376
|
+
safeStringify(params.agent_config)
|
|
6377
|
+
);
|
|
6378
|
+
}
|
|
6379
|
+
const cfg = params.generation_config;
|
|
6380
|
+
if (isDict(cfg)) {
|
|
6381
|
+
if (cfg.temperature !== void 0) {
|
|
6382
|
+
span2.setAttribute(
|
|
6383
|
+
SpanAttributes2.LLM_REQUEST_TEMPERATURE,
|
|
6384
|
+
Number(cfg.temperature)
|
|
6385
|
+
);
|
|
6386
|
+
}
|
|
6387
|
+
if (cfg.top_p !== void 0) {
|
|
6388
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_TOP_P, Number(cfg.top_p));
|
|
6389
|
+
}
|
|
6390
|
+
if (cfg.max_output_tokens !== void 0) {
|
|
6391
|
+
span2.setAttribute(
|
|
6392
|
+
SpanAttributes2.LLM_REQUEST_MAX_TOKENS,
|
|
6393
|
+
Number(cfg.max_output_tokens)
|
|
6394
|
+
);
|
|
6395
|
+
}
|
|
6396
|
+
if (cfg.seed !== void 0) {
|
|
6397
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_SEED, Number(cfg.seed));
|
|
6398
|
+
}
|
|
6399
|
+
if (cfg.stop_sequences !== void 0) {
|
|
6400
|
+
span2.setAttribute(
|
|
6401
|
+
SpanAttributes2.LLM_CHAT_STOP_SEQUENCES,
|
|
6402
|
+
safeStringify(cfg.stop_sequences)
|
|
6403
|
+
);
|
|
6404
|
+
}
|
|
6405
|
+
if (cfg.thinking_level !== void 0) {
|
|
6406
|
+
span2.setAttribute(
|
|
6407
|
+
SpanAttributes2.LLM_REQUEST_REASONING_EFFORT,
|
|
6408
|
+
String(cfg.thinking_level)
|
|
6409
|
+
);
|
|
6410
|
+
}
|
|
6411
|
+
if (cfg.thinking_summaries !== void 0) {
|
|
6412
|
+
span2.setAttribute(
|
|
6413
|
+
SpanAttributes2.LLM_REQUEST_THINKING_SUMMARIES,
|
|
6414
|
+
String(cfg.thinking_summaries)
|
|
6415
|
+
);
|
|
6416
|
+
}
|
|
6417
|
+
if (cfg.tool_choice !== void 0) {
|
|
6418
|
+
span2.setAttribute(
|
|
6419
|
+
SpanAttributes2.LLM_REQUEST_TOOL_CHOICE,
|
|
6420
|
+
safeStringify(cfg.tool_choice)
|
|
6421
|
+
);
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
setToolDefinitions(span2, params.tools);
|
|
6425
|
+
if (typeof params.store === "boolean") {
|
|
6426
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_STORE, params.store);
|
|
6427
|
+
}
|
|
6428
|
+
if (typeof params.background === "boolean") {
|
|
6429
|
+
span2.setAttribute(
|
|
6430
|
+
SpanAttributes2.LLM_REQUEST_BACKGROUND,
|
|
6431
|
+
params.background
|
|
6432
|
+
);
|
|
6433
|
+
}
|
|
6434
|
+
if (params.previous_interaction_id !== void 0) {
|
|
6435
|
+
span2.setAttribute(
|
|
6436
|
+
SpanAttributes2.LLM_REQUEST_PREVIOUS_INTERACTION_ID,
|
|
6437
|
+
String(params.previous_interaction_id)
|
|
6438
|
+
);
|
|
6439
|
+
}
|
|
6440
|
+
if (params.response_mime_type !== void 0) {
|
|
6441
|
+
span2.setAttribute(
|
|
6442
|
+
SpanAttributes2.LLM_REQUEST_RESPONSE_MIME_TYPE,
|
|
6443
|
+
String(params.response_mime_type)
|
|
6444
|
+
);
|
|
6445
|
+
}
|
|
6446
|
+
if (params.service_tier !== void 0) {
|
|
6447
|
+
span2.setAttribute(
|
|
6448
|
+
SpanAttributes2.LLM_REQUEST_SERVICE_TIER,
|
|
6449
|
+
String(params.service_tier)
|
|
6450
|
+
);
|
|
6451
|
+
}
|
|
6452
|
+
if (params.response_format !== void 0) {
|
|
6453
|
+
span2.setAttribute(
|
|
6454
|
+
SpanAttributes2.LLM_REQUEST_RESPONSE_FORMAT,
|
|
6455
|
+
safeStringify(params.response_format)
|
|
6456
|
+
);
|
|
6457
|
+
}
|
|
6458
|
+
if (Array.isArray(params.response_modalities)) {
|
|
6459
|
+
span2.setAttribute(
|
|
6460
|
+
SpanAttributes2.LLM_REQUEST_RESPONSE_MODALITIES,
|
|
6461
|
+
params.response_modalities.map((m) => String(m))
|
|
6462
|
+
);
|
|
6463
|
+
}
|
|
6464
|
+
if (!isTraceContentEnabled()) return;
|
|
6465
|
+
const messages = [];
|
|
6466
|
+
if (params.system_instruction !== void 0) {
|
|
6467
|
+
messages.push({
|
|
6468
|
+
role: "system",
|
|
6469
|
+
content: String(params.system_instruction)
|
|
6470
|
+
});
|
|
6471
|
+
}
|
|
6472
|
+
messages.push(...inputMessages(params.input));
|
|
6473
|
+
writePromptAttributes(
|
|
6474
|
+
span2,
|
|
6475
|
+
messages.filter((m) => m.content)
|
|
6476
|
+
);
|
|
6477
|
+
} catch (e) {
|
|
6478
|
+
Logger.error(`${LOG_PREFIX2}: setInteractionRequestAttributes error`, e);
|
|
6479
|
+
}
|
|
6480
|
+
}
|
|
6481
|
+
var MODALITY_USAGE_PREFIXES = {
|
|
6482
|
+
input_tokens_by_modality: "gen_ai.usage.input_tokens_by_modality",
|
|
6483
|
+
output_tokens_by_modality: "gen_ai.usage.output_tokens_by_modality",
|
|
6484
|
+
cached_tokens_by_modality: "gen_ai.usage.cached_tokens_by_modality",
|
|
6485
|
+
tool_use_tokens_by_modality: "gen_ai.usage.tool_use_tokens_by_modality"
|
|
6486
|
+
};
|
|
6487
|
+
function setUsageAttributes3(span2, usage) {
|
|
6488
|
+
if (!isDict(usage)) return;
|
|
6489
|
+
const totals = [
|
|
6490
|
+
["total_input_tokens", SpanAttributes2.LLM_USAGE_PROMPT_TOKENS],
|
|
6491
|
+
["total_tokens", SpanAttributes2.LLM_USAGE_TOTAL_TOKENS],
|
|
6492
|
+
["total_cached_tokens", SpanAttributes2.LLM_USAGE_CACHE_READ_INPUT_TOKENS],
|
|
6493
|
+
["total_thought_tokens", SpanAttributes2.LLM_USAGE_REASONING_TOKENS],
|
|
6494
|
+
["total_tool_use_tokens", SpanAttributes2.LLM_USAGE_TOOL_USE_TOKENS]
|
|
6495
|
+
];
|
|
6496
|
+
for (const [field_, attribute] of totals) {
|
|
6497
|
+
const value = usage[field_];
|
|
6498
|
+
if (typeof value === "number") span2.setAttribute(attribute, value);
|
|
6499
|
+
}
|
|
6500
|
+
let completion = 0;
|
|
6501
|
+
let hasCompletion = false;
|
|
6502
|
+
for (const field_ of ["total_output_tokens", "total_thought_tokens"]) {
|
|
6503
|
+
const value = usage[field_];
|
|
6504
|
+
if (typeof value === "number") {
|
|
6505
|
+
completion += value;
|
|
6506
|
+
hasCompletion = true;
|
|
6507
|
+
}
|
|
6508
|
+
}
|
|
6509
|
+
if (hasCompletion) {
|
|
6510
|
+
span2.setAttribute(SpanAttributes2.LLM_USAGE_COMPLETION_TOKENS, completion);
|
|
6511
|
+
}
|
|
6512
|
+
for (const [field_, prefix] of Object.entries(MODALITY_USAGE_PREFIXES)) {
|
|
6513
|
+
const entries = usage[field_];
|
|
6514
|
+
if (!Array.isArray(entries)) continue;
|
|
6515
|
+
for (const entry of entries) {
|
|
6516
|
+
const modality = field(entry, "modality");
|
|
6517
|
+
const tokens = field(entry, "tokens");
|
|
6518
|
+
if (modality && typeof tokens === "number") {
|
|
6519
|
+
span2.setAttribute(`${prefix}.${String(modality)}`, tokens);
|
|
6520
|
+
}
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
const grounding = usage.grounding_tool_count;
|
|
6524
|
+
if (Array.isArray(grounding)) {
|
|
6525
|
+
for (const entry of grounding) {
|
|
6526
|
+
const toolType = field(entry, "type");
|
|
6527
|
+
const count = field(entry, "count");
|
|
6528
|
+
if (toolType && typeof count === "number") {
|
|
6529
|
+
span2.setAttribute(
|
|
6530
|
+
`${SpanAttributes2.LLM_USAGE_GROUNDING_TOOL_COUNT}.${String(toolType)}`,
|
|
6531
|
+
count
|
|
6532
|
+
);
|
|
6533
|
+
}
|
|
6534
|
+
}
|
|
6535
|
+
}
|
|
6536
|
+
}
|
|
6537
|
+
function outputSteps(steps) {
|
|
6538
|
+
if (!Array.isArray(steps)) return [];
|
|
6539
|
+
let firstOutput = 0;
|
|
6540
|
+
steps.forEach((step, index) => {
|
|
6541
|
+
if (field(step, "type") === "user_input") firstOutput = index + 1;
|
|
6542
|
+
});
|
|
6543
|
+
return steps.slice(firstOutput);
|
|
6544
|
+
}
|
|
6545
|
+
function interactionOutputText(steps) {
|
|
6546
|
+
return outputSteps(steps).filter((step) => field(step, "type") === "model_output").map((step) => contentText(field(step, "content"))).join("");
|
|
6547
|
+
}
|
|
6548
|
+
function setInteractionResponseAttributes(span2, interaction) {
|
|
6549
|
+
try {
|
|
6550
|
+
if (!span2.isRecording() || !isDict(interaction)) return;
|
|
6551
|
+
if (interaction.id !== void 0 && interaction.id !== null) {
|
|
6552
|
+
const id = String(interaction.id);
|
|
6553
|
+
span2.setAttribute(SpanAttributes2.LLM_RESPONSE_ID, id);
|
|
6554
|
+
span2.setAttribute("llm.response.id", id);
|
|
6555
|
+
}
|
|
6556
|
+
if (interaction.model !== void 0 && interaction.model !== null) {
|
|
6557
|
+
span2.setAttribute(
|
|
6558
|
+
SpanAttributes2.LLM_RESPONSE_MODEL,
|
|
6559
|
+
String(interaction.model)
|
|
6560
|
+
);
|
|
6561
|
+
}
|
|
6562
|
+
if (interaction.status !== void 0 && interaction.status !== null) {
|
|
6563
|
+
const status = String(interaction.status);
|
|
6564
|
+
span2.setAttribute(SpanAttributes2.LLM_RESPONSE_STATUS, status);
|
|
6565
|
+
span2.setAttribute(SpanAttributes2.LLM_RESPONSE_FINISH_REASON, status);
|
|
6566
|
+
span2.setAttribute("gen_ai.response.finish_reason", status);
|
|
6567
|
+
}
|
|
6568
|
+
if (interaction.previous_interaction_id !== void 0 && interaction.previous_interaction_id !== null) {
|
|
6569
|
+
span2.setAttribute(
|
|
6570
|
+
SpanAttributes2.LLM_RESPONSE_PREVIOUS_INTERACTION_ID,
|
|
6571
|
+
String(interaction.previous_interaction_id)
|
|
6572
|
+
);
|
|
6573
|
+
}
|
|
6574
|
+
setUsageAttributes3(span2, interaction.usage);
|
|
6575
|
+
if (Array.isArray(interaction.steps)) {
|
|
6576
|
+
span2.setAttribute(
|
|
6577
|
+
SpanAttributes2.LLM_INTERACTION_STEP_COUNT,
|
|
6578
|
+
interaction.steps.length
|
|
6579
|
+
);
|
|
6580
|
+
}
|
|
6581
|
+
if (!isTraceContentEnabled()) return;
|
|
6582
|
+
const reasoning = [];
|
|
6583
|
+
const emitted = [];
|
|
6584
|
+
let index = 0;
|
|
6585
|
+
for (const step of outputSteps(interaction.steps)) {
|
|
6586
|
+
const message = stepMessage(step);
|
|
6587
|
+
if (!message) continue;
|
|
6588
|
+
if (message.stepType === "thought") {
|
|
6589
|
+
if (message.content) reasoning.push(message.content);
|
|
6590
|
+
continue;
|
|
6591
|
+
}
|
|
6592
|
+
if (!message.content) continue;
|
|
6593
|
+
const prefix = `${SpanAttributes2.LLM_COMPLETIONS}.${index}`;
|
|
6594
|
+
span2.setAttribute(`${prefix}.role`, message.role);
|
|
6595
|
+
span2.setAttribute(`${prefix}.content`, message.content);
|
|
6596
|
+
span2.setAttribute(`${prefix}.step_type`, message.stepType ?? "");
|
|
6597
|
+
if (message.toolCall) {
|
|
6598
|
+
span2.setAttribute(
|
|
6599
|
+
`${prefix}.tool_calls.0.name`,
|
|
6600
|
+
String(message.toolCall.name ?? "")
|
|
6601
|
+
);
|
|
6602
|
+
if (message.toolCall.id !== void 0) {
|
|
6603
|
+
span2.setAttribute(
|
|
6604
|
+
`${prefix}.tool_calls.0.id`,
|
|
6605
|
+
String(message.toolCall.id)
|
|
6606
|
+
);
|
|
6607
|
+
}
|
|
6608
|
+
if (message.toolCall.arguments !== void 0) {
|
|
6609
|
+
span2.setAttribute(
|
|
6610
|
+
`${prefix}.tool_calls.0.arguments`,
|
|
6611
|
+
safeStringify(message.toolCall.arguments)
|
|
6612
|
+
);
|
|
6613
|
+
}
|
|
6614
|
+
}
|
|
6615
|
+
if (message.modalities && message.modalities.length > 0) {
|
|
6616
|
+
span2.setAttribute(`${prefix}.modality`, message.modalities);
|
|
6617
|
+
}
|
|
6618
|
+
emitted.push(message);
|
|
6619
|
+
index += 1;
|
|
6620
|
+
}
|
|
6621
|
+
if (emitted.length > 0) {
|
|
6622
|
+
span2.setAttribute(
|
|
6623
|
+
"output",
|
|
6624
|
+
JSON.stringify(
|
|
6625
|
+
emitted.map((m) => ({ role: m.role, content: m.content }))
|
|
6626
|
+
)
|
|
6627
|
+
);
|
|
6628
|
+
}
|
|
6629
|
+
if (reasoning.length > 0) {
|
|
6630
|
+
span2.setAttribute(
|
|
6631
|
+
SpanAttributes2.LLM_RESPONSE_REASONING,
|
|
6632
|
+
reasoning.join("")
|
|
6633
|
+
);
|
|
6634
|
+
}
|
|
6635
|
+
} catch (e) {
|
|
6636
|
+
Logger.error(`${LOG_PREFIX2}: setInteractionResponseAttributes error`, e);
|
|
6637
|
+
}
|
|
6638
|
+
}
|
|
6639
|
+
|
|
6640
|
+
// src/instrumentation/google-genai/types.ts
|
|
6641
|
+
var SPAN_NAMES2 = {
|
|
6642
|
+
CHAT: "google_genai.chat",
|
|
6643
|
+
EMBEDDING: "google_genai.embedding",
|
|
6644
|
+
INTERACTION: "google_genai.interaction"
|
|
6645
|
+
};
|
|
6646
|
+
|
|
6647
|
+
// src/instrumentation/google-genai/interactions-wrapper.ts
|
|
6648
|
+
var LOG_PREFIX3 = "netra.instrumentation.google_genai";
|
|
6649
|
+
var NETRA_STREAM = /* @__PURE__ */ Symbol.for("netra.googlegenai.interactions.stream");
|
|
6650
|
+
var INTERACTION_CREATED = "interaction.created";
|
|
6651
|
+
var INTERACTION_COMPLETED = "interaction.completed";
|
|
6652
|
+
var INTERACTION_STATUS_UPDATE = "interaction.status_update";
|
|
6653
|
+
var STEP_START = "step.start";
|
|
6654
|
+
var STEP_DELTA = "step.delta";
|
|
6655
|
+
var ERROR_EVENT = "error";
|
|
6656
|
+
function field2(obj, name) {
|
|
6657
|
+
if (obj === null || obj === void 0) return void 0;
|
|
6658
|
+
return obj[name];
|
|
6659
|
+
}
|
|
6660
|
+
var InteractionStreamAccumulator = class {
|
|
6661
|
+
constructor(span2, startTime) {
|
|
6662
|
+
this.span = span2;
|
|
6663
|
+
this.startTime = startTime;
|
|
6664
|
+
this.finalized = false;
|
|
6665
|
+
this.unobserved = null;
|
|
6666
|
+
this.firstTextRecorded = false;
|
|
6667
|
+
this.stepTypes = /* @__PURE__ */ new Map();
|
|
6668
|
+
this.stepText = /* @__PURE__ */ new Map();
|
|
6669
|
+
this.stepThoughts = /* @__PURE__ */ new Map();
|
|
6670
|
+
this.stepArguments = /* @__PURE__ */ new Map();
|
|
6671
|
+
this.stepMeta = /* @__PURE__ */ new Map();
|
|
6672
|
+
this.completedSteps = null;
|
|
6673
|
+
this.output = "";
|
|
6674
|
+
}
|
|
6675
|
+
processEvent(event) {
|
|
6676
|
+
try {
|
|
6677
|
+
this.reduce(event);
|
|
6678
|
+
} catch (e) {
|
|
6679
|
+
Logger.error(`${LOG_PREFIX3}: interaction event error`, e);
|
|
6680
|
+
}
|
|
6681
|
+
}
|
|
6682
|
+
reduce(event) {
|
|
6683
|
+
this.absorbUsage(event);
|
|
6684
|
+
const eventType = field2(event, "event_type");
|
|
6685
|
+
switch (eventType) {
|
|
6686
|
+
case INTERACTION_CREATED: {
|
|
6687
|
+
const interaction = field2(event, "interaction");
|
|
6688
|
+
this.id = field2(interaction, "id") ?? this.id;
|
|
6689
|
+
this.model = field2(interaction, "model") ?? this.model;
|
|
6690
|
+
this.status = field2(interaction, "status") ?? this.status;
|
|
6691
|
+
break;
|
|
6692
|
+
}
|
|
6693
|
+
case STEP_START: {
|
|
6694
|
+
const index = field2(event, "index");
|
|
6695
|
+
const step = field2(event, "step");
|
|
6696
|
+
if (typeof index !== "number") break;
|
|
6697
|
+
const stepType = field2(step, "type");
|
|
6698
|
+
if (typeof stepType === "string") this.stepTypes.set(index, stepType);
|
|
6699
|
+
if (stepType === "function_call") {
|
|
6700
|
+
this.stepMeta.set(index, {
|
|
6701
|
+
id: field2(step, "id"),
|
|
6702
|
+
name: field2(step, "name")
|
|
6703
|
+
});
|
|
6704
|
+
}
|
|
6705
|
+
break;
|
|
6706
|
+
}
|
|
6707
|
+
case STEP_DELTA:
|
|
6708
|
+
this.reduceDelta(field2(event, "index"), field2(event, "delta"));
|
|
6709
|
+
break;
|
|
6710
|
+
case INTERACTION_STATUS_UPDATE:
|
|
6711
|
+
this.status = field2(event, "status") ?? this.status;
|
|
6712
|
+
break;
|
|
6713
|
+
case INTERACTION_COMPLETED: {
|
|
6714
|
+
const interaction = field2(event, "interaction");
|
|
6715
|
+
this.id = field2(interaction, "id") ?? this.id;
|
|
6716
|
+
this.model = field2(interaction, "model") ?? this.model;
|
|
6717
|
+
this.status = field2(interaction, "status") ?? this.status;
|
|
6718
|
+
const steps = field2(interaction, "steps");
|
|
6719
|
+
if (Array.isArray(steps) && steps.length > 0) this.completedSteps = steps;
|
|
6720
|
+
break;
|
|
6721
|
+
}
|
|
6722
|
+
case ERROR_EVENT:
|
|
6723
|
+
this.error = field2(event, "error");
|
|
6724
|
+
break;
|
|
6725
|
+
}
|
|
6726
|
+
}
|
|
6727
|
+
reduceDelta(index, delta) {
|
|
6728
|
+
if (typeof index !== "number" || delta === null || delta === void 0) return;
|
|
6729
|
+
const deltaType = field2(delta, "type");
|
|
6730
|
+
if (deltaType === "text") {
|
|
6731
|
+
const text = field2(delta, "text");
|
|
6732
|
+
if (typeof text === "string" && text.length > 0) {
|
|
6733
|
+
push(this.stepText, index, text);
|
|
6734
|
+
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "model_output");
|
|
6735
|
+
this.recordFirstText();
|
|
6736
|
+
}
|
|
6737
|
+
} else if (deltaType === "thought_summary") {
|
|
6738
|
+
const text = deltaContentText(field2(delta, "content"));
|
|
6739
|
+
if (text) {
|
|
6740
|
+
push(this.stepThoughts, index, text);
|
|
6741
|
+
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "thought");
|
|
6742
|
+
}
|
|
6743
|
+
} else if (deltaType === "arguments_delta") {
|
|
6744
|
+
const fragment = field2(delta, "arguments") ?? field2(delta, "delta");
|
|
6745
|
+
if (typeof fragment === "string" && fragment.length > 0) {
|
|
6746
|
+
push(this.stepArguments, index, fragment);
|
|
6747
|
+
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "function_call");
|
|
6748
|
+
}
|
|
6749
|
+
} else if (deltaType === "image" || deltaType === "audio" || deltaType === "document" || deltaType === "video") {
|
|
6750
|
+
push(this.stepText, index, `<${deltaType}>`);
|
|
6751
|
+
if (!this.stepTypes.has(index)) this.stepTypes.set(index, "model_output");
|
|
6752
|
+
}
|
|
6753
|
+
}
|
|
6754
|
+
recordFirstText() {
|
|
6755
|
+
if (this.firstTextRecorded) return;
|
|
6756
|
+
this.firstTextRecorded = true;
|
|
6757
|
+
this.span.setAttribute(
|
|
6758
|
+
"gen_ai.performance.time_to_first_token",
|
|
6759
|
+
(Date.now() - this.startTime) / 1e3
|
|
6760
|
+
);
|
|
6761
|
+
}
|
|
6762
|
+
absorbUsage(event) {
|
|
6763
|
+
const metadata = field2(event, "metadata");
|
|
6764
|
+
const candidates = [
|
|
6765
|
+
field2(metadata, "total_usage"),
|
|
6766
|
+
field2(metadata, "usage"),
|
|
6767
|
+
field2(event, "usage"),
|
|
6768
|
+
field2(field2(event, "interaction"), "usage")
|
|
6769
|
+
];
|
|
6770
|
+
for (const candidate of candidates) {
|
|
6771
|
+
if (candidate !== void 0 && candidate !== null) {
|
|
6772
|
+
this.usage = candidate;
|
|
6773
|
+
return;
|
|
6774
|
+
}
|
|
6775
|
+
}
|
|
6776
|
+
}
|
|
6777
|
+
/** Mark the stream as consumed through a path we cannot observe. */
|
|
6778
|
+
abandon(via) {
|
|
6779
|
+
this.unobserved = via;
|
|
6780
|
+
this.finalize();
|
|
6781
|
+
}
|
|
6782
|
+
buildInteraction() {
|
|
6783
|
+
const steps = this.completedSteps && this.stepText.size === 0 ? this.completedSteps : this.buildSteps();
|
|
6784
|
+
return {
|
|
6785
|
+
id: this.id,
|
|
6786
|
+
model: this.model,
|
|
6787
|
+
status: this.status,
|
|
6788
|
+
usage: this.usage,
|
|
6789
|
+
steps
|
|
6790
|
+
};
|
|
6791
|
+
}
|
|
6792
|
+
buildSteps() {
|
|
6793
|
+
const indices = /* @__PURE__ */ new Set([
|
|
6794
|
+
...this.stepTypes.keys(),
|
|
6795
|
+
...this.stepText.keys(),
|
|
6796
|
+
...this.stepThoughts.keys()
|
|
6797
|
+
]);
|
|
6798
|
+
return [...indices].sort((a, b) => a - b).map((index) => {
|
|
6799
|
+
const stepType = this.stepTypes.get(index) ?? "model_output";
|
|
6800
|
+
if (stepType === "thought") {
|
|
6801
|
+
return {
|
|
6802
|
+
type: "thought",
|
|
6803
|
+
summary: [
|
|
6804
|
+
{ type: "text", text: (this.stepThoughts.get(index) ?? []).join("") }
|
|
6805
|
+
]
|
|
6806
|
+
};
|
|
6807
|
+
}
|
|
6808
|
+
if (stepType === "function_call") {
|
|
6809
|
+
const meta = this.stepMeta.get(index) ?? {};
|
|
6810
|
+
return {
|
|
6811
|
+
type: "function_call",
|
|
6812
|
+
id: meta.id,
|
|
6813
|
+
name: meta.name,
|
|
6814
|
+
arguments: parseArguments(
|
|
6815
|
+
(this.stepArguments.get(index) ?? []).join("")
|
|
6816
|
+
)
|
|
6817
|
+
};
|
|
6818
|
+
}
|
|
6819
|
+
return {
|
|
6820
|
+
type: stepType,
|
|
6821
|
+
content: [
|
|
6822
|
+
{ type: "text", text: (this.stepText.get(index) ?? []).join("") }
|
|
6823
|
+
]
|
|
6824
|
+
};
|
|
6825
|
+
});
|
|
6826
|
+
}
|
|
6827
|
+
/** Close the span. Safe to call more than once. */
|
|
6828
|
+
finalize() {
|
|
6829
|
+
if (this.finalized) return;
|
|
6830
|
+
this.finalized = true;
|
|
6831
|
+
try {
|
|
6832
|
+
const interaction = this.buildInteraction();
|
|
6833
|
+
setInteractionResponseAttributes(this.span, interaction);
|
|
6834
|
+
this.output = interactionOutputText(interaction.steps);
|
|
6835
|
+
this.span.setAttribute(
|
|
6836
|
+
SpanAttributes2.LLM_RESPONSE_DURATION,
|
|
6837
|
+
(Date.now() - this.startTime) / 1e3
|
|
6838
|
+
);
|
|
6839
|
+
if (this.unobserved) {
|
|
6840
|
+
this.span.setAttribute(SpanAttributes2.STREAM_UNOBSERVED, this.unobserved);
|
|
6841
|
+
}
|
|
6842
|
+
if (this.error) {
|
|
6843
|
+
this.span.setAttribute(
|
|
6844
|
+
"error.type",
|
|
6845
|
+
String(field2(this.error, "code") ?? "error")
|
|
6846
|
+
);
|
|
6847
|
+
this.span.setStatus({
|
|
6848
|
+
code: SpanStatusCode.ERROR,
|
|
6849
|
+
message: String(field2(this.error, "message") ?? "interaction failed")
|
|
6850
|
+
});
|
|
6851
|
+
} else {
|
|
6852
|
+
this.span.setStatus({ code: SpanStatusCode.OK });
|
|
6853
|
+
}
|
|
6854
|
+
} catch (e) {
|
|
6855
|
+
Logger.error(`${LOG_PREFIX3}: interaction finalize error`, e);
|
|
6856
|
+
} finally {
|
|
6857
|
+
this.span.end();
|
|
6858
|
+
}
|
|
6859
|
+
}
|
|
6860
|
+
fail(error) {
|
|
6861
|
+
if (this.finalized) return;
|
|
6862
|
+
this.span.setStatus({
|
|
6863
|
+
code: SpanStatusCode.ERROR,
|
|
6864
|
+
message: error instanceof Error ? error.message : String(error)
|
|
6865
|
+
});
|
|
6866
|
+
this.span.recordException(error);
|
|
6867
|
+
this.finalize();
|
|
6868
|
+
}
|
|
6869
|
+
};
|
|
6870
|
+
function push(map, index, value) {
|
|
6871
|
+
const existing = map.get(index);
|
|
6872
|
+
if (existing) existing.push(value);
|
|
6873
|
+
else map.set(index, [value]);
|
|
6874
|
+
}
|
|
6875
|
+
function deltaContentText(content) {
|
|
6876
|
+
if (content === null || content === void 0) return "";
|
|
6877
|
+
if (typeof content === "string") return content;
|
|
6878
|
+
const items = Array.isArray(content) ? content : [content];
|
|
6879
|
+
return items.map((item) => String(field2(item, "text") ?? "")).join("");
|
|
6880
|
+
}
|
|
6881
|
+
function parseArguments(raw) {
|
|
6882
|
+
if (!raw) return {};
|
|
6883
|
+
try {
|
|
6884
|
+
return JSON.parse(raw);
|
|
6885
|
+
} catch {
|
|
6886
|
+
return raw;
|
|
6887
|
+
}
|
|
6888
|
+
}
|
|
6889
|
+
function isInteractionStream(value) {
|
|
6890
|
+
return value !== null && value !== void 0 && typeof value[Symbol.asyncIterator] === "function";
|
|
6891
|
+
}
|
|
6892
|
+
function wrapIterator(iterator, accumulator, withContext) {
|
|
6893
|
+
return {
|
|
6894
|
+
async next(value) {
|
|
6895
|
+
try {
|
|
6896
|
+
const result = await withContext(() => iterator.next(value));
|
|
6897
|
+
if (result.done) accumulator.finalize();
|
|
6898
|
+
else accumulator.processEvent(result.value);
|
|
6899
|
+
return result;
|
|
6900
|
+
} catch (e) {
|
|
6901
|
+
accumulator.fail(e);
|
|
6902
|
+
throw e;
|
|
6903
|
+
}
|
|
6904
|
+
},
|
|
6905
|
+
async return(value) {
|
|
6906
|
+
try {
|
|
6907
|
+
const result = await withContext(
|
|
6908
|
+
() => iterator.return?.(value) ?? { done: true, value }
|
|
6909
|
+
);
|
|
6910
|
+
accumulator.finalize();
|
|
6911
|
+
return result;
|
|
6912
|
+
} catch (e) {
|
|
6913
|
+
accumulator.fail(e);
|
|
6914
|
+
throw e;
|
|
6915
|
+
}
|
|
6916
|
+
},
|
|
6917
|
+
async throw(e) {
|
|
6918
|
+
try {
|
|
6919
|
+
const result = await withContext(() => {
|
|
6920
|
+
if (iterator.throw) return iterator.throw(e);
|
|
6921
|
+
throw e;
|
|
6922
|
+
});
|
|
6923
|
+
if (result.done) accumulator.finalize();
|
|
6924
|
+
return result;
|
|
6925
|
+
} catch (err) {
|
|
6926
|
+
accumulator.fail(err);
|
|
6927
|
+
throw err;
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
};
|
|
6931
|
+
}
|
|
6932
|
+
var UNOBSERVED_METHODS = /* @__PURE__ */ new Set(["getReader", "pipeTo", "pipeThrough", "tee"]);
|
|
6933
|
+
function instrumentInteractionStream(stream, accumulator, withContext) {
|
|
6934
|
+
if (stream[NETRA_STREAM]) return stream;
|
|
6935
|
+
const makeIterator = (options) => wrapIterator(stream[Symbol.asyncIterator](options), accumulator, withContext);
|
|
6936
|
+
return new Proxy(stream, {
|
|
6937
|
+
get(target, property) {
|
|
6938
|
+
if (property === NETRA_STREAM) return true;
|
|
6939
|
+
if (property === Symbol.asyncIterator || property === "values") {
|
|
6940
|
+
return (options) => makeIterator(options);
|
|
6941
|
+
}
|
|
6942
|
+
if (typeof property === "string" && UNOBSERVED_METHODS.has(property)) {
|
|
6943
|
+
const original = Reflect.get(target, property, target);
|
|
6944
|
+
if (typeof original !== "function") return original;
|
|
6945
|
+
return (...args) => {
|
|
6946
|
+
accumulator.abandon(property);
|
|
6947
|
+
return original.apply(target, args);
|
|
6948
|
+
};
|
|
6949
|
+
}
|
|
6950
|
+
const value = Reflect.get(target, property, target);
|
|
6951
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
6952
|
+
}
|
|
6953
|
+
});
|
|
6954
|
+
}
|
|
6955
|
+
function interactionsWrapper(tracer) {
|
|
6956
|
+
return function wrapper(original) {
|
|
6957
|
+
return function(...args) {
|
|
6958
|
+
if (shouldSuppressInstrumentation()) {
|
|
6959
|
+
return original.apply(this, args);
|
|
6960
|
+
}
|
|
6961
|
+
const params = args[0] ?? {};
|
|
6962
|
+
const currentContext = context.active();
|
|
6963
|
+
return tracer.startActiveSpan(
|
|
6964
|
+
SPAN_NAMES2.INTERACTION,
|
|
6965
|
+
{ kind: SpanKind.CLIENT },
|
|
6966
|
+
(span2) => {
|
|
6967
|
+
const startTime = Date.now();
|
|
6968
|
+
try {
|
|
6969
|
+
setInteractionRequestAttributes(span2, params);
|
|
6970
|
+
const spanContext = trace.setSpan(currentContext, span2);
|
|
6971
|
+
const withContext = (fn) => context.with(spanContext, fn);
|
|
6972
|
+
const suppressedCtx = createSuppressedContext(spanContext);
|
|
6973
|
+
const response = context.with(
|
|
6974
|
+
suppressedCtx,
|
|
6975
|
+
() => original.apply(this, args)
|
|
6976
|
+
);
|
|
6977
|
+
if (!isPromise(response)) {
|
|
6978
|
+
return finishNonStreaming(span2, response, startTime);
|
|
6979
|
+
}
|
|
6980
|
+
return response.then(
|
|
6981
|
+
(value) => {
|
|
6982
|
+
if (isInteractionStream(value)) {
|
|
6983
|
+
span2.setAttribute(SpanAttributes2.LLM_IS_STREAMING, true);
|
|
6984
|
+
const accumulator = new InteractionStreamAccumulator(
|
|
6985
|
+
span2,
|
|
6986
|
+
startTime
|
|
6987
|
+
);
|
|
6988
|
+
return instrumentInteractionStream(
|
|
6989
|
+
value,
|
|
6990
|
+
accumulator,
|
|
6991
|
+
withContext
|
|
6992
|
+
);
|
|
6993
|
+
}
|
|
6994
|
+
return finishNonStreaming(span2, value, startTime);
|
|
6995
|
+
},
|
|
6996
|
+
(error) => {
|
|
6997
|
+
span2.setStatus({
|
|
6998
|
+
code: SpanStatusCode.ERROR,
|
|
6999
|
+
message: error instanceof Error ? error.message : String(error)
|
|
7000
|
+
});
|
|
7001
|
+
span2.recordException(error);
|
|
7002
|
+
span2.end();
|
|
7003
|
+
throw error;
|
|
7004
|
+
}
|
|
7005
|
+
);
|
|
7006
|
+
} catch (error) {
|
|
7007
|
+
span2.setStatus({
|
|
7008
|
+
code: SpanStatusCode.ERROR,
|
|
7009
|
+
message: error instanceof Error ? error.message : String(error)
|
|
7010
|
+
});
|
|
7011
|
+
span2.recordException(error);
|
|
7012
|
+
span2.end();
|
|
7013
|
+
throw error;
|
|
7014
|
+
}
|
|
7015
|
+
}
|
|
7016
|
+
);
|
|
7017
|
+
};
|
|
7018
|
+
};
|
|
7019
|
+
}
|
|
7020
|
+
function finishNonStreaming(span2, value, startTime) {
|
|
7021
|
+
try {
|
|
7022
|
+
span2.setAttribute(SpanAttributes2.LLM_IS_STREAMING, false);
|
|
7023
|
+
setInteractionResponseAttributes(span2, value);
|
|
7024
|
+
span2.setAttribute(
|
|
7025
|
+
SpanAttributes2.LLM_RESPONSE_DURATION,
|
|
7026
|
+
(Date.now() - startTime) / 1e3
|
|
7027
|
+
);
|
|
7028
|
+
span2.setStatus({ code: SpanStatusCode.OK });
|
|
7029
|
+
} catch (e) {
|
|
7030
|
+
Logger.error(`${LOG_PREFIX3}: interaction response error`, e);
|
|
7031
|
+
} finally {
|
|
7032
|
+
span2.end();
|
|
7033
|
+
}
|
|
7034
|
+
return value;
|
|
7035
|
+
}
|
|
7036
|
+
|
|
7037
|
+
// src/instrumentation/google-genai/version.ts
|
|
7038
|
+
var __version__2 = "1.0.0";
|
|
7039
|
+
var LOG_PREFIX4 = "netra.instrumentation.google_genai";
|
|
6151
7040
|
function buildParams(args, self) {
|
|
6152
7041
|
const raw = args[0];
|
|
6153
7042
|
const params = typeof raw === "object" && raw !== null ? { ...raw } : { message: raw };
|
|
@@ -6287,7 +7176,7 @@ function streamWrapperFactory(tracer, spanName, requestType) {
|
|
|
6287
7176
|
(endTime - startTime) / 1e3
|
|
6288
7177
|
);
|
|
6289
7178
|
} catch (e) {
|
|
6290
|
-
Logger.error(`${
|
|
7179
|
+
Logger.error(`${LOG_PREFIX4}: stream finalize error`, e);
|
|
6291
7180
|
}
|
|
6292
7181
|
if (status === "ok") {
|
|
6293
7182
|
span2.setStatus({ code: SpanStatusCode.OK });
|
|
@@ -6316,6 +7205,9 @@ var chatStreamWrapper2 = (tracer) => streamWrapperFactory(tracer, SPAN_NAMES2.CH
|
|
|
6316
7205
|
var embeddingsWrapper = (tracer) => genericWrapperFactory(tracer, SPAN_NAMES2.EMBEDDING, "embedding");
|
|
6317
7206
|
|
|
6318
7207
|
// src/instrumentation/google-genai/index.ts
|
|
7208
|
+
var INTERACTIONS_PATCHED = /* @__PURE__ */ Symbol.for(
|
|
7209
|
+
"netra.googlegenai.interactions.patched"
|
|
7210
|
+
);
|
|
6319
7211
|
var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
6320
7212
|
constructor() {
|
|
6321
7213
|
super(...arguments);
|
|
@@ -6323,11 +7215,15 @@ var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
|
6323
7215
|
this.instrumentationVersion = __version__2;
|
|
6324
7216
|
this.packageName = "@google/genai";
|
|
6325
7217
|
this.displayName = "Google GenAI";
|
|
7218
|
+
/** Original `interactions` descriptors, for an exact restore on unpatch. */
|
|
7219
|
+
this.interactionsDescriptors = [];
|
|
7220
|
+
/** Resource prototypes whose `create` we wrapped. */
|
|
7221
|
+
this.patchedInteractionProtos = [];
|
|
6326
7222
|
}
|
|
6327
7223
|
extractClasses(mod) {
|
|
6328
7224
|
const root = mod.default ?? mod;
|
|
6329
7225
|
if (!root.Models) return null;
|
|
6330
|
-
return { Models: root.Models, Chat: root.Chat };
|
|
7226
|
+
return { Models: root.Models, Chat: root.Chat, GoogleGenAI: root.GoogleGenAI };
|
|
6331
7227
|
}
|
|
6332
7228
|
isSameClasses(a, b) {
|
|
6333
7229
|
return a.Models === b.Models;
|
|
@@ -6362,8 +7258,57 @@ var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
|
6362
7258
|
wrapped = true;
|
|
6363
7259
|
}
|
|
6364
7260
|
}
|
|
7261
|
+
if (this.patchInteractions(classes.GoogleGenAI, tracer)) {
|
|
7262
|
+
wrapped = true;
|
|
7263
|
+
}
|
|
6365
7264
|
return wrapped;
|
|
6366
7265
|
}
|
|
7266
|
+
/**
|
|
7267
|
+
* Redefine the `interactions` accessor so the resource prototype gets patched
|
|
7268
|
+
* on first access.
|
|
7269
|
+
*
|
|
7270
|
+
* shimmer cannot be used on the accessor itself -- it does a plain property
|
|
7271
|
+
* assignment, which would clobber the getter. Nothing is constructed here
|
|
7272
|
+
* either: `new GoogleGenAI({})` writes an API-key warning to the console.
|
|
7273
|
+
*
|
|
7274
|
+
* A client that read `.interactions` before instrumentation finished keeps
|
|
7275
|
+
* its cached resource, but the prototype is shared, so the patch still
|
|
7276
|
+
* applies the next time any instance reads the accessor. Netra.init() is
|
|
7277
|
+
* awaited before user code, so this is an edge case rather than a hole.
|
|
7278
|
+
*/
|
|
7279
|
+
patchInteractions(GoogleGenAI, tracer) {
|
|
7280
|
+
if (!GoogleGenAI?.prototype) return false;
|
|
7281
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
7282
|
+
GoogleGenAI.prototype,
|
|
7283
|
+
"interactions"
|
|
7284
|
+
);
|
|
7285
|
+
if (!descriptor?.get || !descriptor.configurable) return false;
|
|
7286
|
+
const originalGet = descriptor.get;
|
|
7287
|
+
const patchedProtos = this.patchedInteractionProtos;
|
|
7288
|
+
this.interactionsDescriptors.push([GoogleGenAI, descriptor]);
|
|
7289
|
+
Object.defineProperty(GoogleGenAI.prototype, "interactions", {
|
|
7290
|
+
configurable: true,
|
|
7291
|
+
enumerable: descriptor.enumerable,
|
|
7292
|
+
get() {
|
|
7293
|
+
const resource = originalGet.call(this);
|
|
7294
|
+
try {
|
|
7295
|
+
const proto = resource && Object.getPrototypeOf(resource);
|
|
7296
|
+
if (proto && !proto[INTERACTIONS_PATCHED] && typeof proto.create === "function") {
|
|
7297
|
+
Object.defineProperty(proto, INTERACTIONS_PATCHED, {
|
|
7298
|
+
value: true,
|
|
7299
|
+
configurable: true
|
|
7300
|
+
});
|
|
7301
|
+
shimmer.wrap(proto, "create", interactionsWrapper(tracer));
|
|
7302
|
+
patchedProtos.push(proto);
|
|
7303
|
+
}
|
|
7304
|
+
} catch (error) {
|
|
7305
|
+
Logger.error(`Google GenAI: failed to patch interactions: ${error}`);
|
|
7306
|
+
}
|
|
7307
|
+
return resource;
|
|
7308
|
+
}
|
|
7309
|
+
});
|
|
7310
|
+
return true;
|
|
7311
|
+
}
|
|
6367
7312
|
removePatches(classes) {
|
|
6368
7313
|
const modelsProto = classes.Models?.prototype;
|
|
6369
7314
|
if (modelsProto) {
|
|
@@ -6382,6 +7327,25 @@ var NetraGoogleGenAIInstrumentor = class extends BaseInstrumentor {
|
|
|
6382
7327
|
shimmer.unwrap(chatProto, "sendMessageStream");
|
|
6383
7328
|
}
|
|
6384
7329
|
}
|
|
7330
|
+
onUninstrument() {
|
|
7331
|
+
for (const proto of this.patchedInteractionProtos) {
|
|
7332
|
+
try {
|
|
7333
|
+
shimmer.unwrap(proto, "create");
|
|
7334
|
+
delete proto[INTERACTIONS_PATCHED];
|
|
7335
|
+
} catch (error) {
|
|
7336
|
+
Logger.error(`Google GenAI: failed to unwrap interactions.create: ${error}`);
|
|
7337
|
+
}
|
|
7338
|
+
}
|
|
7339
|
+
this.patchedInteractionProtos = [];
|
|
7340
|
+
for (const [GoogleGenAI, descriptor] of this.interactionsDescriptors) {
|
|
7341
|
+
try {
|
|
7342
|
+
Object.defineProperty(GoogleGenAI.prototype, "interactions", descriptor);
|
|
7343
|
+
} catch (error) {
|
|
7344
|
+
Logger.error(`Google GenAI: failed to restore interactions accessor: ${error}`);
|
|
7345
|
+
}
|
|
7346
|
+
}
|
|
7347
|
+
this.interactionsDescriptors = [];
|
|
7348
|
+
}
|
|
6385
7349
|
};
|
|
6386
7350
|
var googleGenAIInstrumentor = new NetraGoogleGenAIInstrumentor();
|
|
6387
7351
|
|
|
@@ -6785,7 +7749,7 @@ function _setEmbeddingResponseAttributes(span2, response) {
|
|
|
6785
7749
|
}
|
|
6786
7750
|
|
|
6787
7751
|
// src/instrumentation/google-generative-ai/wrappers.ts
|
|
6788
|
-
var
|
|
7752
|
+
var LOG_PREFIX5 = "netra.instrumentation.google_generative_ai";
|
|
6789
7753
|
var CHAT_SPAN_NAME = "google_generative_ai.chat";
|
|
6790
7754
|
var EMBEDDING_SPAN_NAME = "google_generative_ai.embedding";
|
|
6791
7755
|
function buildKwargs(instance) {
|
|
@@ -6830,7 +7794,7 @@ function googleGenerativeAIWrapper(tracer, spanName, requestType) {
|
|
|
6830
7794
|
try {
|
|
6831
7795
|
setRequestAttributes4(span2, kwargs, requestType, args[0]);
|
|
6832
7796
|
} catch (e) {
|
|
6833
|
-
Logger.error(`${
|
|
7797
|
+
Logger.error(`${LOG_PREFIX5}:`, e);
|
|
6834
7798
|
}
|
|
6835
7799
|
const startTime = Date.now();
|
|
6836
7800
|
const response = original.apply(this, args);
|
|
@@ -6851,7 +7815,7 @@ function googleGenerativeAIWrapper(tracer, spanName, requestType) {
|
|
|
6851
7815
|
);
|
|
6852
7816
|
}
|
|
6853
7817
|
} catch (e) {
|
|
6854
|
-
Logger.error(`${
|
|
7818
|
+
Logger.error(`${LOG_PREFIX5}:`, e);
|
|
6855
7819
|
}
|
|
6856
7820
|
span2.setStatus({ code: SpanStatusCode.OK });
|
|
6857
7821
|
span2.end();
|
|
@@ -6876,7 +7840,7 @@ function googleGenerativeAIWrapper(tracer, spanName, requestType) {
|
|
|
6876
7840
|
(endTime - startTime) / 1e3
|
|
6877
7841
|
);
|
|
6878
7842
|
} catch (e) {
|
|
6879
|
-
Logger.error(`${
|
|
7843
|
+
Logger.error(`${LOG_PREFIX5}:`, e);
|
|
6880
7844
|
}
|
|
6881
7845
|
span2.setStatus({ code: SpanStatusCode.OK });
|
|
6882
7846
|
span2.end();
|
|
@@ -6918,7 +7882,7 @@ function googleGenerativeAIStreamWrapper(tracer, spanName, requestType) {
|
|
|
6918
7882
|
try {
|
|
6919
7883
|
setRequestAttributes4(span2, kwargs, requestType, args[0]);
|
|
6920
7884
|
} catch (e) {
|
|
6921
|
-
Logger.error(`${
|
|
7885
|
+
Logger.error(`${LOG_PREFIX5}:`, e);
|
|
6922
7886
|
}
|
|
6923
7887
|
const response = original.apply(this, args);
|
|
6924
7888
|
if (!isPromise(response)) {
|
|
@@ -6942,7 +7906,7 @@ function googleGenerativeAIStreamWrapper(tracer, spanName, requestType) {
|
|
|
6942
7906
|
duration
|
|
6943
7907
|
);
|
|
6944
7908
|
} catch (e) {
|
|
6945
|
-
Logger.error(`${
|
|
7909
|
+
Logger.error(`${LOG_PREFIX5}:`, e);
|
|
6946
7910
|
}
|
|
6947
7911
|
span2.setStatus({ code: SpanStatusCode.OK });
|
|
6948
7912
|
span2.end();
|
|
@@ -6978,7 +7942,7 @@ function googleGenerativeAIStreamWrapper(tracer, spanName, requestType) {
|
|
|
6978
7942
|
duration
|
|
6979
7943
|
);
|
|
6980
7944
|
} catch (e) {
|
|
6981
|
-
Logger.error(`${
|
|
7945
|
+
Logger.error(`${LOG_PREFIX5}:`, e);
|
|
6982
7946
|
}
|
|
6983
7947
|
span2.setStatus({ code: SpanStatusCode.OK });
|
|
6984
7948
|
span2.end();
|
|
@@ -7658,350 +8622,6 @@ var groqInstrumentor = new NetraGroqInstrumentor();
|
|
|
7658
8622
|
// src/instrumentation/langgraph/version.ts
|
|
7659
8623
|
var __version__5 = "1.0.0";
|
|
7660
8624
|
|
|
7661
|
-
// node_modules/@langchain/core/dist/_virtual/rolldown_runtime.js
|
|
7662
|
-
var __defProp = Object.defineProperty;
|
|
7663
|
-
var __export = (target, all) => {
|
|
7664
|
-
for (var name in all) __defProp(target, name, {
|
|
7665
|
-
get: all[name],
|
|
7666
|
-
enumerable: true
|
|
7667
|
-
});
|
|
7668
|
-
};
|
|
7669
|
-
|
|
7670
|
-
// node_modules/@langchain/core/dist/load/map_keys.js
|
|
7671
|
-
var import_decamelize = __toESM(require_decamelize(), 1);
|
|
7672
|
-
__toESM(require_camelcase(), 1);
|
|
7673
|
-
function keyToJson(key, map) {
|
|
7674
|
-
return map?.[key] || (0, import_decamelize.default)(key);
|
|
7675
|
-
}
|
|
7676
|
-
function mapKeys(fields, mapper, map) {
|
|
7677
|
-
const mapped = {};
|
|
7678
|
-
for (const key in fields) if (Object.hasOwn(fields, key)) mapped[mapper(key, map)] = fields[key];
|
|
7679
|
-
return mapped;
|
|
7680
|
-
}
|
|
7681
|
-
|
|
7682
|
-
// node_modules/@langchain/core/dist/load/validation.js
|
|
7683
|
-
var LC_ESCAPED_KEY = "__lc_escaped__";
|
|
7684
|
-
function needsEscaping(obj) {
|
|
7685
|
-
return "lc" in obj || Object.keys(obj).length === 1 && LC_ESCAPED_KEY in obj;
|
|
7686
|
-
}
|
|
7687
|
-
function escapeObject(obj) {
|
|
7688
|
-
return { [LC_ESCAPED_KEY]: obj };
|
|
7689
|
-
}
|
|
7690
|
-
function isSerializableLike(obj) {
|
|
7691
|
-
return obj !== null && typeof obj === "object" && "lc_serializable" in obj && typeof obj.toJSON === "function";
|
|
7692
|
-
}
|
|
7693
|
-
function createNotImplemented(obj) {
|
|
7694
|
-
let id;
|
|
7695
|
-
if (obj !== null && typeof obj === "object") if ("lc_id" in obj && Array.isArray(obj.lc_id)) id = obj.lc_id;
|
|
7696
|
-
else id = [obj.constructor?.name ?? "Object"];
|
|
7697
|
-
else id = [typeof obj];
|
|
7698
|
-
return {
|
|
7699
|
-
lc: 1,
|
|
7700
|
-
type: "not_implemented",
|
|
7701
|
-
id
|
|
7702
|
-
};
|
|
7703
|
-
}
|
|
7704
|
-
function escapeIfNeeded(value, pathSet = /* @__PURE__ */ new WeakSet()) {
|
|
7705
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
7706
|
-
if (pathSet.has(value)) return createNotImplemented(value);
|
|
7707
|
-
if (isSerializableLike(value)) return value;
|
|
7708
|
-
pathSet.add(value);
|
|
7709
|
-
const record = value;
|
|
7710
|
-
if (needsEscaping(record)) {
|
|
7711
|
-
pathSet.delete(value);
|
|
7712
|
-
return escapeObject(record);
|
|
7713
|
-
}
|
|
7714
|
-
const result = {};
|
|
7715
|
-
for (const [key, val] of Object.entries(record)) result[key] = escapeIfNeeded(val, pathSet);
|
|
7716
|
-
pathSet.delete(value);
|
|
7717
|
-
return result;
|
|
7718
|
-
}
|
|
7719
|
-
if (Array.isArray(value)) return value.map((item) => escapeIfNeeded(item, pathSet));
|
|
7720
|
-
return value;
|
|
7721
|
-
}
|
|
7722
|
-
|
|
7723
|
-
// node_modules/@langchain/core/dist/load/serializable.js
|
|
7724
|
-
var serializable_exports = {};
|
|
7725
|
-
__export(serializable_exports, {
|
|
7726
|
-
Serializable: () => Serializable,
|
|
7727
|
-
get_lc_unique_name: () => get_lc_unique_name
|
|
7728
|
-
});
|
|
7729
|
-
function shallowCopy(obj) {
|
|
7730
|
-
return Array.isArray(obj) ? [...obj] : { ...obj };
|
|
7731
|
-
}
|
|
7732
|
-
function replaceSecrets(root, secretsMap) {
|
|
7733
|
-
const result = shallowCopy(root);
|
|
7734
|
-
for (const [path, secretId] of Object.entries(secretsMap)) {
|
|
7735
|
-
const [last, ...partsReverse] = path.split(".").reverse();
|
|
7736
|
-
let current = result;
|
|
7737
|
-
for (const part of partsReverse.reverse()) {
|
|
7738
|
-
if (current[part] === void 0) break;
|
|
7739
|
-
current[part] = shallowCopy(current[part]);
|
|
7740
|
-
current = current[part];
|
|
7741
|
-
}
|
|
7742
|
-
if (current[last] !== void 0) current[last] = {
|
|
7743
|
-
lc: 1,
|
|
7744
|
-
type: "secret",
|
|
7745
|
-
id: [secretId]
|
|
7746
|
-
};
|
|
7747
|
-
}
|
|
7748
|
-
return result;
|
|
7749
|
-
}
|
|
7750
|
-
function get_lc_unique_name(serializableClass) {
|
|
7751
|
-
const parentClass = Object.getPrototypeOf(serializableClass);
|
|
7752
|
-
const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" && (typeof parentClass.lc_name !== "function" || serializableClass.lc_name() !== parentClass.lc_name());
|
|
7753
|
-
if (lcNameIsSubclassed) return serializableClass.lc_name();
|
|
7754
|
-
else return serializableClass.name;
|
|
7755
|
-
}
|
|
7756
|
-
var Serializable = class Serializable2 {
|
|
7757
|
-
constructor(kwargs, ..._args) {
|
|
7758
|
-
__publicField(this, "lc_serializable", false);
|
|
7759
|
-
__publicField(this, "lc_kwargs");
|
|
7760
|
-
if (this.lc_serializable_keys !== void 0) this.lc_kwargs = Object.fromEntries(Object.entries(kwargs || {}).filter(([key]) => this.lc_serializable_keys?.includes(key)));
|
|
7761
|
-
else this.lc_kwargs = kwargs ?? {};
|
|
7762
|
-
}
|
|
7763
|
-
/**
|
|
7764
|
-
* The name of the serializable. Override to provide an alias or
|
|
7765
|
-
* to preserve the serialized module name in minified environments.
|
|
7766
|
-
*
|
|
7767
|
-
* Implemented as a static method to support loading logic.
|
|
7768
|
-
*/
|
|
7769
|
-
static lc_name() {
|
|
7770
|
-
return this.name;
|
|
7771
|
-
}
|
|
7772
|
-
/**
|
|
7773
|
-
* The final serialized identifier for the module.
|
|
7774
|
-
*/
|
|
7775
|
-
get lc_id() {
|
|
7776
|
-
return [...this.lc_namespace, get_lc_unique_name(this.constructor)];
|
|
7777
|
-
}
|
|
7778
|
-
/**
|
|
7779
|
-
* A map of secrets, which will be omitted from serialization.
|
|
7780
|
-
* Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
|
|
7781
|
-
* Values are the secret ids, which will be used when deserializing.
|
|
7782
|
-
*/
|
|
7783
|
-
get lc_secrets() {
|
|
7784
|
-
return void 0;
|
|
7785
|
-
}
|
|
7786
|
-
/**
|
|
7787
|
-
* A map of additional attributes to merge with constructor args.
|
|
7788
|
-
* Keys are the attribute names, e.g. "foo".
|
|
7789
|
-
* Values are the attribute values, which will be serialized.
|
|
7790
|
-
* These attributes need to be accepted by the constructor as arguments.
|
|
7791
|
-
*/
|
|
7792
|
-
get lc_attributes() {
|
|
7793
|
-
return void 0;
|
|
7794
|
-
}
|
|
7795
|
-
/**
|
|
7796
|
-
* A map of aliases for constructor args.
|
|
7797
|
-
* Keys are the attribute names, e.g. "foo".
|
|
7798
|
-
* Values are the alias that will replace the key in serialization.
|
|
7799
|
-
* This is used to eg. make argument names match Python.
|
|
7800
|
-
*/
|
|
7801
|
-
get lc_aliases() {
|
|
7802
|
-
return void 0;
|
|
7803
|
-
}
|
|
7804
|
-
/**
|
|
7805
|
-
* A manual list of keys that should be serialized.
|
|
7806
|
-
* If not overridden, all fields passed into the constructor will be serialized.
|
|
7807
|
-
*/
|
|
7808
|
-
get lc_serializable_keys() {
|
|
7809
|
-
return void 0;
|
|
7810
|
-
}
|
|
7811
|
-
toJSON() {
|
|
7812
|
-
if (!this.lc_serializable) return this.toJSONNotImplemented();
|
|
7813
|
-
if (this.lc_kwargs instanceof Serializable2 || typeof this.lc_kwargs !== "object" || Array.isArray(this.lc_kwargs)) return this.toJSONNotImplemented();
|
|
7814
|
-
const aliases = {};
|
|
7815
|
-
const secrets = {};
|
|
7816
|
-
const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
|
|
7817
|
-
acc[key] = key in this ? this[key] : this.lc_kwargs[key];
|
|
7818
|
-
return acc;
|
|
7819
|
-
}, {});
|
|
7820
|
-
for (let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
|
|
7821
|
-
Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
|
|
7822
|
-
Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
|
|
7823
|
-
Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
|
|
7824
|
-
}
|
|
7825
|
-
Object.keys(secrets).forEach((keyPath) => {
|
|
7826
|
-
let read = this;
|
|
7827
|
-
let write = kwargs;
|
|
7828
|
-
const [last, ...partsReverse] = keyPath.split(".").reverse();
|
|
7829
|
-
for (const key of partsReverse.reverse()) {
|
|
7830
|
-
if (!(key in read) || read[key] === void 0) return;
|
|
7831
|
-
if (!(key in write) || write[key] === void 0) {
|
|
7832
|
-
if (typeof read[key] === "object" && read[key] != null) write[key] = {};
|
|
7833
|
-
else if (Array.isArray(read[key])) write[key] = [];
|
|
7834
|
-
}
|
|
7835
|
-
read = read[key];
|
|
7836
|
-
write = write[key];
|
|
7837
|
-
}
|
|
7838
|
-
if (last in read && read[last] !== void 0) write[last] = write[last] || read[last];
|
|
7839
|
-
});
|
|
7840
|
-
const escapedKwargs = {};
|
|
7841
|
-
const pathSet = /* @__PURE__ */ new WeakSet();
|
|
7842
|
-
pathSet.add(this);
|
|
7843
|
-
for (const [key, value] of Object.entries(kwargs)) escapedKwargs[key] = escapeIfNeeded(value, pathSet);
|
|
7844
|
-
const kwargsWithSecrets = Object.keys(secrets).length ? replaceSecrets(escapedKwargs, secrets) : escapedKwargs;
|
|
7845
|
-
const processedKwargs = mapKeys(kwargsWithSecrets, keyToJson, aliases);
|
|
7846
|
-
return {
|
|
7847
|
-
lc: 1,
|
|
7848
|
-
type: "constructor",
|
|
7849
|
-
id: this.lc_id,
|
|
7850
|
-
kwargs: processedKwargs
|
|
7851
|
-
};
|
|
7852
|
-
}
|
|
7853
|
-
toJSONNotImplemented() {
|
|
7854
|
-
return {
|
|
7855
|
-
lc: 1,
|
|
7856
|
-
type: "not_implemented",
|
|
7857
|
-
id: this.lc_id
|
|
7858
|
-
};
|
|
7859
|
-
}
|
|
7860
|
-
};
|
|
7861
|
-
|
|
7862
|
-
// node_modules/@langchain/core/dist/utils/env.js
|
|
7863
|
-
var env_exports = {};
|
|
7864
|
-
__export(env_exports, {
|
|
7865
|
-
getEnv: () => getEnv,
|
|
7866
|
-
getEnvironmentVariable: () => getEnvironmentVariable,
|
|
7867
|
-
getRuntimeEnvironment: () => getRuntimeEnvironment,
|
|
7868
|
-
isBrowser: () => isBrowser,
|
|
7869
|
-
isDeno: () => isDeno,
|
|
7870
|
-
isJsDom: () => isJsDom,
|
|
7871
|
-
isNode: () => isNode,
|
|
7872
|
-
isWebWorker: () => isWebWorker
|
|
7873
|
-
});
|
|
7874
|
-
var isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
7875
|
-
var isWebWorker = () => typeof globalThis === "object" && globalThis.constructor && globalThis.constructor.name === "DedicatedWorkerGlobalScope";
|
|
7876
|
-
var isJsDom = () => typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom");
|
|
7877
|
-
var isDeno = () => typeof Deno !== "undefined";
|
|
7878
|
-
var isNode = () => typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined" && !isDeno();
|
|
7879
|
-
var getEnv = () => {
|
|
7880
|
-
let env;
|
|
7881
|
-
if (isBrowser()) env = "browser";
|
|
7882
|
-
else if (isNode()) env = "node";
|
|
7883
|
-
else if (isWebWorker()) env = "webworker";
|
|
7884
|
-
else if (isJsDom()) env = "jsdom";
|
|
7885
|
-
else if (isDeno()) env = "deno";
|
|
7886
|
-
else env = "other";
|
|
7887
|
-
return env;
|
|
7888
|
-
};
|
|
7889
|
-
var runtimeEnvironment;
|
|
7890
|
-
function getRuntimeEnvironment() {
|
|
7891
|
-
if (runtimeEnvironment === void 0) {
|
|
7892
|
-
const env = getEnv();
|
|
7893
|
-
runtimeEnvironment = {
|
|
7894
|
-
library: "langchain-js",
|
|
7895
|
-
runtime: env
|
|
7896
|
-
};
|
|
7897
|
-
}
|
|
7898
|
-
return runtimeEnvironment;
|
|
7899
|
-
}
|
|
7900
|
-
function getEnvironmentVariable(name) {
|
|
7901
|
-
try {
|
|
7902
|
-
if (typeof process !== "undefined") return process.env?.[name];
|
|
7903
|
-
else if (isDeno()) return Deno?.env.get(name);
|
|
7904
|
-
else return void 0;
|
|
7905
|
-
} catch {
|
|
7906
|
-
return void 0;
|
|
7907
|
-
}
|
|
7908
|
-
}
|
|
7909
|
-
|
|
7910
|
-
// node_modules/@langchain/core/dist/callbacks/base.js
|
|
7911
|
-
init_esm_node();
|
|
7912
|
-
var base_exports = {};
|
|
7913
|
-
__export(base_exports, {
|
|
7914
|
-
BaseCallbackHandler: () => BaseCallbackHandler,
|
|
7915
|
-
callbackHandlerPrefersStreaming: () => callbackHandlerPrefersStreaming,
|
|
7916
|
-
isBaseCallbackHandler: () => isBaseCallbackHandler
|
|
7917
|
-
});
|
|
7918
|
-
var BaseCallbackHandlerMethodsClass = class {
|
|
7919
|
-
};
|
|
7920
|
-
function callbackHandlerPrefersStreaming(x) {
|
|
7921
|
-
return "lc_prefer_streaming" in x && x.lc_prefer_streaming;
|
|
7922
|
-
}
|
|
7923
|
-
var BaseCallbackHandler = class extends BaseCallbackHandlerMethodsClass {
|
|
7924
|
-
constructor(input) {
|
|
7925
|
-
super();
|
|
7926
|
-
__publicField(this, "lc_serializable", false);
|
|
7927
|
-
__publicField(this, "lc_kwargs");
|
|
7928
|
-
__publicField(this, "ignoreLLM", false);
|
|
7929
|
-
__publicField(this, "ignoreChain", false);
|
|
7930
|
-
__publicField(this, "ignoreAgent", false);
|
|
7931
|
-
__publicField(this, "ignoreRetriever", false);
|
|
7932
|
-
__publicField(this, "ignoreCustomEvent", false);
|
|
7933
|
-
__publicField(this, "raiseError", false);
|
|
7934
|
-
__publicField(this, "awaitHandlers", getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false");
|
|
7935
|
-
this.lc_kwargs = input || {};
|
|
7936
|
-
if (input) {
|
|
7937
|
-
this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
|
|
7938
|
-
this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
|
|
7939
|
-
this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
|
|
7940
|
-
this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
|
|
7941
|
-
this.ignoreCustomEvent = input.ignoreCustomEvent ?? this.ignoreCustomEvent;
|
|
7942
|
-
this.raiseError = input.raiseError ?? this.raiseError;
|
|
7943
|
-
this.awaitHandlers = this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
|
|
7944
|
-
}
|
|
7945
|
-
}
|
|
7946
|
-
get lc_namespace() {
|
|
7947
|
-
return [
|
|
7948
|
-
"langchain_core",
|
|
7949
|
-
"callbacks",
|
|
7950
|
-
this.name
|
|
7951
|
-
];
|
|
7952
|
-
}
|
|
7953
|
-
get lc_secrets() {
|
|
7954
|
-
return void 0;
|
|
7955
|
-
}
|
|
7956
|
-
get lc_attributes() {
|
|
7957
|
-
return void 0;
|
|
7958
|
-
}
|
|
7959
|
-
get lc_aliases() {
|
|
7960
|
-
return void 0;
|
|
7961
|
-
}
|
|
7962
|
-
get lc_serializable_keys() {
|
|
7963
|
-
return void 0;
|
|
7964
|
-
}
|
|
7965
|
-
/**
|
|
7966
|
-
* The name of the serializable. Override to provide an alias or
|
|
7967
|
-
* to preserve the serialized module name in minified environments.
|
|
7968
|
-
*
|
|
7969
|
-
* Implemented as a static method to support loading logic.
|
|
7970
|
-
*/
|
|
7971
|
-
static lc_name() {
|
|
7972
|
-
return this.name;
|
|
7973
|
-
}
|
|
7974
|
-
/**
|
|
7975
|
-
* The final serialized identifier for the module.
|
|
7976
|
-
*/
|
|
7977
|
-
get lc_id() {
|
|
7978
|
-
return [...this.lc_namespace, get_lc_unique_name(this.constructor)];
|
|
7979
|
-
}
|
|
7980
|
-
copy() {
|
|
7981
|
-
return new this.constructor(this);
|
|
7982
|
-
}
|
|
7983
|
-
toJSON() {
|
|
7984
|
-
return Serializable.prototype.toJSON.call(this);
|
|
7985
|
-
}
|
|
7986
|
-
toJSONNotImplemented() {
|
|
7987
|
-
return Serializable.prototype.toJSONNotImplemented.call(this);
|
|
7988
|
-
}
|
|
7989
|
-
static fromMethods(methods) {
|
|
7990
|
-
class Handler extends BaseCallbackHandler {
|
|
7991
|
-
constructor() {
|
|
7992
|
-
super();
|
|
7993
|
-
__publicField(this, "name", v7_default());
|
|
7994
|
-
Object.assign(this, methods);
|
|
7995
|
-
}
|
|
7996
|
-
}
|
|
7997
|
-
return new Handler();
|
|
7998
|
-
}
|
|
7999
|
-
};
|
|
8000
|
-
var isBaseCallbackHandler = (x) => {
|
|
8001
|
-
const callbackHandler = x;
|
|
8002
|
-
return callbackHandler !== void 0 && typeof callbackHandler.copy === "function" && typeof callbackHandler.name === "string" && typeof callbackHandler.awaitHandlers === "boolean";
|
|
8003
|
-
};
|
|
8004
|
-
|
|
8005
8625
|
// src/instrumentation/langgraph/utils.ts
|
|
8006
8626
|
var NetraLanggraphAttributes = {
|
|
8007
8627
|
spanType: "netra.span.type",
|
|
@@ -10117,11 +10737,11 @@ function setGenerationAttributes(span2, data, systemName) {
|
|
|
10117
10737
|
}
|
|
10118
10738
|
const effectiveOutput = unwrapGenerationOutput(data.output);
|
|
10119
10739
|
if (data.usage) {
|
|
10120
|
-
|
|
10740
|
+
setUsageAttributes4(span2, data.usage);
|
|
10121
10741
|
} else if (effectiveOutput && typeof effectiveOutput === "object" && !Array.isArray(effectiveOutput)) {
|
|
10122
10742
|
const respUsage = effectiveOutput.usage;
|
|
10123
10743
|
if (respUsage && typeof respUsage === "object") {
|
|
10124
|
-
|
|
10744
|
+
setUsageAttributes4(span2, respUsage);
|
|
10125
10745
|
}
|
|
10126
10746
|
}
|
|
10127
10747
|
if (data.input !== void 0) {
|
|
@@ -10160,7 +10780,7 @@ function setResponseAttributes8(span2, agentSpan, systemName) {
|
|
|
10160
10780
|
}
|
|
10161
10781
|
const resp = data._response;
|
|
10162
10782
|
if (data.usage && !(resp && typeof resp === "object" && resp.usage)) {
|
|
10163
|
-
|
|
10783
|
+
setUsageAttributes4(span2, data.usage);
|
|
10164
10784
|
}
|
|
10165
10785
|
}
|
|
10166
10786
|
function setFunctionAttributes(span2, data) {
|
|
@@ -10209,7 +10829,7 @@ function setCustomAttributes(span2, data) {
|
|
|
10209
10829
|
span2.setAttribute(NETRA_CUSTOM_DATA, safeStringify(data.data));
|
|
10210
10830
|
}
|
|
10211
10831
|
}
|
|
10212
|
-
function
|
|
10832
|
+
function setUsageAttributes4(span2, usage) {
|
|
10213
10833
|
const promptTokens = usage.input_tokens ?? usage.prompt_tokens;
|
|
10214
10834
|
const completionTokens = usage.output_tokens ?? usage.completion_tokens;
|
|
10215
10835
|
const totalTokens = usage.total_tokens;
|
|
@@ -11774,7 +12394,7 @@ function patchTraceloopLangchainCallbackHandler() {
|
|
|
11774
12394
|
} catch (e) {
|
|
11775
12395
|
Logger.debug("require() for traceloop langchain failed, falling back to import().");
|
|
11776
12396
|
}
|
|
11777
|
-
import('./dist-
|
|
12397
|
+
import('./dist-4UBY6Q6Z.js').then((mod) => {
|
|
11778
12398
|
applyPatch(mod, "import");
|
|
11779
12399
|
}).catch(() => {
|
|
11780
12400
|
});
|
|
@@ -12345,17 +12965,17 @@ var BaseTask = class {
|
|
|
12345
12965
|
};
|
|
12346
12966
|
|
|
12347
12967
|
// src/simulation/utils.ts
|
|
12348
|
-
var
|
|
12968
|
+
var LOG_PREFIX6 = "netra.simulation";
|
|
12349
12969
|
var DEFAULT_FILE_DOWNLOAD_TIMEOUT_S = 30;
|
|
12350
12970
|
var MAX_FILE_DOWNLOAD_WORKERS = 8;
|
|
12351
12971
|
var _cachedFileDownloadTimeoutMs = null;
|
|
12352
12972
|
function validateSimulationInputs(datasetId, task2) {
|
|
12353
12973
|
if (!datasetId) {
|
|
12354
|
-
Logger.error(`${
|
|
12974
|
+
Logger.error(`${LOG_PREFIX6}: dataset_id is required`);
|
|
12355
12975
|
return false;
|
|
12356
12976
|
}
|
|
12357
12977
|
if (!(task2 instanceof BaseTask)) {
|
|
12358
|
-
Logger.error(`${
|
|
12978
|
+
Logger.error(`${LOG_PREFIX6}: task must be a BaseTask instance`);
|
|
12359
12979
|
return false;
|
|
12360
12980
|
}
|
|
12361
12981
|
return true;
|
|
@@ -12372,7 +12992,7 @@ function _getFileDownloadTimeout() {
|
|
|
12372
12992
|
return _cachedFileDownloadTimeoutMs;
|
|
12373
12993
|
}
|
|
12374
12994
|
Logger.warn(
|
|
12375
|
-
`${
|
|
12995
|
+
`${LOG_PREFIX6}: Invalid file download timeout '${envVal}', using default ${DEFAULT_FILE_DOWNLOAD_TIMEOUT_S}s`
|
|
12376
12996
|
);
|
|
12377
12997
|
}
|
|
12378
12998
|
_cachedFileDownloadTimeoutMs = DEFAULT_FILE_DOWNLOAD_TIMEOUT_S * 1e3;
|
|
@@ -12401,7 +13021,7 @@ async function _downloadSingleFile(fileData, timeoutMs, signal) {
|
|
|
12401
13021
|
const status = axios.isAxiosError(error) ? error.response?.status : void 0;
|
|
12402
13022
|
const reason = status ? `HTTP ${status}` : error instanceof Error ? error.message : String(error);
|
|
12403
13023
|
Logger.error(
|
|
12404
|
-
`${
|
|
13024
|
+
`${LOG_PREFIX6}: Failed to download file '${fileData.fileName}': ${reason}`
|
|
12405
13025
|
);
|
|
12406
13026
|
throw new Error(
|
|
12407
13027
|
`Failed to download file '${fileData.fileName}': ${reason}`
|
|
@@ -12418,7 +13038,7 @@ function parseFiles(rawFiles) {
|
|
|
12418
13038
|
const downloadUrl = entry.downloadUrl || "";
|
|
12419
13039
|
if (!fileName || !downloadUrl) {
|
|
12420
13040
|
Logger.warn(
|
|
12421
|
-
`${
|
|
13041
|
+
`${LOG_PREFIX6}: Skipping malformed file attachment (missing fileName or downloadUrl)`
|
|
12422
13042
|
);
|
|
12423
13043
|
continue;
|
|
12424
13044
|
}
|
|
@@ -12462,7 +13082,7 @@ async function executeTask2(task2, message, sessionId, rawFiles, setupContext) {
|
|
|
12462
13082
|
}
|
|
12463
13083
|
|
|
12464
13084
|
// src/simulation/client.ts
|
|
12465
|
-
var
|
|
13085
|
+
var LOG_PREFIX7 = "netra.simulation";
|
|
12466
13086
|
var DEFAULT_TIMEOUT = 1e4;
|
|
12467
13087
|
var SimulationHttpClient = class {
|
|
12468
13088
|
constructor(config) {
|
|
@@ -12475,7 +13095,7 @@ var SimulationHttpClient = class {
|
|
|
12475
13095
|
_createClient(config) {
|
|
12476
13096
|
const endpoint = (config.otlpEndpoint || "").trim();
|
|
12477
13097
|
if (!endpoint) {
|
|
12478
|
-
Logger.error(`${
|
|
13098
|
+
Logger.error(`${LOG_PREFIX7}: NETRA_OTLP_ENDPOINT is required`);
|
|
12479
13099
|
return null;
|
|
12480
13100
|
}
|
|
12481
13101
|
const baseURL = this._resolveBaseUrl(endpoint);
|
|
@@ -12497,7 +13117,7 @@ var SimulationHttpClient = class {
|
|
|
12497
13117
|
);
|
|
12498
13118
|
return instance;
|
|
12499
13119
|
} catch (error) {
|
|
12500
|
-
Logger.error(`${
|
|
13120
|
+
Logger.error(`${LOG_PREFIX7}: Failed to create HTTP client:`, error);
|
|
12501
13121
|
return null;
|
|
12502
13122
|
}
|
|
12503
13123
|
}
|
|
@@ -12532,7 +13152,7 @@ var SimulationHttpClient = class {
|
|
|
12532
13152
|
const timeout = parseFloat(timeoutStr);
|
|
12533
13153
|
if (isNaN(timeout)) {
|
|
12534
13154
|
Logger.warn(
|
|
12535
|
-
`${
|
|
13155
|
+
`${LOG_PREFIX7}: Invalid timeout '${timeoutStr}', using default ${DEFAULT_TIMEOUT}ms`
|
|
12536
13156
|
);
|
|
12537
13157
|
return DEFAULT_TIMEOUT;
|
|
12538
13158
|
}
|
|
@@ -12544,9 +13164,9 @@ var SimulationHttpClient = class {
|
|
|
12544
13164
|
* Used in the two-phase flow so that beforeAll/before hooks can run
|
|
12545
13165
|
* before any LLM spend.
|
|
12546
13166
|
*/
|
|
12547
|
-
async initializeRun(name, datasetId,
|
|
13167
|
+
async initializeRun(name, datasetId, context17, hooksMeta) {
|
|
12548
13168
|
if (!this.client) {
|
|
12549
|
-
Logger.error(`${
|
|
13169
|
+
Logger.error(`${LOG_PREFIX7}: Client not initialized`);
|
|
12550
13170
|
return null;
|
|
12551
13171
|
}
|
|
12552
13172
|
try {
|
|
@@ -12554,7 +13174,7 @@ var SimulationHttpClient = class {
|
|
|
12554
13174
|
const payload = {
|
|
12555
13175
|
name,
|
|
12556
13176
|
datasetId,
|
|
12557
|
-
context:
|
|
13177
|
+
context: context17 || {}
|
|
12558
13178
|
};
|
|
12559
13179
|
if (hooksMeta) {
|
|
12560
13180
|
payload.lifecycleHooks = hooksMeta;
|
|
@@ -12564,7 +13184,7 @@ var SimulationHttpClient = class {
|
|
|
12564
13184
|
const responseData = data.data || {};
|
|
12565
13185
|
const items = responseData.items || [];
|
|
12566
13186
|
if (items.length === 0) {
|
|
12567
|
-
Logger.warn(`${
|
|
13187
|
+
Logger.warn(`${LOG_PREFIX7}: No items returned from initialize_run`);
|
|
12568
13188
|
return null;
|
|
12569
13189
|
}
|
|
12570
13190
|
const runId = responseData.id || "";
|
|
@@ -12577,7 +13197,7 @@ var SimulationHttpClient = class {
|
|
|
12577
13197
|
};
|
|
12578
13198
|
} catch (error) {
|
|
12579
13199
|
const errorMsg = this._extractErrorMessage(error);
|
|
12580
|
-
Logger.error(`${
|
|
13200
|
+
Logger.error(`${LOG_PREFIX7}: Failed to initialize run:`, errorMsg);
|
|
12581
13201
|
return null;
|
|
12582
13202
|
}
|
|
12583
13203
|
}
|
|
@@ -12588,7 +13208,7 @@ var SimulationHttpClient = class {
|
|
|
12588
13208
|
*/
|
|
12589
13209
|
async generateFirstTurn(runId, runItemId) {
|
|
12590
13210
|
if (!this.client) {
|
|
12591
|
-
Logger.error(`${
|
|
13211
|
+
Logger.error(`${LOG_PREFIX7}: Client not initialized`);
|
|
12592
13212
|
return null;
|
|
12593
13213
|
}
|
|
12594
13214
|
try {
|
|
@@ -12606,7 +13226,7 @@ var SimulationHttpClient = class {
|
|
|
12606
13226
|
} catch (error) {
|
|
12607
13227
|
const errorMsg = this._extractErrorMessage(error);
|
|
12608
13228
|
Logger.error(
|
|
12609
|
-
`${
|
|
13229
|
+
`${LOG_PREFIX7}: Failed to generate first turn for item ${runItemId}:`,
|
|
12610
13230
|
errorMsg
|
|
12611
13231
|
);
|
|
12612
13232
|
return null;
|
|
@@ -12617,7 +13237,7 @@ var SimulationHttpClient = class {
|
|
|
12617
13237
|
*/
|
|
12618
13238
|
async triggerConversation(message, turnId, sessionId, traceId) {
|
|
12619
13239
|
if (!this.client) {
|
|
12620
|
-
Logger.error(`${
|
|
13240
|
+
Logger.error(`${LOG_PREFIX7}: Client not initialized`);
|
|
12621
13241
|
return null;
|
|
12622
13242
|
}
|
|
12623
13243
|
try {
|
|
@@ -12640,7 +13260,7 @@ var SimulationHttpClient = class {
|
|
|
12640
13260
|
}
|
|
12641
13261
|
const userMessages = responseData.userMessages || [];
|
|
12642
13262
|
if (userMessages.length === 0) {
|
|
12643
|
-
Logger.warn(`${
|
|
13263
|
+
Logger.warn(`${LOG_PREFIX7}: No user messages in continue response`);
|
|
12644
13264
|
return null;
|
|
12645
13265
|
}
|
|
12646
13266
|
const nextMsg = userMessages[0];
|
|
@@ -12653,7 +13273,7 @@ var SimulationHttpClient = class {
|
|
|
12653
13273
|
};
|
|
12654
13274
|
} catch (error) {
|
|
12655
13275
|
const errorMsg = this._extractErrorMessage(error);
|
|
12656
|
-
Logger.error(`${
|
|
13276
|
+
Logger.error(`${LOG_PREFIX7}: Failed to trigger conversation:`, errorMsg);
|
|
12657
13277
|
return null;
|
|
12658
13278
|
}
|
|
12659
13279
|
}
|
|
@@ -12672,17 +13292,17 @@ var SimulationHttpClient = class {
|
|
|
12672
13292
|
*/
|
|
12673
13293
|
async reportFailure(runId, runItemId, error, status = "failed") {
|
|
12674
13294
|
if (!this.client) {
|
|
12675
|
-
Logger.error(`${
|
|
13295
|
+
Logger.error(`${LOG_PREFIX7}: Client not initialized`);
|
|
12676
13296
|
return;
|
|
12677
13297
|
}
|
|
12678
13298
|
try {
|
|
12679
13299
|
const url = `/evaluations/run/${runId}/item/${runItemId}/status`;
|
|
12680
13300
|
const payload = { status, failureReason: error };
|
|
12681
13301
|
await this.client.patch(url, payload);
|
|
12682
|
-
Logger.info(`${
|
|
13302
|
+
Logger.info(`${LOG_PREFIX7}: Reported failure - ${error}`);
|
|
12683
13303
|
} catch (err) {
|
|
12684
13304
|
const errorMsg = this._extractErrorMessage(err);
|
|
12685
|
-
Logger.error(`${
|
|
13305
|
+
Logger.error(`${LOG_PREFIX7}: Failed to report failure:`, errorMsg);
|
|
12686
13306
|
}
|
|
12687
13307
|
}
|
|
12688
13308
|
/**
|
|
@@ -12691,7 +13311,7 @@ var SimulationHttpClient = class {
|
|
|
12691
13311
|
async postRunStatus(runId, status) {
|
|
12692
13312
|
if (!this.client) {
|
|
12693
13313
|
Logger.error(
|
|
12694
|
-
`${
|
|
13314
|
+
`${LOG_PREFIX7}: Client not initialized; cannot post run status`
|
|
12695
13315
|
);
|
|
12696
13316
|
return { success: false };
|
|
12697
13317
|
}
|
|
@@ -12701,14 +13321,14 @@ var SimulationHttpClient = class {
|
|
|
12701
13321
|
const response = await this.client.post(url, payload);
|
|
12702
13322
|
const data = response.data;
|
|
12703
13323
|
if (data && typeof data === "object" && "data" in data) {
|
|
12704
|
-
Logger.info(`${
|
|
13324
|
+
Logger.info(`${LOG_PREFIX7}: Completed test run successfully`);
|
|
12705
13325
|
return data.data || {};
|
|
12706
13326
|
}
|
|
12707
13327
|
return data;
|
|
12708
13328
|
} catch (error) {
|
|
12709
13329
|
const errorMsg = this._extractErrorMessage(error);
|
|
12710
13330
|
Logger.error(
|
|
12711
|
-
`${
|
|
13331
|
+
`${LOG_PREFIX7}: Failed to post run status for run '${runId}':`,
|
|
12712
13332
|
errorMsg
|
|
12713
13333
|
);
|
|
12714
13334
|
return { success: false };
|
|
@@ -12733,7 +13353,7 @@ var SimulationHttpClient = class {
|
|
|
12733
13353
|
};
|
|
12734
13354
|
|
|
12735
13355
|
// src/simulation/hooks.ts
|
|
12736
|
-
var
|
|
13356
|
+
var LOG_PREFIX8 = "netra.simulation";
|
|
12737
13357
|
function describeHooks(hooks) {
|
|
12738
13358
|
const descFn = (fn) => {
|
|
12739
13359
|
if (!fn) return null;
|
|
@@ -12777,11 +13397,11 @@ function describeHooks(hooks) {
|
|
|
12777
13397
|
}
|
|
12778
13398
|
async function runBeforeAll(hooks) {
|
|
12779
13399
|
if (!hooks?.beforeAll) return null;
|
|
12780
|
-
Logger.info(`${
|
|
13400
|
+
Logger.info(`${LOG_PREFIX8}: running beforeAll hook`);
|
|
12781
13401
|
const result = await hooks.beforeAll();
|
|
12782
13402
|
if (result !== null && result !== void 0 && typeof result !== "object") {
|
|
12783
13403
|
Logger.warn(
|
|
12784
|
-
`${
|
|
13404
|
+
`${LOG_PREFIX8}: beforeAll returned ${typeof result} (expected object or null); ignoring value`
|
|
12785
13405
|
);
|
|
12786
13406
|
return null;
|
|
12787
13407
|
}
|
|
@@ -12790,7 +13410,7 @@ async function runBeforeAll(hooks) {
|
|
|
12790
13410
|
async function runBefore(hooks, datasetItemId, sharedContext) {
|
|
12791
13411
|
if (hooks?.before && datasetItemId in hooks.before) {
|
|
12792
13412
|
Logger.info(
|
|
12793
|
-
`${
|
|
13413
|
+
`${LOG_PREFIX8}: running before hook for datasetItemId=${datasetItemId}`
|
|
12794
13414
|
);
|
|
12795
13415
|
const itemHook = hooks.before[datasetItemId];
|
|
12796
13416
|
const result = await itemHook(sharedContext);
|
|
@@ -12800,7 +13420,7 @@ async function runBefore(hooks, datasetItemId, sharedContext) {
|
|
|
12800
13420
|
Object.assign(base, result);
|
|
12801
13421
|
} else {
|
|
12802
13422
|
Logger.warn(
|
|
12803
|
-
`${
|
|
13423
|
+
`${LOG_PREFIX8}: before hook returned ${typeof result} (expected object or null); ignoring value`
|
|
12804
13424
|
);
|
|
12805
13425
|
}
|
|
12806
13426
|
}
|
|
@@ -12811,7 +13431,7 @@ async function runBefore(hooks, datasetItemId, sharedContext) {
|
|
|
12811
13431
|
async function runBeforeEach(hooks, datasetItemId, sharedContext) {
|
|
12812
13432
|
if (!hooks?.beforeEach) return sharedContext;
|
|
12813
13433
|
Logger.info(
|
|
12814
|
-
`${
|
|
13434
|
+
`${LOG_PREFIX8}: running beforeEach hook for datasetItemId=${datasetItemId}`
|
|
12815
13435
|
);
|
|
12816
13436
|
const result = await hooks.beforeEach(sharedContext);
|
|
12817
13437
|
const base = { ...sharedContext || {} };
|
|
@@ -12820,7 +13440,7 @@ async function runBeforeEach(hooks, datasetItemId, sharedContext) {
|
|
|
12820
13440
|
Object.assign(base, result);
|
|
12821
13441
|
} else {
|
|
12822
13442
|
Logger.warn(
|
|
12823
|
-
`${
|
|
13443
|
+
`${LOG_PREFIX8}: beforeEach hook returned ${typeof result} (expected object or null); ignoring value`
|
|
12824
13444
|
);
|
|
12825
13445
|
}
|
|
12826
13446
|
}
|
|
@@ -12829,7 +13449,7 @@ async function runBeforeEach(hooks, datasetItemId, sharedContext) {
|
|
|
12829
13449
|
async function runAfter(hooks, datasetItemId, itemResult, setupContext) {
|
|
12830
13450
|
if (hooks?.after && datasetItemId in hooks.after) {
|
|
12831
13451
|
Logger.info(
|
|
12832
|
-
`${
|
|
13452
|
+
`${LOG_PREFIX8}: running after hook for datasetItemId=${datasetItemId}`
|
|
12833
13453
|
);
|
|
12834
13454
|
await hooks.after[datasetItemId](itemResult, setupContext);
|
|
12835
13455
|
}
|
|
@@ -12837,18 +13457,18 @@ async function runAfter(hooks, datasetItemId, itemResult, setupContext) {
|
|
|
12837
13457
|
async function runAfterEach(hooks, datasetItemId, itemResult, setupContext) {
|
|
12838
13458
|
if (!hooks?.afterEach) return;
|
|
12839
13459
|
Logger.info(
|
|
12840
|
-
`${
|
|
13460
|
+
`${LOG_PREFIX8}: running afterEach hook for datasetItemId=${datasetItemId}`
|
|
12841
13461
|
);
|
|
12842
13462
|
await hooks.afterEach(itemResult, setupContext);
|
|
12843
13463
|
}
|
|
12844
13464
|
async function runAfterAll(hooks, results, sharedContext) {
|
|
12845
13465
|
if (!hooks?.afterAll) return;
|
|
12846
|
-
Logger.info(`${
|
|
13466
|
+
Logger.info(`${LOG_PREFIX8}: running afterAll hook`);
|
|
12847
13467
|
await hooks.afterAll(results, sharedContext);
|
|
12848
13468
|
}
|
|
12849
13469
|
|
|
12850
13470
|
// src/simulation/api.ts
|
|
12851
|
-
var
|
|
13471
|
+
var LOG_PREFIX9 = "netra.simulation";
|
|
12852
13472
|
var SPAN_NAME = "Netra.Simulation.TestRun";
|
|
12853
13473
|
var Simulation = class {
|
|
12854
13474
|
constructor(config) {
|
|
@@ -12872,7 +13492,7 @@ var Simulation = class {
|
|
|
12872
13492
|
name,
|
|
12873
13493
|
datasetId,
|
|
12874
13494
|
task: task2,
|
|
12875
|
-
context:
|
|
13495
|
+
context: context17,
|
|
12876
13496
|
maxConcurrency = 5,
|
|
12877
13497
|
hooks
|
|
12878
13498
|
} = options;
|
|
@@ -12884,7 +13504,7 @@ var Simulation = class {
|
|
|
12884
13504
|
const initResult = await this._client.initializeRun(
|
|
12885
13505
|
name,
|
|
12886
13506
|
datasetId,
|
|
12887
|
-
|
|
13507
|
+
context17,
|
|
12888
13508
|
hooksMeta && Object.keys(hooksMeta).length > 0 ? hooksMeta : null
|
|
12889
13509
|
);
|
|
12890
13510
|
if (!initResult) {
|
|
@@ -12892,7 +13512,7 @@ var Simulation = class {
|
|
|
12892
13512
|
}
|
|
12893
13513
|
const { runId, items } = initResult;
|
|
12894
13514
|
if (!items || items.length === 0) {
|
|
12895
|
-
Logger.error(`${
|
|
13515
|
+
Logger.error(`${LOG_PREFIX9}: No items returned from initialize_run`);
|
|
12896
13516
|
return null;
|
|
12897
13517
|
}
|
|
12898
13518
|
let interrupted = false;
|
|
@@ -12934,7 +13554,7 @@ var Simulation = class {
|
|
|
12934
13554
|
sharedContext = await runBeforeAll(hooks);
|
|
12935
13555
|
} catch (error) {
|
|
12936
13556
|
const errorMsg = `beforeAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
12937
|
-
Logger.error(`${
|
|
13557
|
+
Logger.error(`${LOG_PREFIX9}: ${errorMsg} \u2014 aborting run (no LLM spent)`);
|
|
12938
13558
|
await this._reportFailures(
|
|
12939
13559
|
runId,
|
|
12940
13560
|
items.map((item) => item.runItemId),
|
|
@@ -12956,7 +13576,7 @@ var Simulation = class {
|
|
|
12956
13576
|
await runAfterAll(hooks, results, null);
|
|
12957
13577
|
} catch (afterAllError) {
|
|
12958
13578
|
const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
|
|
12959
|
-
Logger.error(`${
|
|
13579
|
+
Logger.error(`${LOG_PREFIX9}: ${afterAllMsg}`);
|
|
12960
13580
|
}
|
|
12961
13581
|
await this._client.postRunStatus(runId, "completed");
|
|
12962
13582
|
return results;
|
|
@@ -12979,7 +13599,7 @@ var Simulation = class {
|
|
|
12979
13599
|
setupContexts.set(runItemId, setupContext);
|
|
12980
13600
|
} catch (error) {
|
|
12981
13601
|
const errorMsg = `before hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
12982
|
-
Logger.error(`${
|
|
13602
|
+
Logger.error(`${LOG_PREFIX9}: ${errorMsg} for runItemId=${runItemId}`);
|
|
12983
13603
|
await this._client.reportFailure(runId, runItemId, errorMsg, "prescript_failed");
|
|
12984
13604
|
const itemResult = {
|
|
12985
13605
|
runItemId,
|
|
@@ -12995,7 +13615,7 @@ var Simulation = class {
|
|
|
12995
13615
|
}
|
|
12996
13616
|
const simItem = await this._client.generateFirstTurn(runId, runItemId);
|
|
12997
13617
|
if (!simItem) {
|
|
12998
|
-
Logger.warn(`${
|
|
13618
|
+
Logger.warn(`${LOG_PREFIX9}: Failed to generate first turn for item ${runItemId}, marking failed`);
|
|
12999
13619
|
await this._client.reportFailure(runId, runItemId, "Failed to generate first user message");
|
|
13000
13620
|
const itemResult = {
|
|
13001
13621
|
runItemId,
|
|
@@ -13011,7 +13631,7 @@ var Simulation = class {
|
|
|
13011
13631
|
);
|
|
13012
13632
|
await Promise.all(setupPromises);
|
|
13013
13633
|
if (simulationItems.length === 0) {
|
|
13014
|
-
Logger.error(`${
|
|
13634
|
+
Logger.error(`${LOG_PREFIX9}: All items failed during setup/generation`);
|
|
13015
13635
|
const results = {
|
|
13016
13636
|
success: false,
|
|
13017
13637
|
completed: [],
|
|
@@ -13022,12 +13642,12 @@ var Simulation = class {
|
|
|
13022
13642
|
await runAfterAll(hooks, results, sharedContext);
|
|
13023
13643
|
} catch (afterAllError) {
|
|
13024
13644
|
const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
|
|
13025
|
-
Logger.error(`${
|
|
13645
|
+
Logger.error(`${LOG_PREFIX9}: ${afterAllMsg}`);
|
|
13026
13646
|
}
|
|
13027
13647
|
await this._client.postRunStatus(runId, "completed");
|
|
13028
13648
|
return results;
|
|
13029
13649
|
}
|
|
13030
|
-
Logger.info(`${
|
|
13650
|
+
Logger.info(`${LOG_PREFIX9}: Starting simulation with ${simulationItems.length} items`);
|
|
13031
13651
|
try {
|
|
13032
13652
|
const result = await this._runSimulationAsync(
|
|
13033
13653
|
runId,
|
|
@@ -13040,11 +13660,11 @@ var Simulation = class {
|
|
|
13040
13660
|
failedItems
|
|
13041
13661
|
);
|
|
13042
13662
|
const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
|
|
13043
|
-
Logger.info(`${
|
|
13663
|
+
Logger.info(`${LOG_PREFIX9}: Simulation completed in ${elapsedTime} seconds`);
|
|
13044
13664
|
await this._client.postRunStatus(runId, "completed");
|
|
13045
13665
|
return result;
|
|
13046
13666
|
} catch (error) {
|
|
13047
|
-
Logger.error(`${
|
|
13667
|
+
Logger.error(`${LOG_PREFIX9}: Run simulation failed`);
|
|
13048
13668
|
await this._client.postRunStatus(runId, "failed");
|
|
13049
13669
|
throw error;
|
|
13050
13670
|
}
|
|
@@ -13086,7 +13706,7 @@ var Simulation = class {
|
|
|
13086
13706
|
}
|
|
13087
13707
|
processedCount++;
|
|
13088
13708
|
Logger.info(
|
|
13089
|
-
`${
|
|
13709
|
+
`${LOG_PREFIX9}: ${processedCount}/${runItems.length} processed (run_item_id=${runItem.runItemId})`
|
|
13090
13710
|
);
|
|
13091
13711
|
return result;
|
|
13092
13712
|
})
|
|
@@ -13097,7 +13717,7 @@ var Simulation = class {
|
|
|
13097
13717
|
await runAfterAll(hooks, results, sharedContext);
|
|
13098
13718
|
} catch (error) {
|
|
13099
13719
|
const errorMsg = `afterAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
13100
|
-
Logger.error(`${
|
|
13720
|
+
Logger.error(`${LOG_PREFIX9}: ${errorMsg}`);
|
|
13101
13721
|
const completed = results.completed;
|
|
13102
13722
|
const successfulIds = completed.map((item) => item.runItemId);
|
|
13103
13723
|
await this._reportFailures(
|
|
@@ -13117,7 +13737,7 @@ var Simulation = class {
|
|
|
13117
13737
|
}
|
|
13118
13738
|
results.success = results.failed.length === 0;
|
|
13119
13739
|
Logger.info(
|
|
13120
|
-
`${
|
|
13740
|
+
`${LOG_PREFIX9}: Completed=${results.completed.length}, Failed=${results.failed.length}`
|
|
13121
13741
|
);
|
|
13122
13742
|
return results;
|
|
13123
13743
|
}
|
|
@@ -13148,14 +13768,14 @@ var Simulation = class {
|
|
|
13148
13768
|
await runAfter(hooks, datasetItemId, itemResult, setupContext);
|
|
13149
13769
|
} catch (error) {
|
|
13150
13770
|
const errorMsg = `after hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
13151
|
-
Logger.error(`${
|
|
13771
|
+
Logger.error(`${LOG_PREFIX9}: ${errorMsg} for runItemId=${runItemId}`);
|
|
13152
13772
|
errors.push(errorMsg);
|
|
13153
13773
|
}
|
|
13154
13774
|
try {
|
|
13155
13775
|
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
13156
13776
|
} catch (error) {
|
|
13157
13777
|
const errorMsg = `afterEach hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
13158
|
-
Logger.error(`${
|
|
13778
|
+
Logger.error(`${LOG_PREFIX9}: ${errorMsg} for runItemId=${runItemId}`);
|
|
13159
13779
|
errors.push(errorMsg);
|
|
13160
13780
|
}
|
|
13161
13781
|
if (errors.length > 0 && itemResult.success) {
|
|
@@ -13188,7 +13808,7 @@ var Simulation = class {
|
|
|
13188
13808
|
const span2 = new SpanWrapper(
|
|
13189
13809
|
SPAN_NAME,
|
|
13190
13810
|
{ [Config.TRACE_ORIGIN_KEY]: Config.TRACE_ORIGIN_EVALUATION },
|
|
13191
|
-
|
|
13811
|
+
LOG_PREFIX9
|
|
13192
13812
|
);
|
|
13193
13813
|
span2.start();
|
|
13194
13814
|
try {
|
|
@@ -13219,7 +13839,7 @@ var Simulation = class {
|
|
|
13219
13839
|
}
|
|
13220
13840
|
if (response.decision === "stop") {
|
|
13221
13841
|
Logger.info(
|
|
13222
|
-
`${
|
|
13842
|
+
`${LOG_PREFIX9}: Completed run_item_id=${runItemId} reason=${response.reason}`
|
|
13223
13843
|
);
|
|
13224
13844
|
const itemResult = {
|
|
13225
13845
|
runItemId,
|
|
@@ -13235,7 +13855,7 @@ var Simulation = class {
|
|
|
13235
13855
|
} catch (error) {
|
|
13236
13856
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
13237
13857
|
Logger.error(
|
|
13238
|
-
`${
|
|
13858
|
+
`${LOG_PREFIX9}: Task failed run_item_id=${runItemId}, turn_id=${turnId}: ${errorMsg}`
|
|
13239
13859
|
);
|
|
13240
13860
|
await this._client.reportFailure(runId, runItemId, errorMsg);
|
|
13241
13861
|
const itemResult = {
|
|
@@ -13252,7 +13872,7 @@ var Simulation = class {
|
|
|
13252
13872
|
}
|
|
13253
13873
|
}
|
|
13254
13874
|
};
|
|
13255
|
-
var
|
|
13875
|
+
var Tracer19 = class {
|
|
13256
13876
|
constructor(cfg, effectiveProvider) {
|
|
13257
13877
|
if (effectiveProvider && typeof effectiveProvider.getTracer === "function") {
|
|
13258
13878
|
this.tracer = effectiveProvider.getTracer(Config.LIBRARY_NAME, Config.LIBRARY_VERSION);
|
|
@@ -13263,8 +13883,8 @@ var Tracer18 = class {
|
|
|
13263
13883
|
};
|
|
13264
13884
|
function spanHasOutput(span2) {
|
|
13265
13885
|
try {
|
|
13266
|
-
for (const
|
|
13267
|
-
const attrs = span2[
|
|
13886
|
+
for (const field3 of ["attributes", "_attributes"]) {
|
|
13887
|
+
const attrs = span2[field3];
|
|
13268
13888
|
if (attrs && typeof attrs === "object" && attrs["output"]) return true;
|
|
13269
13889
|
}
|
|
13270
13890
|
} catch (e) {
|
|
@@ -13467,7 +14087,7 @@ var Netra = class {
|
|
|
13467
14087
|
config.blockInstruments,
|
|
13468
14088
|
config.rootInstruments
|
|
13469
14089
|
);
|
|
13470
|
-
const tracer = new
|
|
14090
|
+
const tracer = new Tracer19(cfg, effectiveProvider);
|
|
13471
14091
|
this._tracer = tracer.tracer;
|
|
13472
14092
|
try {
|
|
13473
14093
|
this.usage = new Usage(cfg);
|