neatlogs 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -66,7 +66,8 @@ __export(index_exports, {
66
66
  trace: () => trace2,
67
67
  traceToolAnthropic: () => traceTool2,
68
68
  traceToolAzureOpenAI: () => traceTool3,
69
- traceToolBedrock: () => traceTool5,
69
+ traceToolBedrock: () => traceTool6,
70
+ traceToolGoogleGenAI: () => traceTool5,
70
71
  traceToolOpenAI: () => traceTool,
71
72
  traceToolVertexAI: () => traceTool4,
72
73
  updatePrompt: () => updatePrompt,
@@ -76,6 +77,8 @@ __export(index_exports, {
76
77
  wrapBedrock: () => wrapBedrock,
77
78
  wrapCallModel: () => wrapCallModel,
78
79
  wrapClaudeAgentSDK: () => wrapClaudeAgentSDK,
80
+ wrapGoogleGenAI: () => wrapGoogleGenAI,
81
+ wrapGoogleGenAIChat: () => wrapGoogleGenAIChat,
79
82
  wrapMastra: () => wrapMastra,
80
83
  wrapOpenAI: () => wrapOpenAI,
81
84
  wrapOpenRouterAgent: () => wrapOpenRouterAgent,
@@ -5820,7 +5823,7 @@ async function removeTag(name, tag) {
5820
5823
  }
5821
5824
 
5822
5825
  // src/version.ts
5823
- var __version__ = "1.1.4";
5826
+ var __version__ = "1.1.5";
5824
5827
 
5825
5828
  // src/init.ts
5826
5829
  var logger13 = getLogger();
@@ -7881,10 +7884,14 @@ function recordError4(span2, err) {
7881
7884
  span2.end();
7882
7885
  }
7883
7886
 
7884
- // src/bedrock.ts
7887
+ // src/google-genai.ts
7885
7888
  var import_api15 = require("@opentelemetry/api");
7886
- var TRACER_NAME7 = "neatlogs.bedrock";
7887
- var PROVIDER3 = "bedrock";
7889
+ var TRACER_NAME7 = "neatlogs.google_genai";
7890
+ var PROVIDER3 = "google";
7891
+ var SYSTEM3 = "google_genai";
7892
+ function wrapGoogleGenAI(client) {
7893
+ return wrapNamespace5(client, []);
7894
+ }
7888
7895
  function traceTool5(name, fn) {
7889
7896
  return async function tracedTool(args) {
7890
7897
  const tracer = getProviderTracer(TRACER_NAME7);
@@ -7914,6 +7921,394 @@ function traceTool5(name, fn) {
7914
7921
  );
7915
7922
  };
7916
7923
  }
7924
+ function wrapNamespace5(target, path3) {
7925
+ return new Proxy(target, {
7926
+ get(obj, prop, receiver) {
7927
+ const value = Reflect.get(obj, prop, receiver);
7928
+ if (typeof prop === "symbol" || String(prop).startsWith("_")) return value;
7929
+ const currentPath = [...path3, String(prop)];
7930
+ const pathStr = currentPath.join(".");
7931
+ if (pathStr === "models.generateContent" && typeof value === "function") {
7932
+ return tracedGenerateContent2(value.bind(obj), false);
7933
+ }
7934
+ if (pathStr === "models.generateContentStream" && typeof value === "function") {
7935
+ return tracedGenerateContent2(value.bind(obj), true);
7936
+ }
7937
+ if (pathStr === "models.embedContent" && typeof value === "function") {
7938
+ return tracedEmbedContent2(value.bind(obj));
7939
+ }
7940
+ if (pathStr === "models.countTokens" && typeof value === "function") {
7941
+ return tracedCountTokens2(value.bind(obj));
7942
+ }
7943
+ if (value && typeof value === "object" && !Array.isArray(value) && isNamespace5(currentPath)) {
7944
+ return wrapNamespace5(value, currentPath);
7945
+ }
7946
+ return value;
7947
+ }
7948
+ });
7949
+ }
7950
+ function isNamespace5(path3) {
7951
+ if (path3.length > 2) return false;
7952
+ return ["models", "chats"].includes(path3[path3.length - 1]);
7953
+ }
7954
+ function wrapGoogleGenAIChat(chat) {
7955
+ const c = chat;
7956
+ if (!c || c._neatlogsGoogleGenAIPatched) return chat;
7957
+ if (typeof c.sendMessage === "function") {
7958
+ const orig = c.sendMessage.bind(c);
7959
+ c.sendMessage = (params, ...rest) => tracedChatSend2(orig, c, params, rest, false);
7960
+ }
7961
+ if (typeof c.sendMessageStream === "function") {
7962
+ const orig = c.sendMessageStream.bind(c);
7963
+ c.sendMessageStream = (params, ...rest) => tracedChatSend2(orig, c, params, rest, true);
7964
+ }
7965
+ try {
7966
+ Object.defineProperty(c, "_neatlogsGoogleGenAIPatched", { value: true, enumerable: false, configurable: true });
7967
+ } catch {
7968
+ c._neatlogsGoogleGenAIPatched = true;
7969
+ }
7970
+ return chat;
7971
+ }
7972
+ function tracedChatSend2(original, chat, params, rest, isStream) {
7973
+ const tracer = getProviderTracer(TRACER_NAME7);
7974
+ const model = chat?.model ?? chat?.modelVersion ?? "";
7975
+ const span2 = tracer.startSpan("google_genai.chat.send_message", {
7976
+ attributes: {
7977
+ "neatlogs.span.kind": "LLM",
7978
+ "neatlogs.llm.provider": PROVIDER3,
7979
+ "neatlogs.llm.system": SYSTEM3,
7980
+ "neatlogs.llm.model_name": model,
7981
+ "neatlogs.llm.is_streaming": isStream
7982
+ }
7983
+ }, import_api15.context.active());
7984
+ const message = params?.message ?? params;
7985
+ span2.setAttribute("neatlogs.llm.input_messages.0.role", "user");
7986
+ span2.setAttribute(
7987
+ "neatlogs.llm.input_messages.0.content",
7988
+ typeof message === "string" ? message : safeStringify7(message)
7989
+ );
7990
+ const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
7991
+ const result = import_api15.context.with(ctx, () => original(params, ...rest));
7992
+ return Promise.resolve(result).then(
7993
+ (response) => {
7994
+ if (isStream) return wrapStream2(response, span2);
7995
+ finalizeResponse2(span2, response);
7996
+ return response;
7997
+ },
7998
+ (err) => {
7999
+ recordError5(span2, err);
8000
+ throw err;
8001
+ }
8002
+ );
8003
+ }
8004
+ function tracedEmbedContent2(original) {
8005
+ return function(opts, ...rest) {
8006
+ const tracer = getProviderTracer(TRACER_NAME7);
8007
+ const span2 = tracer.startSpan("google_genai.models.embed_content", {
8008
+ attributes: {
8009
+ "neatlogs.span.kind": "EMBEDDING",
8010
+ "neatlogs.llm.provider": PROVIDER3,
8011
+ "neatlogs.embedding.model_name": opts?.model ?? "",
8012
+ "neatlogs.embedding.text": safeStringify7(opts?.contents ?? "")
8013
+ }
8014
+ }, import_api15.context.active());
8015
+ const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
8016
+ const result = import_api15.context.with(ctx, () => original(opts, ...rest));
8017
+ return Promise.resolve(result).then(
8018
+ (response) => {
8019
+ const embeddings = response?.embeddings;
8020
+ if (Array.isArray(embeddings)) {
8021
+ span2.setAttribute("neatlogs.embedding.count", embeddings.length);
8022
+ const vals = embeddings[0]?.values;
8023
+ if (Array.isArray(vals)) span2.setAttribute("neatlogs.embedding.dimensions", vals.length);
8024
+ }
8025
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8026
+ span2.end();
8027
+ return response;
8028
+ },
8029
+ (err) => {
8030
+ recordError5(span2, err);
8031
+ throw err;
8032
+ }
8033
+ );
8034
+ };
8035
+ }
8036
+ function tracedCountTokens2(original) {
8037
+ return function(opts, ...rest) {
8038
+ const tracer = getProviderTracer(TRACER_NAME7);
8039
+ const span2 = tracer.startSpan("google_genai.models.count_tokens", {
8040
+ attributes: {
8041
+ "neatlogs.span.kind": "LLM",
8042
+ "neatlogs.llm.provider": PROVIDER3,
8043
+ "neatlogs.llm.task": "count_tokens",
8044
+ "neatlogs.llm.model_name": opts?.model ?? ""
8045
+ }
8046
+ }, import_api15.context.active());
8047
+ const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
8048
+ const result = import_api15.context.with(ctx, () => original(opts, ...rest));
8049
+ return Promise.resolve(result).then(
8050
+ (response) => {
8051
+ if (response?.totalTokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.totalTokens);
8052
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8053
+ span2.end();
8054
+ return response;
8055
+ },
8056
+ (err) => {
8057
+ recordError5(span2, err);
8058
+ throw err;
8059
+ }
8060
+ );
8061
+ };
8062
+ }
8063
+ function tracedGenerateContent2(original, isStream) {
8064
+ return function(opts, ...rest) {
8065
+ const tracer = getProviderTracer(TRACER_NAME7);
8066
+ const model = opts?.model ?? "";
8067
+ const span2 = tracer.startSpan("google_genai.models.generate_content", {
8068
+ attributes: {
8069
+ "neatlogs.span.kind": "LLM",
8070
+ "neatlogs.llm.provider": PROVIDER3,
8071
+ "neatlogs.llm.system": SYSTEM3,
8072
+ "neatlogs.llm.model_name": model,
8073
+ "neatlogs.llm.is_streaming": isStream
8074
+ }
8075
+ }, import_api15.context.active());
8076
+ setInputAttributes2(span2, opts);
8077
+ const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
8078
+ const result = import_api15.context.with(ctx, () => original(opts, ...rest));
8079
+ return Promise.resolve(result).then(
8080
+ (response) => {
8081
+ if (isStream) {
8082
+ return wrapStream2(response, span2);
8083
+ }
8084
+ finalizeResponse2(span2, response);
8085
+ return response;
8086
+ },
8087
+ (err) => {
8088
+ recordError5(span2, err);
8089
+ throw err;
8090
+ }
8091
+ );
8092
+ };
8093
+ }
8094
+ function setInputAttributes2(span2, opts) {
8095
+ let idx = 0;
8096
+ const config = opts?.config;
8097
+ const systemInstruction = config?.systemInstruction ?? config?.system_instruction;
8098
+ if (systemInstruction) {
8099
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, "system");
8100
+ span2.setAttribute(
8101
+ `neatlogs.llm.input_messages.${idx}.content`,
8102
+ typeof systemInstruction === "string" ? systemInstruction : safeStringify7(systemInstruction)
8103
+ );
8104
+ idx++;
8105
+ }
8106
+ const contents = opts?.contents;
8107
+ if (typeof contents === "string") {
8108
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, "user");
8109
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.content`, contents);
8110
+ } else if (Array.isArray(contents)) {
8111
+ for (const item of contents) {
8112
+ if (typeof item === "string") {
8113
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, "user");
8114
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.content`, item);
8115
+ idx++;
8116
+ } else if (item && typeof item === "object") {
8117
+ const role = item.role ?? "user";
8118
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, role);
8119
+ const parts = item.parts ?? [];
8120
+ const textParts = [];
8121
+ for (const part of parts) {
8122
+ if (typeof part === "string") textParts.push(part);
8123
+ else if (part?.text) textParts.push(part.text);
8124
+ }
8125
+ span2.setAttribute(
8126
+ `neatlogs.llm.input_messages.${idx}.content`,
8127
+ textParts.length ? textParts.join("\n") : safeStringify7(parts)
8128
+ );
8129
+ idx++;
8130
+ }
8131
+ }
8132
+ } else if (contents) {
8133
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, "user");
8134
+ span2.setAttribute(`neatlogs.llm.input_messages.${idx}.content`, safeStringify7(contents));
8135
+ }
8136
+ const tools = config?.tools;
8137
+ if (Array.isArray(tools)) {
8138
+ let t = 0;
8139
+ for (const tool of tools) {
8140
+ const decls = tool?.functionDeclarations ?? tool?.function_declarations ?? [];
8141
+ for (const fn of decls) {
8142
+ span2.setAttribute(`neatlogs.llm.tools.${t}.name`, fn?.name ?? "");
8143
+ if (fn?.description) span2.setAttribute(`neatlogs.llm.tools.${t}.description`, fn.description);
8144
+ if (fn?.parameters) span2.setAttribute(`neatlogs.llm.tools.${t}.input_schema`, safeStringify7(fn.parameters));
8145
+ t++;
8146
+ }
8147
+ }
8148
+ }
8149
+ if (config) {
8150
+ if (config.temperature != null) span2.setAttribute("neatlogs.llm.temperature", config.temperature);
8151
+ if (config.topP != null) span2.setAttribute("neatlogs.llm.top_p", config.topP);
8152
+ if (config.topK != null) span2.setAttribute("neatlogs.llm.top_k", config.topK);
8153
+ const maxTokens = config.maxOutputTokens ?? config.max_output_tokens;
8154
+ if (maxTokens != null) span2.setAttribute("neatlogs.llm.max_tokens", maxTokens);
8155
+ const params = {};
8156
+ if (config.temperature != null) params.temperature = config.temperature;
8157
+ if (config.topP != null) params.top_p = config.topP;
8158
+ if (config.topK != null) params.top_k = config.topK;
8159
+ if (maxTokens != null) params.max_tokens = maxTokens;
8160
+ if (config.frequencyPenalty != null) params.frequency_penalty = config.frequencyPenalty;
8161
+ if (config.presencePenalty != null) params.presence_penalty = config.presencePenalty;
8162
+ if (Object.keys(params).length > 0) {
8163
+ span2.setAttribute("neatlogs.llm.invocation_parameters", JSON.stringify(params));
8164
+ }
8165
+ }
8166
+ }
8167
+ function wrapStream2(stream, span2) {
8168
+ const chunks = [];
8169
+ const originalAsyncIterator = stream?.[Symbol.asyncIterator]?.bind(stream);
8170
+ if (!originalAsyncIterator) {
8171
+ finalizeStreamChunks4(span2, chunks);
8172
+ return stream;
8173
+ }
8174
+ const wrapped = Object.create(Object.getPrototypeOf(stream));
8175
+ Object.assign(wrapped, stream);
8176
+ wrapped[Symbol.asyncIterator] = function() {
8177
+ const iterator = originalAsyncIterator();
8178
+ return {
8179
+ async next() {
8180
+ try {
8181
+ const result = await iterator.next();
8182
+ if (result.done) {
8183
+ finalizeStreamChunks4(span2, chunks);
8184
+ return result;
8185
+ }
8186
+ chunks.push(result.value);
8187
+ return result;
8188
+ } catch (err) {
8189
+ recordError5(span2, err);
8190
+ throw err;
8191
+ }
8192
+ },
8193
+ async return(value) {
8194
+ finalizeStreamChunks4(span2, chunks);
8195
+ return iterator.return?.(value) ?? { done: true, value: void 0 };
8196
+ },
8197
+ async throw(err) {
8198
+ recordError5(span2, err);
8199
+ return iterator.throw?.(err) ?? { done: true, value: void 0 };
8200
+ }
8201
+ };
8202
+ };
8203
+ return wrapped;
8204
+ }
8205
+ function finalizeStreamChunks4(span2, chunks) {
8206
+ const textParts = [];
8207
+ let finishReason = "";
8208
+ let usage = null;
8209
+ for (const chunk of chunks) {
8210
+ for (const candidate of chunk?.candidates ?? []) {
8211
+ for (const part of candidate?.content?.parts ?? []) {
8212
+ if (part?.text && !part?.thought) textParts.push(part.text);
8213
+ }
8214
+ if (candidate?.finishReason) finishReason = candidate.finishReason;
8215
+ }
8216
+ if (chunk?.usageMetadata) usage = chunk.usageMetadata;
8217
+ }
8218
+ const fullText = textParts.join("");
8219
+ if (fullText) {
8220
+ span2.setAttribute("neatlogs.llm.output_messages.0.role", "assistant");
8221
+ span2.setAttribute("neatlogs.llm.output_messages.0.content", fullText);
8222
+ }
8223
+ if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8224
+ setUsage2(span2, usage);
8225
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8226
+ span2.end();
8227
+ }
8228
+ function finalizeResponse2(span2, response) {
8229
+ const textParts = [];
8230
+ let toolIdx = 0;
8231
+ for (const candidate of response?.candidates ?? []) {
8232
+ for (const part of candidate?.content?.parts ?? []) {
8233
+ if (part?.text && !part?.thought) {
8234
+ textParts.push(part.text);
8235
+ } else if (part?.thought && part?.text) {
8236
+ span2.setAttribute("neatlogs.llm.output_messages.0.thinking", part.text);
8237
+ } else if (part?.functionCall) {
8238
+ const fc = part.functionCall;
8239
+ span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.name`, fc?.name ?? "");
8240
+ span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.arguments`, safeStringify7(fc?.args ?? {}));
8241
+ toolIdx++;
8242
+ }
8243
+ }
8244
+ if (candidate?.finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(candidate.finishReason));
8245
+ }
8246
+ if (textParts.length) {
8247
+ span2.setAttribute("neatlogs.llm.output_messages.0.role", "assistant");
8248
+ span2.setAttribute("neatlogs.llm.output_messages.0.content", textParts.join(""));
8249
+ }
8250
+ setUsage2(span2, response?.usageMetadata);
8251
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8252
+ span2.end();
8253
+ }
8254
+ function setUsage2(span2, usage) {
8255
+ if (!usage) return;
8256
+ if (usage.promptTokenCount != null) span2.setAttribute("neatlogs.llm.token_count.prompt", usage.promptTokenCount);
8257
+ if (usage.candidatesTokenCount != null) span2.setAttribute("neatlogs.llm.token_count.completion", usage.candidatesTokenCount);
8258
+ if (usage.totalTokenCount != null) span2.setAttribute("neatlogs.llm.token_count.total", usage.totalTokenCount);
8259
+ if (usage.cachedContentTokenCount != null) span2.setAttribute("neatlogs.llm.token_count.cache_read", usage.cachedContentTokenCount);
8260
+ if (usage.thoughtsTokenCount != null) span2.setAttribute("neatlogs.llm.token_count.reasoning", usage.thoughtsTokenCount);
8261
+ }
8262
+ function safeStringify7(value) {
8263
+ try {
8264
+ return typeof value === "string" ? value : JSON.stringify(value);
8265
+ } catch {
8266
+ return "";
8267
+ }
8268
+ }
8269
+ function recordError5(span2, err) {
8270
+ if (err instanceof Error) {
8271
+ span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: err.message });
8272
+ span2.recordException(err);
8273
+ } else {
8274
+ span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: String(err) });
8275
+ }
8276
+ span2.end();
8277
+ }
8278
+
8279
+ // src/bedrock.ts
8280
+ var import_api16 = require("@opentelemetry/api");
8281
+ var TRACER_NAME8 = "neatlogs.bedrock";
8282
+ var PROVIDER4 = "bedrock";
8283
+ function traceTool6(name, fn) {
8284
+ return async function tracedTool(args) {
8285
+ const tracer = getProviderTracer(TRACER_NAME8);
8286
+ return tracer.startActiveSpan(
8287
+ `tool.${name}`,
8288
+ {
8289
+ attributes: {
8290
+ "neatlogs.span.kind": "TOOL",
8291
+ "neatlogs.tool.name": name,
8292
+ "input.value": safeStringify8(args)
8293
+ }
8294
+ },
8295
+ import_api16.context.active(),
8296
+ async (span2) => {
8297
+ try {
8298
+ const result = await fn(args);
8299
+ span2.setAttribute("output.value", safeStringify8(result));
8300
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8301
+ return result;
8302
+ } catch (err) {
8303
+ recordError6(span2, err);
8304
+ throw err;
8305
+ } finally {
8306
+ span2.end();
8307
+ }
8308
+ }
8309
+ );
8310
+ };
8311
+ }
7917
8312
  function wrapBedrock(client) {
7918
8313
  const c = client;
7919
8314
  if (c._neatlogsBedrockPatched) return client;
@@ -7948,15 +8343,15 @@ function vendorFromModel(modelId) {
7948
8343
  return vendor || "bedrock";
7949
8344
  }
7950
8345
  function startSpan(name, modelId, isStream) {
7951
- return getProviderTracer(TRACER_NAME7).startSpan(name, {
8346
+ return getProviderTracer(TRACER_NAME8).startSpan(name, {
7952
8347
  attributes: {
7953
8348
  "neatlogs.span.kind": "LLM",
7954
- "neatlogs.llm.provider": PROVIDER3,
8349
+ "neatlogs.llm.provider": PROVIDER4,
7955
8350
  "neatlogs.llm.system": vendorFromModel(modelId),
7956
8351
  "neatlogs.llm.model_name": String(modelId ?? ""),
7957
8352
  "neatlogs.llm.is_streaming": isStream
7958
8353
  }
7959
- }, import_api15.context.active());
8354
+ }, import_api16.context.active());
7960
8355
  }
7961
8356
  function tracedConverse(originalSend, command, input, rest, isStream) {
7962
8357
  const span2 = startSpan(
@@ -7965,8 +8360,8 @@ function tracedConverse(originalSend, command, input, rest, isStream) {
7965
8360
  isStream
7966
8361
  );
7967
8362
  setConverseInput(span2, input);
7968
- const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
7969
- const promise = import_api15.context.with(ctx, () => originalSend(command, ...rest));
8363
+ const ctx = import_api16.trace.setSpan(import_api16.context.active(), span2);
8364
+ const promise = import_api16.context.with(ctx, () => originalSend(command, ...rest));
7970
8365
  return promise.then(
7971
8366
  (response) => {
7972
8367
  if (isStream) {
@@ -7976,7 +8371,7 @@ function tracedConverse(originalSend, command, input, rest, isStream) {
7976
8371
  return response;
7977
8372
  },
7978
8373
  (err) => {
7979
- recordError5(span2, err);
8374
+ recordError6(span2, err);
7980
8375
  throw err;
7981
8376
  }
7982
8377
  );
@@ -8005,19 +8400,19 @@ function setConverseInput(span2, input) {
8005
8400
  const spec = tools[i]?.toolSpec ?? {};
8006
8401
  if (spec.name) span2.setAttribute(`neatlogs.llm.tools.${i}.name`, spec.name);
8007
8402
  if (spec.description) span2.setAttribute(`neatlogs.llm.tools.${i}.description`, spec.description);
8008
- if (spec.inputSchema) span2.setAttribute(`neatlogs.llm.tools.${i}.input_schema`, safeStringify7(spec.inputSchema));
8403
+ if (spec.inputSchema) span2.setAttribute(`neatlogs.llm.tools.${i}.input_schema`, safeStringify8(spec.inputSchema));
8009
8404
  }
8010
8405
  }
8011
8406
  function converseBlocksToText(content) {
8012
8407
  if (typeof content === "string") return content;
8013
- if (!Array.isArray(content)) return safeStringify7(content);
8408
+ if (!Array.isArray(content)) return safeStringify8(content);
8014
8409
  const parts = [];
8015
8410
  for (const block of content) {
8016
8411
  if (block && typeof block === "object") {
8017
8412
  if ("text" in block) parts.push(String(block.text));
8018
- else if ("toolResult" in block) parts.push(safeStringify7(block.toolResult));
8019
- else if ("toolUse" in block) parts.push(safeStringify7(block.toolUse));
8020
- else parts.push(safeStringify7(block));
8413
+ else if ("toolResult" in block) parts.push(safeStringify8(block.toolResult));
8414
+ else if ("toolUse" in block) parts.push(safeStringify8(block.toolUse));
8415
+ else parts.push(safeStringify8(block));
8021
8416
  } else {
8022
8417
  parts.push(String(block));
8023
8418
  }
@@ -8036,7 +8431,7 @@ function finalizeConverse(span2, response) {
8036
8431
  const tu = block.toolUse;
8037
8432
  span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.id`, String(tu?.toolUseId ?? ""));
8038
8433
  span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.name`, String(tu?.name ?? ""));
8039
- span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.arguments`, safeStringify7(tu?.input ?? {}));
8434
+ span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.arguments`, safeStringify8(tu?.input ?? {}));
8040
8435
  toolIdx++;
8041
8436
  }
8042
8437
  }
@@ -8046,7 +8441,7 @@ function finalizeConverse(span2, response) {
8046
8441
  }
8047
8442
  if (response?.stopReason) span2.setAttribute("neatlogs.llm.finish_reason", String(response.stopReason));
8048
8443
  setConverseUsage(span2, response?.usage);
8049
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8444
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8050
8445
  span2.end();
8051
8446
  }
8052
8447
  function setConverseUsage(span2, usage) {
@@ -8060,7 +8455,7 @@ function setConverseUsage(span2, usage) {
8060
8455
  function wrapConverseStream(response, span2) {
8061
8456
  const stream = response?.stream;
8062
8457
  if (!stream || typeof stream[Symbol.asyncIterator] !== "function") {
8063
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8458
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8064
8459
  span2.end();
8065
8460
  return response;
8066
8461
  }
@@ -8099,7 +8494,7 @@ function wrapConverseStream(response, span2) {
8099
8494
  if (ev?.metadata?.usage) usage = ev.metadata.usage;
8100
8495
  return result;
8101
8496
  } catch (err) {
8102
- recordError5(span2, err);
8497
+ recordError6(span2, err);
8103
8498
  throw err;
8104
8499
  }
8105
8500
  },
@@ -8128,7 +8523,7 @@ function finalizeConverseStream(span2, textParts, toolCalls, finishReason, usage
8128
8523
  }
8129
8524
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8130
8525
  setConverseUsage(span2, usage);
8131
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8526
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8132
8527
  span2.end();
8133
8528
  }
8134
8529
  function isEmbeddingModel(modelId) {
@@ -8140,16 +8535,16 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
8140
8535
  const bodyIn = decodeBody(input?.body);
8141
8536
  let span2;
8142
8537
  if (isEmbedding) {
8143
- span2 = getProviderTracer(TRACER_NAME7).startSpan("bedrock.invoke_model", {
8538
+ span2 = getProviderTracer(TRACER_NAME8).startSpan("bedrock.invoke_model", {
8144
8539
  attributes: {
8145
8540
  "neatlogs.span.kind": "EMBEDDING",
8146
- "neatlogs.llm.provider": PROVIDER3,
8541
+ "neatlogs.llm.provider": PROVIDER4,
8147
8542
  "neatlogs.embedding.model_name": String(input?.modelId ?? "")
8148
8543
  }
8149
- }, import_api15.context.active());
8544
+ }, import_api16.context.active());
8150
8545
  const text = bodyIn?.inputText ?? bodyIn?.texts ?? bodyIn?.input_text;
8151
8546
  if (text) {
8152
- span2.setAttribute("neatlogs.embedding.text", typeof text === "string" ? text : safeStringify7(text));
8547
+ span2.setAttribute("neatlogs.embedding.text", typeof text === "string" ? text : safeStringify8(text));
8153
8548
  }
8154
8549
  } else {
8155
8550
  span2 = startSpan(
@@ -8159,8 +8554,8 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
8159
8554
  );
8160
8555
  setInvokeInput(span2, vendor, bodyIn);
8161
8556
  }
8162
- const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
8163
- const promise = import_api15.context.with(ctx, () => originalSend(command, ...rest));
8557
+ const ctx = import_api16.trace.setSpan(import_api16.context.active(), span2);
8558
+ const promise = import_api16.context.with(ctx, () => originalSend(command, ...rest));
8164
8559
  return promise.then(
8165
8560
  (response) => {
8166
8561
  if (isStream) {
@@ -8173,13 +8568,13 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
8173
8568
  finalizeInvoke(span2, vendor, decodeBody(response?.body));
8174
8569
  }
8175
8570
  } catch {
8176
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8571
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8177
8572
  span2.end();
8178
8573
  }
8179
8574
  return response;
8180
8575
  },
8181
8576
  (err) => {
8182
- recordError5(span2, err);
8577
+ recordError6(span2, err);
8183
8578
  throw err;
8184
8579
  }
8185
8580
  );
@@ -8198,7 +8593,7 @@ function finalizeInvokeEmbedding(span2, body) {
8198
8593
  span2.setAttribute("neatlogs.llm.token_count.prompt", body.inputTextTokenCount);
8199
8594
  span2.setAttribute("neatlogs.embedding.token_count", body.inputTextTokenCount);
8200
8595
  }
8201
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8596
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8202
8597
  span2.end();
8203
8598
  }
8204
8599
  function decodeBody(body) {
@@ -8220,7 +8615,7 @@ function setInvokeInput(span2, vendor, body) {
8220
8615
  span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, "system");
8221
8616
  span2.setAttribute(
8222
8617
  `neatlogs.llm.input_messages.${idx}.content`,
8223
- typeof body.system === "string" ? body.system : safeStringify7(body.system)
8618
+ typeof body.system === "string" ? body.system : safeStringify8(body.system)
8224
8619
  );
8225
8620
  idx++;
8226
8621
  }
@@ -8229,7 +8624,7 @@ function setInvokeInput(span2, vendor, body) {
8229
8624
  span2.setAttribute(`neatlogs.llm.input_messages.${idx}.role`, msg?.role ?? "user");
8230
8625
  span2.setAttribute(
8231
8626
  `neatlogs.llm.input_messages.${idx}.content`,
8232
- typeof msg?.content === "string" ? msg.content : safeStringify7(msg?.content)
8627
+ typeof msg?.content === "string" ? msg.content : safeStringify8(msg?.content)
8233
8628
  );
8234
8629
  idx++;
8235
8630
  }
@@ -8264,7 +8659,7 @@ function finalizeInvoke(span2, vendor, body) {
8264
8659
  if (b?.type === "tool_use") {
8265
8660
  span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.id`, String(b.id ?? ""));
8266
8661
  span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.name`, String(b.name ?? ""));
8267
- span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.arguments`, safeStringify7(b.input ?? {}));
8662
+ span2.setAttribute(`neatlogs.llm.tool_calls.${toolIdx}.arguments`, safeStringify8(b.input ?? {}));
8268
8663
  toolIdx++;
8269
8664
  }
8270
8665
  }
@@ -8306,13 +8701,13 @@ function finalizeInvoke(span2, vendor, body) {
8306
8701
  span2.setAttribute("neatlogs.llm.token_count.total", promptTokens + completionTokens);
8307
8702
  }
8308
8703
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8309
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8704
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8310
8705
  span2.end();
8311
8706
  }
8312
8707
  function wrapInvokeStream(response, span2, vendor) {
8313
8708
  const body = response?.body;
8314
8709
  if (!body || typeof body[Symbol.asyncIterator] !== "function") {
8315
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8710
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8316
8711
  span2.end();
8317
8712
  return response;
8318
8713
  }
@@ -8330,7 +8725,7 @@ function wrapInvokeStream(response, span2, vendor) {
8330
8725
  if (promptTokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", promptTokens);
8331
8726
  if (completionTokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", completionTokens);
8332
8727
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8333
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8728
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8334
8729
  span2.end();
8335
8730
  };
8336
8731
  const wrappedBody = {
@@ -8360,7 +8755,7 @@ function wrapInvokeStream(response, span2, vendor) {
8360
8755
  }
8361
8756
  return result;
8362
8757
  } catch (err) {
8363
- recordError5(span2, err);
8758
+ recordError6(span2, err);
8364
8759
  throw err;
8365
8760
  }
8366
8761
  },
@@ -8374,26 +8769,26 @@ function wrapInvokeStream(response, span2, vendor) {
8374
8769
  response.body = wrappedBody;
8375
8770
  return response;
8376
8771
  }
8377
- function safeStringify7(value) {
8772
+ function safeStringify8(value) {
8378
8773
  try {
8379
8774
  return typeof value === "string" ? value : JSON.stringify(value);
8380
8775
  } catch {
8381
8776
  return "";
8382
8777
  }
8383
8778
  }
8384
- function recordError5(span2, err) {
8779
+ function recordError6(span2, err) {
8385
8780
  if (err instanceof Error) {
8386
- span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: err.message });
8781
+ span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: err.message });
8387
8782
  span2.recordException(err);
8388
8783
  } else {
8389
- span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: String(err) });
8784
+ span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: String(err) });
8390
8785
  }
8391
8786
  span2.end();
8392
8787
  }
8393
8788
 
8394
8789
  // src/langchain.ts
8395
- var import_api16 = require("@opentelemetry/api");
8396
- var TRACER_NAME8 = "neatlogs.langchain";
8790
+ var import_api17 = require("@opentelemetry/api");
8791
+ var TRACER_NAME9 = "neatlogs.langchain";
8397
8792
  function langchainHandler(opts) {
8398
8793
  return new NeatlogsCallbackHandler(opts);
8399
8794
  }
@@ -8417,10 +8812,10 @@ var NeatlogsCallbackHandler = class {
8417
8812
  _startCtx(parentRunId, runId, kind) {
8418
8813
  const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8419
8814
  if (parentSpan) {
8420
- return import_api16.trace.setSpan(import_api16.context.active(), parentSpan);
8815
+ return import_api17.trace.setSpan(import_api17.context.active(), parentSpan);
8421
8816
  }
8422
- const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8423
- const { root, ctx } = maybeOpenAutoRoot(tracer, kind, import_api16.context.active());
8817
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8818
+ const { root, ctx } = maybeOpenAutoRoot(tracer, kind, import_api17.context.active());
8424
8819
  if (root) this._autoRoots.set(runId, root);
8425
8820
  return ctx;
8426
8821
  }
@@ -8433,7 +8828,7 @@ var NeatlogsCallbackHandler = class {
8433
8828
  }
8434
8829
  // --- Chain/Graph callbacks ---
8435
8830
  async handleChainStart(serialized, inputs, runId, parentRunId, tags, metadata) {
8436
- const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8831
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8437
8832
  const name = serialized?.name ?? serialized?.id?.at(-1) ?? "chain";
8438
8833
  const parentCtx = this._startCtx(parentRunId, runId, "chain");
8439
8834
  const attrs = {
@@ -8441,7 +8836,7 @@ var NeatlogsCallbackHandler = class {
8441
8836
  "neatlogs.chain.name": name
8442
8837
  };
8443
8838
  if (this._workflowName) attrs["neatlogs.workflow.name"] = this._workflowName;
8444
- if (inputs) attrs["input.value"] = safeStringify8(inputs);
8839
+ if (inputs) attrs["input.value"] = safeStringify9(inputs);
8445
8840
  if (tags?.length) attrs["neatlogs.tags"] = tags.join(",");
8446
8841
  const span2 = tracer.startSpan(`langchain.chain.${name}`, { attributes: attrs }, parentCtx);
8447
8842
  this._spans.set(runId, span2);
@@ -8449,8 +8844,8 @@ var NeatlogsCallbackHandler = class {
8449
8844
  async handleChainEnd(outputs, runId) {
8450
8845
  const span2 = this._spans.get(runId);
8451
8846
  if (!span2) return;
8452
- if (outputs) span2.setAttribute("output.value", safeStringify8(outputs));
8453
- span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8847
+ if (outputs) span2.setAttribute("output.value", safeStringify9(outputs));
8848
+ span2.setStatus({ code: import_api17.SpanStatusCode.OK });
8454
8849
  span2.end();
8455
8850
  this._spans.delete(runId);
8456
8851
  this._endAutoRoot(runId);
@@ -8458,7 +8853,7 @@ var NeatlogsCallbackHandler = class {
8458
8853
  async handleChainError(error, runId) {
8459
8854
  const span2 = this._spans.get(runId);
8460
8855
  if (!span2) return;
8461
- span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8856
+ span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: error.message });
8462
8857
  span2.recordException(error);
8463
8858
  span2.end();
8464
8859
  this._spans.delete(runId);
@@ -8466,7 +8861,7 @@ var NeatlogsCallbackHandler = class {
8466
8861
  }
8467
8862
  // --- LLM callbacks ---
8468
8863
  async handleLLMStart(serialized, prompts, runId, parentRunId, extraParams) {
8469
- const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8864
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8470
8865
  const model = serialized?.kwargs?.model_name ?? serialized?.kwargs?.model ?? serialized?.name ?? "";
8471
8866
  const parentCtx = this._startCtx(parentRunId, runId, "llm");
8472
8867
  const attrs = {
@@ -8488,7 +8883,7 @@ var NeatlogsCallbackHandler = class {
8488
8883
  this._spans.set(runId, span2);
8489
8884
  }
8490
8885
  async handleChatModelStart(serialized, messages, runId, parentRunId, extraParams) {
8491
- const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8886
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8492
8887
  const model = serialized?.kwargs?.model_name ?? serialized?.kwargs?.model ?? serialized?.name ?? "";
8493
8888
  const parentCtx = this._startCtx(parentRunId, runId, "llm");
8494
8889
  const attrs = {
@@ -8500,7 +8895,7 @@ var NeatlogsCallbackHandler = class {
8500
8895
  for (let i = 0; i < flatMessages.length; i++) {
8501
8896
  const msg = flatMessages[i];
8502
8897
  const role = msg?.role ?? msg?._getType?.() ?? msg?.constructor?.name ?? "unknown";
8503
- const content = typeof msg?.content === "string" ? msg.content : safeStringify8(msg?.content);
8898
+ const content = typeof msg?.content === "string" ? msg.content : safeStringify9(msg?.content);
8504
8899
  attrs[`neatlogs.llm.input_messages.${i}.role`] = mapRole(role);
8505
8900
  attrs[`neatlogs.llm.input_messages.${i}.content`] = content;
8506
8901
  }
@@ -8531,7 +8926,7 @@ var NeatlogsCallbackHandler = class {
8531
8926
  const tc = toolCalls[k];
8532
8927
  span2.setAttribute(`neatlogs.llm.tool_calls.${k}.id`, tc.id ?? "");
8533
8928
  span2.setAttribute(`neatlogs.llm.tool_calls.${k}.name`, tc.name ?? tc.function?.name ?? "");
8534
- span2.setAttribute(`neatlogs.llm.tool_calls.${k}.arguments`, tc.args ? safeStringify8(tc.args) : tc.function?.arguments ?? "");
8929
+ span2.setAttribute(`neatlogs.llm.tool_calls.${k}.arguments`, tc.args ? safeStringify9(tc.args) : tc.function?.arguments ?? "");
8535
8930
  }
8536
8931
  }
8537
8932
  }
@@ -8548,7 +8943,7 @@ var NeatlogsCallbackHandler = class {
8548
8943
  span2.setAttribute("neatlogs.llm.token_count.total", usage.totalTokens ?? usage.total_tokens);
8549
8944
  }
8550
8945
  }
8551
- span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8946
+ span2.setStatus({ code: import_api17.SpanStatusCode.OK });
8552
8947
  span2.end();
8553
8948
  this._spans.delete(runId);
8554
8949
  this._endAutoRoot(runId);
@@ -8558,7 +8953,7 @@ var NeatlogsCallbackHandler = class {
8558
8953
  async handleLLMError(error, runId) {
8559
8954
  const span2 = this._spans.get(runId);
8560
8955
  if (!span2) return;
8561
- span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8956
+ span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: error.message });
8562
8957
  span2.recordException(error);
8563
8958
  span2.end();
8564
8959
  this._spans.delete(runId);
@@ -8566,7 +8961,7 @@ var NeatlogsCallbackHandler = class {
8566
8961
  }
8567
8962
  // --- Tool callbacks ---
8568
8963
  async handleToolStart(serialized, input, runId, parentRunId, _tags, _metadata, runName, toolCallId) {
8569
- const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8964
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8570
8965
  const name = serialized?.name || runName || (Array.isArray(serialized?.id) ? serialized.id[serialized.id.length - 1] : void 0) || "tool";
8571
8966
  const parentCtx = this._startCtx(parentRunId, runId, "tool");
8572
8967
  const attrs = {
@@ -8582,7 +8977,7 @@ var NeatlogsCallbackHandler = class {
8582
8977
  const span2 = this._spans.get(runId);
8583
8978
  if (!span2) return;
8584
8979
  span2.setAttribute("output.value", String(output));
8585
- span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8980
+ span2.setStatus({ code: import_api17.SpanStatusCode.OK });
8586
8981
  span2.end();
8587
8982
  this._spans.delete(runId);
8588
8983
  this._endAutoRoot(runId);
@@ -8590,7 +8985,7 @@ var NeatlogsCallbackHandler = class {
8590
8985
  async handleToolError(error, runId) {
8591
8986
  const span2 = this._spans.get(runId);
8592
8987
  if (!span2) return;
8593
- span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8988
+ span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: error.message });
8594
8989
  span2.recordException(error);
8595
8990
  span2.end();
8596
8991
  this._spans.delete(runId);
@@ -8598,7 +8993,7 @@ var NeatlogsCallbackHandler = class {
8598
8993
  }
8599
8994
  // --- Retriever callbacks ---
8600
8995
  async handleRetrieverStart(serialized, query, runId, parentRunId) {
8601
- const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8996
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8602
8997
  const name = serialized?.name ?? "retriever";
8603
8998
  const parentCtx = this._startCtx(parentRunId, runId, "retriever");
8604
8999
  const attrs = {
@@ -8621,7 +9016,7 @@ var NeatlogsCallbackHandler = class {
8621
9016
  }
8622
9017
  }
8623
9018
  }
8624
- span2.setStatus({ code: import_api16.SpanStatusCode.OK });
9019
+ span2.setStatus({ code: import_api17.SpanStatusCode.OK });
8625
9020
  span2.end();
8626
9021
  this._spans.delete(runId);
8627
9022
  this._endAutoRoot(runId);
@@ -8629,7 +9024,7 @@ var NeatlogsCallbackHandler = class {
8629
9024
  async handleRetrieverError(error, runId) {
8630
9025
  const span2 = this._spans.get(runId);
8631
9026
  if (!span2) return;
8632
- span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
9027
+ span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: error.message });
8633
9028
  span2.recordException(error);
8634
9029
  span2.end();
8635
9030
  this._spans.delete(runId);
@@ -8654,7 +9049,7 @@ function mapRole(role) {
8654
9049
  if (r === "tool" || r === "toolmessage") return "tool";
8655
9050
  return role;
8656
9051
  }
8657
- function safeStringify8(value) {
9052
+ function safeStringify9(value) {
8658
9053
  try {
8659
9054
  return typeof value === "string" ? value : JSON.stringify(value);
8660
9055
  } catch {
@@ -8730,7 +9125,7 @@ function setOutput(span2, isTool, out) {
8730
9125
  } else {
8731
9126
  span2.setAttribute("neatlogs.llm.output_messages.0.role", "assistant");
8732
9127
  span2.setAttribute("neatlogs.llm.output_messages.0.content", out);
8733
- span2.setAttribute("neatlogs.llm.output", safeStringify9({ role: "assistant", content: out }));
9128
+ span2.setAttribute("neatlogs.llm.output", safeStringify10({ role: "assistant", content: out }));
8734
9129
  }
8735
9130
  }
8736
9131
  function appendInputMessage(span2, role, content) {
@@ -8741,7 +9136,7 @@ function appendInputMessage(span2, role, content) {
8741
9136
  const existing = span2.__neatlogs_in_msgs ?? [];
8742
9137
  existing.push({ role, content });
8743
9138
  span2.__neatlogs_in_msgs = existing;
8744
- const blob = safeStringify9({ messages: existing });
9139
+ const blob = safeStringify10({ messages: existing });
8745
9140
  span2.setAttribute("input.value", blob);
8746
9141
  span2.setAttribute("neatlogs.llm.input", blob);
8747
9142
  }
@@ -8784,15 +9179,15 @@ function flattenBlocks(val) {
8784
9179
  const o = item;
8785
9180
  if (typeof o.text === "string") out.push(o.text);
8786
9181
  else if (typeof o.content === "string") out.push(o.content);
8787
- else if (o.toolUse) out.push(`${o.toolUse.name ?? "tool"}(${safeStringify9(o.toolUse.input ?? {})})`);
9182
+ else if (o.toolUse) out.push(`${o.toolUse.name ?? "tool"}(${safeStringify10(o.toolUse.input ?? {})})`);
8788
9183
  else if (o.toolResult) out.push(flattenBlocks(o.toolResult.content ?? o.toolResult));
8789
9184
  else if (Array.isArray(o.parts)) out.push(flattenBlocks(o.parts));
8790
9185
  else if (Array.isArray(o.content)) out.push(flattenBlocks(o.content));
8791
- else out.push(safeStringify9(o));
9186
+ else out.push(safeStringify10(o));
8792
9187
  }
8793
9188
  return out.filter(Boolean).join("\n");
8794
9189
  }
8795
- function safeStringify9(value) {
9190
+ function safeStringify10(value) {
8796
9191
  if (typeof value === "string") return value;
8797
9192
  try {
8798
9193
  return JSON.stringify(value) ?? "";
@@ -8802,8 +9197,8 @@ function safeStringify9(value) {
8802
9197
  }
8803
9198
 
8804
9199
  // src/openai-agents.ts
8805
- var import_api17 = require("@opentelemetry/api");
8806
- var TRACER_NAME9 = "neatlogs.openai_agents";
9200
+ var import_api18 = require("@opentelemetry/api");
9201
+ var TRACER_NAME10 = "neatlogs.openai_agents";
8807
9202
  function openaiAgentsProcessor() {
8808
9203
  return new NeatlogsTraceProcessor();
8809
9204
  }
@@ -8812,13 +9207,13 @@ var NeatlogsTraceProcessor = class {
8812
9207
  _startTimes = /* @__PURE__ */ new Map();
8813
9208
  // The @openai/agents SDK passes a Trace object: { traceId, name, groupId, metadata }.
8814
9209
  onTraceStart(traceData) {
8815
- const tracer = import_api17.trace.getTracer(TRACER_NAME9);
9210
+ const tracer = import_api18.trace.getTracer(TRACER_NAME10);
8816
9211
  const attrs = { "neatlogs.span.kind": "WORKFLOW" };
8817
9212
  const workflowName = traceData?.name ?? traceData?.workflow_name;
8818
9213
  if (workflowName) attrs["neatlogs.workflow.name"] = workflowName;
8819
9214
  const traceId = traceData?.traceId ?? traceData?.trace_id;
8820
9215
  if (traceId) attrs["neatlogs.agent.trace_id"] = String(traceId);
8821
- const span2 = tracer.startSpan("openai_agents.trace", { attributes: attrs }, import_api17.context.active());
9216
+ const span2 = tracer.startSpan("openai_agents.trace", { attributes: attrs }, import_api18.context.active());
8822
9217
  const key = String(traceId ?? `trace_${Date.now()}`);
8823
9218
  this._spans.set(key, span2);
8824
9219
  this._startTimes.set(key, Date.now());
@@ -8831,7 +9226,7 @@ var NeatlogsTraceProcessor = class {
8831
9226
  if (startTime) {
8832
9227
  span2.setAttribute("neatlogs.metrics.duration_ms", Date.now() - startTime);
8833
9228
  }
8834
- span2.setStatus({ code: import_api17.SpanStatusCode.OK });
9229
+ span2.setStatus({ code: import_api18.SpanStatusCode.OK });
8835
9230
  span2.end();
8836
9231
  this._spans.delete(key);
8837
9232
  this._startTimes.delete(key);
@@ -8839,13 +9234,13 @@ var NeatlogsTraceProcessor = class {
8839
9234
  // The SDK passes a Span object: { type, spanId, traceId, parentId?, spanData: {...} }.
8840
9235
  // The meaningful payload (type, name, input, output, usage, ...) lives in `spanData`.
8841
9236
  onSpanStart(span2) {
8842
- const tracer = import_api17.trace.getTracer(TRACER_NAME9);
9237
+ const tracer = import_api18.trace.getTracer(TRACER_NAME10);
8843
9238
  const data = span2?.spanData ?? span2 ?? {};
8844
9239
  const spanType = data?.type ?? data?.span_type ?? span2?.type ?? "";
8845
9240
  const spanId = String(span2?.spanId ?? span2?.span_id ?? data?.span_id ?? `span_${Date.now()}`);
8846
9241
  const parentKey = String(span2?.parentId ?? span2?.traceId ?? span2?.trace_id ?? "");
8847
9242
  const parentSpan = this._spans.get(parentKey);
8848
- const parentCtx = parentSpan ? import_api17.trace.setSpan(import_api17.context.active(), parentSpan) : import_api17.context.active();
9243
+ const parentCtx = parentSpan ? import_api18.trace.setSpan(import_api18.context.active(), parentSpan) : import_api18.context.active();
8849
9244
  let otelSpan;
8850
9245
  if (spanType === "agent" || spanType === "agent_run") {
8851
9246
  const agentName = data?.name ?? data?.agent_name ?? "agent";
@@ -8871,7 +9266,7 @@ var NeatlogsTraceProcessor = class {
8871
9266
  const role = typeof msg === "object" ? msg.role ?? "" : "";
8872
9267
  const content = typeof msg === "object" ? msg.content ?? "" : String(msg);
8873
9268
  if (role) attrs[`neatlogs.llm.input_messages.${i}.role`] = role;
8874
- if (content) attrs[`neatlogs.llm.input_messages.${i}.content`] = typeof content === "string" ? content : safeStringify10(content);
9269
+ if (content) attrs[`neatlogs.llm.input_messages.${i}.content`] = typeof content === "string" ? content : safeStringify11(content);
8875
9270
  }
8876
9271
  }
8877
9272
  otelSpan = tracer.startSpan("openai_agents.generation", { attributes: attrs }, parentCtx);
@@ -8883,7 +9278,7 @@ var NeatlogsTraceProcessor = class {
8883
9278
  };
8884
9279
  const toolInput = data?.input ?? data?.arguments;
8885
9280
  if (toolInput !== void 0) {
8886
- attrs["input.value"] = typeof toolInput === "string" ? toolInput : safeStringify10(toolInput);
9281
+ attrs["input.value"] = typeof toolInput === "string" ? toolInput : safeStringify11(toolInput);
8887
9282
  }
8888
9283
  otelSpan = tracer.startSpan(`openai_agents.tool.${toolName}`, { attributes: attrs }, parentCtx);
8889
9284
  } else if (spanType === "handoff") {
@@ -8920,13 +9315,13 @@ var NeatlogsTraceProcessor = class {
8920
9315
  for (let i = 0; i < toolCalls.length; i++) {
8921
9316
  const tc = toolCalls[i];
8922
9317
  otelSpan.setAttribute(`neatlogs.llm.tool_calls.${i}.name`, tc.name ?? "");
8923
- otelSpan.setAttribute(`neatlogs.llm.tool_calls.${i}.arguments`, typeof tc.arguments === "string" ? tc.arguments : safeStringify10(tc.arguments ?? {}));
9318
+ otelSpan.setAttribute(`neatlogs.llm.tool_calls.${i}.arguments`, typeof tc.arguments === "string" ? tc.arguments : safeStringify11(tc.arguments ?? {}));
8924
9319
  if (tc.callId ?? tc.id) otelSpan.setAttribute(`neatlogs.llm.tool_calls.${i}.id`, tc.callId ?? tc.id);
8925
9320
  }
8926
9321
  } else if (outputItems?.content) {
8927
9322
  otelSpan.setAttribute("neatlogs.llm.output_messages.0.role", "assistant");
8928
9323
  const c = outputItems.content;
8929
- otelSpan.setAttribute("neatlogs.llm.output_messages.0.content", typeof c === "string" ? c : safeStringify10(c));
9324
+ otelSpan.setAttribute("neatlogs.llm.output_messages.0.content", typeof c === "string" ? c : safeStringify11(c));
8930
9325
  }
8931
9326
  const usage = data?.usage ?? resp?.usage;
8932
9327
  if (usage) {
@@ -8943,24 +9338,24 @@ var NeatlogsTraceProcessor = class {
8943
9338
  } else if (spanType === "function" || spanType === "tool" || spanType === "tool_call") {
8944
9339
  const output = data?.output ?? data?.result;
8945
9340
  if (output != null) {
8946
- otelSpan.setAttribute("output.value", typeof output === "string" ? output : safeStringify10(output));
9341
+ otelSpan.setAttribute("output.value", typeof output === "string" ? output : safeStringify11(output));
8947
9342
  }
8948
9343
  } else if (spanType === "agent" || spanType === "agent_run") {
8949
9344
  const output = data?.output;
8950
9345
  if (output != null) {
8951
- otelSpan.setAttribute("output.value", typeof output === "string" ? output : safeStringify10(output));
9346
+ otelSpan.setAttribute("output.value", typeof output === "string" ? output : safeStringify11(output));
8952
9347
  }
8953
9348
  }
8954
9349
  const error = data?.error ?? span2?.error;
8955
9350
  if (error) {
8956
9351
  if (error instanceof Error) {
8957
- otelSpan.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: error.message });
9352
+ otelSpan.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: error.message });
8958
9353
  otelSpan.recordException(error);
8959
9354
  } else {
8960
- otelSpan.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: String(error) });
9355
+ otelSpan.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: String(error) });
8961
9356
  }
8962
9357
  } else {
8963
- otelSpan.setStatus({ code: import_api17.SpanStatusCode.OK });
9358
+ otelSpan.setStatus({ code: import_api18.SpanStatusCode.OK });
8964
9359
  }
8965
9360
  if (startTime) {
8966
9361
  otelSpan.setAttribute("neatlogs.llm.metrics.duration_ms", Date.now() - startTime);
@@ -8971,7 +9366,7 @@ var NeatlogsTraceProcessor = class {
8971
9366
  }
8972
9367
  shutdown() {
8973
9368
  for (const [, span2] of this._spans) {
8974
- span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: "Processor shutdown before span completed" });
9369
+ span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: "Processor shutdown before span completed" });
8975
9370
  span2.end();
8976
9371
  }
8977
9372
  this._spans.clear();
@@ -8980,7 +9375,7 @@ var NeatlogsTraceProcessor = class {
8980
9375
  forceFlush() {
8981
9376
  }
8982
9377
  };
8983
- function safeStringify10(value) {
9378
+ function safeStringify11(value) {
8984
9379
  try {
8985
9380
  return typeof value === "string" ? value : JSON.stringify(value);
8986
9381
  } catch {
@@ -8989,8 +9384,8 @@ function safeStringify10(value) {
8989
9384
  }
8990
9385
 
8991
9386
  // src/mastra-wrap.ts
8992
- var import_api18 = require("@opentelemetry/api");
8993
- var TRACER_NAME10 = "neatlogs.mastra";
9387
+ var import_api19 = require("@opentelemetry/api");
9388
+ var TRACER_NAME11 = "neatlogs.mastra";
8994
9389
  var PATCH_FLAG2 = "_neatlogs_patched";
8995
9390
  function wrapMastra(entity) {
8996
9391
  if (!entity || entity[PATCH_FLAG2]) return entity;
@@ -9056,14 +9451,14 @@ function patchAgentMethod(agent, method, streaming) {
9056
9451
  }
9057
9452
  if (streaming) attrs["neatlogs.llm.is_streaming"] = true;
9058
9453
  if (streaming) {
9059
- const tracer = import_api18.trace.getTracer(TRACER_NAME10);
9060
- const span2 = tracer.startSpan(`mastra.agent.${agentName}`, { attributes: attrs }, import_api18.context.active());
9061
- const ctx = import_api18.trace.setSpan(import_api18.context.active(), span2);
9454
+ const tracer = import_api19.trace.getTracer(TRACER_NAME11);
9455
+ const span2 = tracer.startSpan(`mastra.agent.${agentName}`, { attributes: attrs }, import_api19.context.active());
9456
+ const ctx = import_api19.trace.setSpan(import_api19.context.active(), span2);
9062
9457
  try {
9063
- const result = await import_api18.context.with(ctx, () => orig(input, opts));
9458
+ const result = await import_api19.context.with(ctx, () => orig(input, opts));
9064
9459
  return wrapStreamingOutput(result, span2, ctx);
9065
9460
  } catch (err) {
9066
- recordError6(span2, err);
9461
+ recordError7(span2, err);
9067
9462
  span2.end();
9068
9463
  throw err;
9069
9464
  }
@@ -9106,7 +9501,7 @@ function patchModelInPlace(model) {
9106
9501
  if (provider) attrs["neatlogs.llm.provider"] = provider;
9107
9502
  if (isStream) attrs["neatlogs.llm.is_streaming"] = true;
9108
9503
  const promptInput = callOpts?.prompt ?? callOpts?.messages;
9109
- if (promptInput !== void 0) attrs["input.value"] = safeStringify11(promptInput);
9504
+ if (promptInput !== void 0) attrs["input.value"] = safeStringify12(promptInput);
9110
9505
  captureInvocationParams(attrs, callOpts);
9111
9506
  return withActiveSpan(`mastra.llm.${modelId || "model"}.${fn}`, attrs, async (span2) => {
9112
9507
  const result = await orig(callOpts);
@@ -9140,12 +9535,12 @@ function patchToolExecute(tool, key) {
9140
9535
  const attrs = {
9141
9536
  "neatlogs.span.kind": "TOOL",
9142
9537
  "neatlogs.tool.name": toolName,
9143
- "input.value": safeStringify11(params)
9538
+ "input.value": safeStringify12(params)
9144
9539
  };
9145
9540
  if (tool.description) attrs["neatlogs.tool.description"] = String(tool.description);
9146
9541
  return withActiveSpan(`mastra.tool.${toolName}`, attrs, async (span2) => {
9147
9542
  const result = await orig(params, options);
9148
- span2.setAttribute("output.value", safeStringify11(result));
9543
+ span2.setAttribute("output.value", safeStringify12(result));
9149
9544
  return result;
9150
9545
  });
9151
9546
  };
@@ -9171,13 +9566,13 @@ function patchRunMethod(run, method, workflowName) {
9171
9566
  "neatlogs.workflow.name": workflowName
9172
9567
  };
9173
9568
  if (startOpts?.inputData !== void 0) {
9174
- attrs["input.value"] = safeStringify11(startOpts.inputData);
9569
+ attrs["input.value"] = safeStringify12(startOpts.inputData);
9175
9570
  }
9176
9571
  return withActiveSpan(`mastra.workflow.${workflowName}`, attrs, async (span2) => {
9177
9572
  const result = await orig(startOpts);
9178
- if (result?.status) span2.setAttribute("neatlogs.metadata", safeStringify11({ status: result.status }));
9573
+ if (result?.status) span2.setAttribute("neatlogs.metadata", safeStringify12({ status: result.status }));
9179
9574
  if (result?.result !== void 0) {
9180
- span2.setAttribute("output.value", safeStringify11(result.result));
9575
+ span2.setAttribute("output.value", safeStringify12(result.result));
9181
9576
  }
9182
9577
  return result;
9183
9578
  });
@@ -9198,14 +9593,14 @@ function patchVectorOp(vector, op, kind) {
9198
9593
  "neatlogs.span.kind": kind,
9199
9594
  "neatlogs.db.system": dbName,
9200
9595
  "neatlogs.db.operation": op,
9201
- "input.value": safeStringify11(params)
9596
+ "input.value": safeStringify12(params)
9202
9597
  };
9203
9598
  const indexName = params?.indexName;
9204
9599
  if (indexName) attrs["neatlogs.vectordb.index_name"] = String(indexName);
9205
9600
  if (kind === "RETRIEVER" && params?.topK != null) attrs["neatlogs.retriever.top_k"] = params.topK;
9206
9601
  return withActiveSpan(`mastra.vector.${op}`, attrs, async (span2) => {
9207
9602
  const result = await orig(params);
9208
- span2.setAttribute("output.value", safeStringify11(result));
9603
+ span2.setAttribute("output.value", safeStringify12(result));
9209
9604
  return result;
9210
9605
  });
9211
9606
  };
@@ -9219,11 +9614,11 @@ function patchMemory(memory) {
9219
9614
  const attrs = {
9220
9615
  "neatlogs.span.kind": "CHAIN",
9221
9616
  "neatlogs.db.operation": op,
9222
- "input.value": safeStringify11(args?.[0])
9617
+ "input.value": safeStringify12(args?.[0])
9223
9618
  };
9224
9619
  return withActiveSpan(`mastra.memory.${op}`, attrs, async (span2) => {
9225
9620
  const result = await orig(...args);
9226
- span2.setAttribute("output.value", safeStringify11(result));
9621
+ span2.setAttribute("output.value", safeStringify12(result));
9227
9622
  return result;
9228
9623
  });
9229
9624
  };
@@ -9264,7 +9659,7 @@ function wrapRootMastra(mastra) {
9264
9659
  }
9265
9660
  function wrapStreamingOutput(output, span2, ctx) {
9266
9661
  if (!output) {
9267
- span2.setStatus({ code: import_api18.SpanStatusCode.OK });
9662
+ span2.setStatus({ code: import_api19.SpanStatusCode.OK });
9268
9663
  span2.end();
9269
9664
  return output;
9270
9665
  }
@@ -9272,8 +9667,8 @@ function wrapStreamingOutput(output, span2, ctx) {
9272
9667
  const endOnce = (err) => {
9273
9668
  if (ended) return;
9274
9669
  ended = true;
9275
- if (err) recordError6(span2, err);
9276
- else span2.setStatus({ code: import_api18.SpanStatusCode.OK });
9670
+ if (err) recordError7(span2, err);
9671
+ else span2.setStatus({ code: import_api19.SpanStatusCode.OK });
9277
9672
  span2.end();
9278
9673
  };
9279
9674
  if (output.text && typeof output.text.then === "function") {
@@ -9364,7 +9759,7 @@ function rebindStreamContext(output, ctx) {
9364
9759
  const origIterator = value[Symbol.asyncIterator].bind(value);
9365
9760
  return {
9366
9761
  [Symbol.asyncIterator]() {
9367
- return import_api18.context.with(ctx, () => origIterator());
9762
+ return import_api19.context.with(ctx, () => origIterator());
9368
9763
  }
9369
9764
  };
9370
9765
  }
@@ -9406,7 +9801,7 @@ function finalizeModelResult(span2, result) {
9406
9801
  const tc = toolCalls[i];
9407
9802
  setToolCall(span2, i, tc.toolName, tc.input ?? tc.args, tc.toolCallId);
9408
9803
  }
9409
- span2.setAttribute("output.value", safeStringify11(result.content));
9804
+ span2.setAttribute("output.value", safeStringify12(result.content));
9410
9805
  }
9411
9806
  if (result.usage) recordUsage(span2, result.usage);
9412
9807
  span2.setAttribute("neatlogs.llm.stop_reason", normalizeFinishReason(result.finishReason));
@@ -9414,7 +9809,7 @@ function finalizeModelResult(span2, result) {
9414
9809
  function normalizeFinishReason(fr) {
9415
9810
  if (fr == null) return "";
9416
9811
  if (typeof fr === "string") return fr;
9417
- return String(fr.unified ?? fr.reason ?? fr.type ?? safeStringify11(fr));
9812
+ return String(fr.unified ?? fr.reason ?? fr.type ?? safeStringify12(fr));
9418
9813
  }
9419
9814
  function tokenValue(v) {
9420
9815
  if (v == null) return void 0;
@@ -9443,22 +9838,22 @@ function captureInvocationParams(attrs, callOpts) {
9443
9838
  }
9444
9839
  }
9445
9840
  if (Array.isArray(callOpts.stopSequences) && callOpts.stopSequences.length) {
9446
- attrs["neatlogs.llm.stop_sequences"] = safeStringify11(callOpts.stopSequences);
9841
+ attrs["neatlogs.llm.stop_sequences"] = safeStringify12(callOpts.stopSequences);
9447
9842
  invocation.stopSequences = callOpts.stopSequences;
9448
9843
  }
9449
9844
  if (Array.isArray(callOpts.tools)) {
9450
9845
  for (let i = 0; i < callOpts.tools.length; i++) {
9451
- attrs[`neatlogs.llm.tools.${i}`] = safeStringify11(callOpts.tools[i]);
9846
+ attrs[`neatlogs.llm.tools.${i}`] = safeStringify12(callOpts.tools[i]);
9452
9847
  }
9453
9848
  invocation.toolChoice = callOpts.toolChoice;
9454
9849
  }
9455
9850
  if (Object.keys(invocation).length) {
9456
- attrs["neatlogs.llm.invocation_parameters"] = safeStringify11(invocation);
9851
+ attrs["neatlogs.llm.invocation_parameters"] = safeStringify12(invocation);
9457
9852
  }
9458
9853
  }
9459
9854
  function setToolCall(span2, i, name, args, id) {
9460
9855
  span2.setAttribute(`neatlogs.llm.tool_calls.${i}.name`, name ?? "");
9461
- span2.setAttribute(`neatlogs.llm.tool_calls.${i}.arguments`, safeStringify11(args ?? {}));
9856
+ span2.setAttribute(`neatlogs.llm.tool_calls.${i}.arguments`, safeStringify12(args ?? {}));
9462
9857
  if (id) span2.setAttribute(`neatlogs.llm.tool_calls.${i}.id`, id);
9463
9858
  }
9464
9859
  function recordUsage(span2, usage) {
@@ -9474,16 +9869,16 @@ function recordUsage(span2, usage) {
9474
9869
  }
9475
9870
  }
9476
9871
  function withActiveSpan(name, attrs, fn) {
9477
- const tracer = import_api18.trace.getTracer(TRACER_NAME10);
9478
- const span2 = tracer.startSpan(name, { attributes: attrs }, import_api18.context.active());
9479
- const ctx = import_api18.trace.setSpan(import_api18.context.active(), span2);
9480
- return import_api18.context.with(ctx, async () => {
9872
+ const tracer = import_api19.trace.getTracer(TRACER_NAME11);
9873
+ const span2 = tracer.startSpan(name, { attributes: attrs }, import_api19.context.active());
9874
+ const ctx = import_api19.trace.setSpan(import_api19.context.active(), span2);
9875
+ return import_api19.context.with(ctx, async () => {
9481
9876
  try {
9482
9877
  const result = await fn(span2);
9483
- span2.setStatus({ code: import_api18.SpanStatusCode.OK });
9878
+ span2.setStatus({ code: import_api19.SpanStatusCode.OK });
9484
9879
  return result;
9485
9880
  } catch (err) {
9486
- recordError6(span2, err);
9881
+ recordError7(span2, err);
9487
9882
  throw err;
9488
9883
  } finally {
9489
9884
  span2.end();
@@ -9503,9 +9898,9 @@ function extractModelId(model) {
9503
9898
  return model.modelId ?? model.name ?? "";
9504
9899
  }
9505
9900
  function toInputValue(input) {
9506
- return typeof input === "string" ? input : safeStringify11(input);
9901
+ return typeof input === "string" ? input : safeStringify12(input);
9507
9902
  }
9508
- function safeStringify11(value) {
9903
+ function safeStringify12(value) {
9509
9904
  if (typeof value === "string") return value;
9510
9905
  try {
9511
9906
  return JSON.stringify(value) ?? "";
@@ -9513,25 +9908,25 @@ function safeStringify11(value) {
9513
9908
  return "";
9514
9909
  }
9515
9910
  }
9516
- function recordError6(span2, err) {
9911
+ function recordError7(span2, err) {
9517
9912
  if (err instanceof Error) {
9518
- span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: err.message });
9913
+ span2.setStatus({ code: import_api19.SpanStatusCode.ERROR, message: err.message });
9519
9914
  span2.recordException(err);
9520
9915
  } else {
9521
- span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: String(err) });
9916
+ span2.setStatus({ code: import_api19.SpanStatusCode.ERROR, message: String(err) });
9522
9917
  }
9523
9918
  }
9524
9919
 
9525
9920
  // src/pi-agent.ts
9526
- var import_api19 = require("@opentelemetry/api");
9527
- var TRACER_NAME11 = "neatlogs.pi-agent";
9921
+ var import_api20 = require("@opentelemetry/api");
9922
+ var TRACER_NAME12 = "neatlogs.pi-agent";
9528
9923
  var PATCH_FLAG3 = "_neatlogs_patched";
9529
9924
  function piAgentHooks(agent) {
9530
9925
  if (!agent || agent[PATCH_FLAG3]) return agent;
9531
9926
  const a = agent;
9532
9927
  if (typeof a.subscribe !== "function") return agent;
9533
9928
  const state = { toolSpans: /* @__PURE__ */ new Map(), inputMessages: [] };
9534
- const tracer = import_api19.trace.getTracer(TRACER_NAME11);
9929
+ const tracer = import_api20.trace.getTracer(TRACER_NAME12);
9535
9930
  a.subscribe((event) => {
9536
9931
  try {
9537
9932
  handleEvent(tracer, state, event);
@@ -9547,10 +9942,10 @@ function handleEvent(tracer, state, event) {
9547
9942
  const span2 = tracer.startSpan(
9548
9943
  "pi_agent.run",
9549
9944
  { attributes: { "neatlogs.span.kind": "AGENT" } },
9550
- import_api19.context.active()
9945
+ import_api20.context.active()
9551
9946
  );
9552
9947
  state.agentSpan = span2;
9553
- state.agentCtx = import_api19.trace.setSpan(import_api19.context.active(), span2);
9948
+ state.agentCtx = import_api20.trace.setSpan(import_api20.context.active(), span2);
9554
9949
  state.inputMessages = [];
9555
9950
  break;
9556
9951
  }
@@ -9569,14 +9964,14 @@ function handleEvent(tracer, state, event) {
9569
9964
  break;
9570
9965
  }
9571
9966
  case "tool_execution_start": {
9572
- const parent = state.agentCtx ?? import_api19.context.active();
9967
+ const parent = state.agentCtx ?? import_api20.context.active();
9573
9968
  const span2 = tracer.startSpan(
9574
9969
  `pi_agent.tool.${event.toolName ?? "tool"}`,
9575
9970
  {
9576
9971
  attributes: {
9577
9972
  "neatlogs.span.kind": "TOOL",
9578
9973
  ...event.toolName ? { "neatlogs.tool.name": String(event.toolName) } : {},
9579
- ...event.args !== void 0 ? { "input.value": safeStringify12(event.args) } : {}
9974
+ ...event.args !== void 0 ? { "input.value": safeStringify13(event.args) } : {}
9580
9975
  }
9581
9976
  },
9582
9977
  parent
@@ -9588,13 +9983,13 @@ function handleEvent(tracer, state, event) {
9588
9983
  const span2 = event.toolCallId ? state.toolSpans.get(event.toolCallId) : void 0;
9589
9984
  if (!span2) return;
9590
9985
  if (event.result !== void 0) {
9591
- span2.setAttribute("output.value", safeStringify12(event.result));
9986
+ span2.setAttribute("output.value", safeStringify13(event.result));
9592
9987
  }
9593
9988
  if (event.isError) {
9594
- span2.setStatus({ code: import_api19.SpanStatusCode.ERROR });
9989
+ span2.setStatus({ code: import_api20.SpanStatusCode.ERROR });
9595
9990
  span2.setAttribute("neatlogs.tool.is_error", true);
9596
9991
  } else {
9597
- span2.setStatus({ code: import_api19.SpanStatusCode.OK });
9992
+ span2.setStatus({ code: import_api20.SpanStatusCode.OK });
9598
9993
  }
9599
9994
  span2.end();
9600
9995
  if (event.toolCallId) state.toolSpans.delete(event.toolCallId);
@@ -9613,7 +10008,7 @@ function handleEvent(tracer, state, event) {
9613
10008
  if (firstUser) state.agentSpan.setAttribute("input.value", firstUser.content);
9614
10009
  const finalText = lastAssistantText(event.messages);
9615
10010
  if (finalText) state.agentSpan.setAttribute("output.value", finalText);
9616
- state.agentSpan.setStatus({ code: import_api19.SpanStatusCode.OK });
10011
+ state.agentSpan.setStatus({ code: import_api20.SpanStatusCode.OK });
9617
10012
  state.agentSpan.end();
9618
10013
  state.agentSpan = void 0;
9619
10014
  state.agentCtx = void 0;
@@ -9635,11 +10030,11 @@ function emitLlmSpan(tracer, state, msg) {
9635
10030
  attrs[`neatlogs.llm.input_messages.${i}.role`] = m.role;
9636
10031
  attrs[`neatlogs.llm.input_messages.${i}.content`] = m.content;
9637
10032
  });
9638
- attrs["neatlogs.llm.input"] = safeStringify12({ messages: inMsgs });
9639
- attrs["input.value"] = safeStringify12({ messages: inMsgs });
10033
+ attrs["neatlogs.llm.input"] = safeStringify13({ messages: inMsgs });
10034
+ attrs["input.value"] = safeStringify13({ messages: inMsgs });
9640
10035
  }
9641
10036
  const { text, toolCalls } = splitAssistantContent(msg.content);
9642
- const outText = text || toolCalls.map((tc) => `${tc.name}(${safeStringify12(tc.arguments)})`).join("\n");
10037
+ const outText = text || toolCalls.map((tc) => `${tc.name}(${safeStringify13(tc.arguments)})`).join("\n");
9643
10038
  if (outText || toolCalls.length) {
9644
10039
  attrs["neatlogs.llm.output_messages.0.role"] = "assistant";
9645
10040
  attrs["neatlogs.llm.output_messages.0.content"] = outText || "";
@@ -9649,11 +10044,11 @@ function emitLlmSpan(tracer, state, msg) {
9649
10044
  toolCalls.forEach((tc, j) => {
9650
10045
  if (tc.name) attrs[`neatlogs.llm.tool_calls.${j}.name`] = tc.name;
9651
10046
  if (tc.arguments !== void 0)
9652
- attrs[`neatlogs.llm.tool_calls.${j}.arguments`] = safeStringify12(tc.arguments);
10047
+ attrs[`neatlogs.llm.tool_calls.${j}.arguments`] = safeStringify13(tc.arguments);
9653
10048
  if (tc.id) attrs[`neatlogs.llm.tool_calls.${j}.id`] = String(tc.id);
9654
10049
  });
9655
10050
  }
9656
- attrs["neatlogs.llm.output"] = safeStringify12(outBlob);
10051
+ attrs["neatlogs.llm.output"] = safeStringify13(outBlob);
9657
10052
  attrs["output.value"] = outText || "";
9658
10053
  }
9659
10054
  const usage = msg.usage;
@@ -9665,13 +10060,13 @@ function emitLlmSpan(tracer, state, msg) {
9665
10060
  if (usage.cacheRead) attrs["neatlogs.llm.token_count.cache_read"] = usage.cacheRead;
9666
10061
  if (usage.cacheWrite) attrs["neatlogs.llm.token_count.cache_write"] = usage.cacheWrite;
9667
10062
  }
9668
- const parent = state.agentCtx ?? import_api19.context.active();
10063
+ const parent = state.agentCtx ?? import_api20.context.active();
9669
10064
  const span2 = tracer.startSpan(
9670
10065
  `pi_agent.llm.${msg.model || "model"}`,
9671
10066
  { attributes: attrs },
9672
10067
  parent
9673
10068
  );
9674
- span2.setStatus({ code: import_api19.SpanStatusCode.OK });
10069
+ span2.setStatus({ code: import_api20.SpanStatusCode.OK });
9675
10070
  span2.end();
9676
10071
  }
9677
10072
  function splitAssistantContent(content) {
@@ -9699,7 +10094,7 @@ function messageText(msg) {
9699
10094
  if (typeof block === "string") parts.push(block);
9700
10095
  else if (block && typeof block === "object") {
9701
10096
  if (typeof block.text === "string") parts.push(block.text);
9702
- else if (block.type === "toolCall") parts.push(`${block.name ?? "tool"}(${safeStringify12(block.arguments)})`);
10097
+ else if (block.type === "toolCall") parts.push(`${block.name ?? "tool"}(${safeStringify13(block.arguments)})`);
9703
10098
  }
9704
10099
  }
9705
10100
  return parts.join("");
@@ -9722,7 +10117,7 @@ function markPatched2(e) {
9722
10117
  e[PATCH_FLAG3] = true;
9723
10118
  }
9724
10119
  }
9725
- function safeStringify12(value) {
10120
+ function safeStringify13(value) {
9726
10121
  if (typeof value === "string") return value;
9727
10122
  try {
9728
10123
  return JSON.stringify(value) ?? "";
@@ -9732,8 +10127,8 @@ function safeStringify12(value) {
9732
10127
  }
9733
10128
 
9734
10129
  // src/claude-agent-sdk.ts
9735
- var import_api20 = require("@opentelemetry/api");
9736
- var TRACER_NAME12 = "neatlogs.claude_agent_sdk";
10130
+ var import_api21 = require("@opentelemetry/api");
10131
+ var TRACER_NAME13 = "neatlogs.claude_agent_sdk";
9737
10132
  var ROOT_SCOPE = "__root__";
9738
10133
  function wrapClaudeAgentSDK(sdk, options = {}) {
9739
10134
  if (!sdk || typeof sdk.query !== "function") return sdk;
@@ -9753,13 +10148,13 @@ function wrapClaudeAgentSDK(sdk, options = {}) {
9753
10148
  }
9754
10149
  function wrapQuery(original, options) {
9755
10150
  return function(params, ...rest) {
9756
- const tracer = import_api20.trace.getTracer(TRACER_NAME12);
10151
+ const tracer = import_api21.trace.getTracer(TRACER_NAME13);
9757
10152
  const workflowName = options.workflowName ?? "claude_agent.query";
9758
10153
  const promptRef = { text: "" };
9759
10154
  const agentSpan = tracer.startSpan(
9760
10155
  "claude_agent.query",
9761
10156
  { attributes: { "neatlogs.span.kind": "AGENT", "neatlogs.workflow.name": workflowName } },
9762
- import_api20.context.active()
10157
+ import_api21.context.active()
9763
10158
  );
9764
10159
  const promptText = extractPromptText(params?.prompt);
9765
10160
  if (promptText) {
@@ -9768,8 +10163,8 @@ function wrapQuery(original, options) {
9768
10163
  } else if (params && isAsyncIterable(params.prompt)) {
9769
10164
  params = { ...params, prompt: tapPromptStream(params.prompt, promptRef) };
9770
10165
  }
9771
- const agentCtx = import_api20.trace.setSpan(import_api20.context.active(), agentSpan);
9772
- const queryObj = import_api20.context.with(agentCtx, () => original(params, ...rest));
10166
+ const agentCtx = import_api21.trace.setSpan(import_api21.context.active(), agentSpan);
10167
+ const queryObj = import_api21.context.with(agentCtx, () => original(params, ...rest));
9773
10168
  return instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRef);
9774
10169
  };
9775
10170
  }
@@ -9788,7 +10183,7 @@ async function* tapPromptStream(prompt, ref) {
9788
10183
  function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRef) {
9789
10184
  const originalAsyncIterator = queryObj?.[Symbol.asyncIterator]?.bind(queryObj);
9790
10185
  if (!originalAsyncIterator) {
9791
- agentSpan.setStatus({ code: import_api20.SpanStatusCode.OK });
10186
+ agentSpan.setStatus({ code: import_api21.SpanStatusCode.OK });
9792
10187
  agentSpan.end();
9793
10188
  return queryObj;
9794
10189
  }
@@ -9823,9 +10218,9 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
9823
10218
  }
9824
10219
  if (rootScope.finalText) agentSpan.setAttribute("output.value", rootScope.finalText);
9825
10220
  if (status === "error") {
9826
- recordError7(agentSpan, err);
10221
+ recordError8(agentSpan, err);
9827
10222
  } else {
9828
- agentSpan.setStatus({ code: import_api20.SpanStatusCode.OK });
10223
+ agentSpan.setStatus({ code: import_api21.SpanStatusCode.OK });
9829
10224
  agentSpan.end();
9830
10225
  }
9831
10226
  };
@@ -9836,7 +10231,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
9836
10231
  return {
9837
10232
  async next() {
9838
10233
  try {
9839
- const result = await import_api20.context.with(agentCtx, () => iterator.next());
10234
+ const result = await import_api21.context.with(agentCtx, () => iterator.next());
9840
10235
  if (result.done) {
9841
10236
  finalizeAgent("ok");
9842
10237
  return result;
@@ -9867,7 +10262,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
9867
10262
  function closeScope(scope, status) {
9868
10263
  try {
9869
10264
  if (scope.finalText) scope.span.setAttribute("output.value", scope.finalText);
9870
- scope.span.setStatus({ code: status === "ok" ? import_api20.SpanStatusCode.OK : import_api20.SpanStatusCode.ERROR });
10265
+ scope.span.setStatus({ code: status === "ok" ? import_api21.SpanStatusCode.OK : import_api21.SpanStatusCode.ERROR });
9871
10266
  scope.span.end();
9872
10267
  } catch {
9873
10268
  }
@@ -9882,7 +10277,7 @@ function getScope(tracer, state, msg) {
9882
10277
  flushAssistantTurn(tracer, root, state);
9883
10278
  }
9884
10279
  const parentToolSpan = state.toolSpans.get(parentId);
9885
- const parentCtx = parentToolSpan ? import_api20.trace.setSpan(import_api20.context.active(), parentToolSpan) : state.scopes.get(ROOT_SCOPE).ctx;
10280
+ const parentCtx = parentToolSpan ? import_api21.trace.setSpan(import_api21.context.active(), parentToolSpan) : state.scopes.get(ROOT_SCOPE).ctx;
9886
10281
  const subType = msg?.subagent_type ? String(msg.subagent_type) : "subagent";
9887
10282
  const attrs = {
9888
10283
  "neatlogs.span.kind": "AGENT",
@@ -9892,7 +10287,7 @@ function getScope(tracer, state, msg) {
9892
10287
  const span2 = tracer.startSpan(`claude_agent.subagent.${subType}`, { attributes: attrs }, parentCtx);
9893
10288
  const scope = {
9894
10289
  span: span2,
9895
- ctx: import_api20.trace.setSpan(import_api20.context.active(), span2),
10290
+ ctx: import_api21.trace.setSpan(import_api21.context.active(), span2),
9896
10291
  inputMessages: msg?.task_description ? [{ role: "user", content: String(msg.task_description) }] : [],
9897
10292
  assistantBuffer: null,
9898
10293
  finalText: "",
@@ -9947,7 +10342,7 @@ function handleMessage(tracer, state, msg, finalizeAgent) {
9947
10342
  rootScope.span.setAttribute("neatlogs.conversation.id", String(msg.session_id));
9948
10343
  }
9949
10344
  const usage = msg.usage;
9950
- if (usage) setUsage2(rootScope.span, usage);
10345
+ if (usage) setUsage3(rootScope.span, usage);
9951
10346
  if (msg.total_cost_usd != null) rootScope.span.setAttribute("neatlogs.agent.cost_usd", msg.total_cost_usd);
9952
10347
  if (msg.num_turns != null) rootScope.span.setAttribute("neatlogs.agent.num_turns", msg.num_turns);
9953
10348
  if (msg.is_error) rootScope.span.setAttribute("neatlogs.agent.is_error", true);
@@ -9996,10 +10391,10 @@ function flushAssistantTurn(tracer, scope, state) {
9996
10391
  attrs[`neatlogs.llm.input_messages.${i}.content`] = m.content;
9997
10392
  });
9998
10393
  if (scope.inputMessages.length) {
9999
- attrs["input.value"] = safeStringify13({ messages: scope.inputMessages });
10394
+ attrs["input.value"] = safeStringify14({ messages: scope.inputMessages });
10000
10395
  }
10001
10396
  const outText = buf.textParts.join("");
10002
- const outValue = outText || buf.toolCalls.map((tc) => `${tc.name}(${safeStringify13(tc.input ?? {})})`).join("\n");
10397
+ const outValue = outText || buf.toolCalls.map((tc) => `${tc.name}(${safeStringify14(tc.input ?? {})})`).join("\n");
10003
10398
  if (outValue) {
10004
10399
  attrs["neatlogs.llm.output_messages.0.role"] = "assistant";
10005
10400
  attrs["neatlogs.llm.output_messages.0.content"] = outValue;
@@ -10011,17 +10406,17 @@ function flushAssistantTurn(tracer, scope, state) {
10011
10406
  buf.toolCalls.forEach((tc, j) => {
10012
10407
  attrs[`neatlogs.llm.tool_calls.${j}.id`] = tc.id;
10013
10408
  attrs[`neatlogs.llm.tool_calls.${j}.name`] = tc.name;
10014
- attrs[`neatlogs.llm.tool_calls.${j}.arguments`] = safeStringify13(tc.input ?? {});
10409
+ attrs[`neatlogs.llm.tool_calls.${j}.arguments`] = safeStringify14(tc.input ?? {});
10015
10410
  });
10016
10411
  if (buf.stopReason) attrs["neatlogs.llm.finish_reason"] = String(buf.stopReason);
10017
10412
  const span2 = tracer.startSpan(`claude_agent.llm.${model || "model"}`, { attributes: attrs }, scope.ctx);
10018
- if (buf.usage) setUsage2(span2, buf.usage);
10019
- span2.setStatus({ code: import_api20.SpanStatusCode.OK });
10413
+ if (buf.usage) setUsage3(span2, buf.usage);
10414
+ span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10020
10415
  span2.end();
10021
10416
  if (outText) scope.finalText = outText;
10022
10417
  const turnParts = [];
10023
10418
  if (outText) turnParts.push(outText);
10024
- for (const tc of buf.toolCalls) turnParts.push(`[tool_call ${tc.name} ${safeStringify13(tc.input ?? {})}]`);
10419
+ for (const tc of buf.toolCalls) turnParts.push(`[tool_call ${tc.name} ${safeStringify14(tc.input ?? {})}]`);
10025
10420
  if (turnParts.length) scope.inputMessages.push({ role: "assistant", content: turnParts.join("\n") });
10026
10421
  for (const tc of buf.toolCalls) {
10027
10422
  const toolSpan = tracer.startSpan(
@@ -10031,7 +10426,7 @@ function flushAssistantTurn(tracer, scope, state) {
10031
10426
  "neatlogs.span.kind": "TOOL",
10032
10427
  "neatlogs.tool.name": String(tc.name ?? ""),
10033
10428
  ...tc.id ? { "neatlogs.tool_call.id": String(tc.id) } : {},
10034
- "input.value": safeStringify13(tc.input ?? {})
10429
+ "input.value": safeStringify14(tc.input ?? {})
10035
10430
  }
10036
10431
  },
10037
10432
  scope.ctx
@@ -10045,16 +10440,16 @@ function closeToolSpansFromUser(state, scope, msg) {
10045
10440
  if (block?.type !== "tool_result") continue;
10046
10441
  const id = block.tool_use_id ?? "";
10047
10442
  const out = block.content;
10048
- const outText = typeof out === "string" ? out : safeStringify13(out);
10443
+ const outText = typeof out === "string" ? out : safeStringify14(out);
10049
10444
  if (outText) scope.inputMessages.push({ role: "tool", content: outText });
10050
10445
  const span2 = state.toolSpans.get(id);
10051
10446
  if (!span2) continue;
10052
10447
  span2.setAttribute("output.value", outText);
10053
10448
  if (block.is_error) {
10054
- span2.setStatus({ code: import_api20.SpanStatusCode.ERROR });
10449
+ span2.setStatus({ code: import_api21.SpanStatusCode.ERROR });
10055
10450
  span2.setAttribute("neatlogs.tool.is_error", true);
10056
10451
  } else {
10057
- span2.setStatus({ code: import_api20.SpanStatusCode.OK });
10452
+ span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10058
10453
  }
10059
10454
  span2.end();
10060
10455
  state.toolSpans.delete(id);
@@ -10073,7 +10468,7 @@ function userMessageText(msg) {
10073
10468
  }
10074
10469
  return parts.join("\n");
10075
10470
  }
10076
- function setUsage2(span2, usage) {
10471
+ function setUsage3(span2, usage) {
10077
10472
  if (!usage) return;
10078
10473
  if (usage.input_tokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", usage.input_tokens);
10079
10474
  if (usage.output_tokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", usage.output_tokens);
@@ -10091,7 +10486,7 @@ function extractPromptText(prompt) {
10091
10486
  if (typeof prompt === "string") return prompt;
10092
10487
  return "";
10093
10488
  }
10094
- function safeStringify13(value) {
10489
+ function safeStringify14(value) {
10095
10490
  if (typeof value === "string") return value;
10096
10491
  try {
10097
10492
  return JSON.stringify(value) ?? "";
@@ -10099,20 +10494,20 @@ function safeStringify13(value) {
10099
10494
  return "";
10100
10495
  }
10101
10496
  }
10102
- function recordError7(span2, err) {
10497
+ function recordError8(span2, err) {
10103
10498
  if (err instanceof Error) {
10104
- span2.setStatus({ code: import_api20.SpanStatusCode.ERROR, message: err.message });
10499
+ span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: err.message });
10105
10500
  span2.recordException(err);
10106
10501
  } else {
10107
- span2.setStatus({ code: import_api20.SpanStatusCode.ERROR, message: String(err) });
10502
+ span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: String(err) });
10108
10503
  }
10109
10504
  span2.end();
10110
10505
  }
10111
10506
 
10112
10507
  // src/openrouter-agent.ts
10113
- var import_api21 = require("@opentelemetry/api");
10114
- var TRACER_NAME13 = "neatlogs.openrouter_agent";
10115
- var PROVIDER4 = "openrouter";
10508
+ var import_api22 = require("@opentelemetry/api");
10509
+ var TRACER_NAME14 = "neatlogs.openrouter_agent";
10510
+ var PROVIDER5 = "openrouter";
10116
10511
  function wrapOpenRouterAgent(client) {
10117
10512
  const c = client;
10118
10513
  if (!c || c._neatlogsWrapped) return client;
@@ -10129,30 +10524,30 @@ function wrapOpenRouterAgent(client) {
10129
10524
  function wrapCallModel(callModel) {
10130
10525
  return function(clientArg, opts, ...rest) {
10131
10526
  const span2 = startLlmSpan(opts);
10132
- const ctx = import_api21.trace.setSpan(import_api21.context.active(), span2);
10133
- const result = import_api21.context.with(ctx, () => callModel.call(this, clientArg, opts, ...rest));
10527
+ const ctx = import_api22.trace.setSpan(import_api22.context.active(), span2);
10528
+ const result = import_api22.context.with(ctx, () => callModel.call(this, clientArg, opts, ...rest));
10134
10529
  return instrumentModelResult(result, span2);
10135
10530
  };
10136
10531
  }
10137
10532
  function tracedCallModel(original) {
10138
10533
  return function(opts, ...rest) {
10139
10534
  const span2 = startLlmSpan(opts);
10140
- const ctx = import_api21.trace.setSpan(import_api21.context.active(), span2);
10141
- const result = import_api21.context.with(ctx, () => original(opts, ...rest));
10535
+ const ctx = import_api22.trace.setSpan(import_api22.context.active(), span2);
10536
+ const result = import_api22.context.with(ctx, () => original(opts, ...rest));
10142
10537
  return instrumentModelResult(result, span2);
10143
10538
  };
10144
10539
  }
10145
10540
  function startLlmSpan(opts) {
10146
- const tracer = getProviderTracer(TRACER_NAME13);
10541
+ const tracer = getProviderTracer(TRACER_NAME14);
10147
10542
  const model = opts?.model ?? "";
10148
10543
  const span2 = tracer.startSpan("openrouter.call_model", {
10149
10544
  attributes: {
10150
10545
  "neatlogs.span.kind": "LLM",
10151
- "neatlogs.llm.provider": PROVIDER4,
10152
- "neatlogs.llm.system": PROVIDER4,
10546
+ "neatlogs.llm.provider": PROVIDER5,
10547
+ "neatlogs.llm.system": PROVIDER5,
10153
10548
  "neatlogs.llm.model_name": model
10154
10549
  }
10155
- }, import_api21.context.active());
10550
+ }, import_api22.context.active());
10156
10551
  const messages = Array.isArray(opts?.messages) ? opts.messages : Array.isArray(opts?.input) ? opts.input : [];
10157
10552
  if (messages.length) {
10158
10553
  messages.forEach((msg, i) => {
@@ -10160,10 +10555,10 @@ function startLlmSpan(opts) {
10160
10555
  const content = msg?.content;
10161
10556
  span2.setAttribute(
10162
10557
  `neatlogs.llm.input_messages.${i}.content`,
10163
- typeof content === "string" ? content : safeStringify14(content)
10558
+ typeof content === "string" ? content : safeStringify15(content)
10164
10559
  );
10165
10560
  });
10166
- span2.setAttribute("input.value", safeStringify14({ messages }));
10561
+ span2.setAttribute("input.value", safeStringify15({ messages }));
10167
10562
  } else if (typeof opts?.input === "string") {
10168
10563
  span2.setAttribute("neatlogs.llm.input_messages.0.role", "user");
10169
10564
  span2.setAttribute("neatlogs.llm.input_messages.0.content", opts.input);
@@ -10204,7 +10599,7 @@ function startLlmSpan(opts) {
10204
10599
  }
10205
10600
  function instrumentModelResult(result, span2) {
10206
10601
  if (!result || typeof result !== "object" && typeof result !== "function") {
10207
- span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10602
+ span2.setStatus({ code: import_api22.SpanStatusCode.OK });
10208
10603
  span2.end();
10209
10604
  return result;
10210
10605
  }
@@ -10215,14 +10610,14 @@ function instrumentModelResult(result, span2) {
10215
10610
  try {
10216
10611
  finalizeLlm(span2, resolved);
10217
10612
  } catch {
10218
- span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10613
+ span2.setStatus({ code: import_api22.SpanStatusCode.OK });
10219
10614
  span2.end();
10220
10615
  }
10221
10616
  };
10222
10617
  const finalizeError = (err) => {
10223
10618
  if (finalized) return;
10224
10619
  finalized = true;
10225
- recordError8(span2, err);
10620
+ recordError9(span2, err);
10226
10621
  };
10227
10622
  return new Proxy(result, {
10228
10623
  get(obj, prop, receiver) {
@@ -10308,7 +10703,7 @@ function finalizeLlm(span2, result) {
10308
10703
  span2.setAttribute(`neatlogs.llm.tool_calls.${j}.id`, tc?.id ?? "");
10309
10704
  span2.setAttribute(`neatlogs.llm.tool_calls.${j}.name`, tc?.function?.name ?? tc?.name ?? "");
10310
10705
  const args = tc?.function?.arguments ?? tc?.arguments;
10311
- span2.setAttribute(`neatlogs.llm.tool_calls.${j}.arguments`, typeof args === "string" ? args : safeStringify14(args ?? {}));
10706
+ span2.setAttribute(`neatlogs.llm.tool_calls.${j}.arguments`, typeof args === "string" ? args : safeStringify15(args ?? {}));
10312
10707
  });
10313
10708
  }
10314
10709
  const model = result?.model ?? result?.response?.model;
@@ -10318,7 +10713,7 @@ function finalizeLlm(span2, result) {
10318
10713
  const finishReason = result?.finishReason ?? result?.finish_reason ?? result?.choices?.[0]?.finish_reason;
10319
10714
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
10320
10715
  setOpenResponsesUsage(span2, result);
10321
- span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10716
+ span2.setStatus({ code: import_api22.SpanStatusCode.OK });
10322
10717
  span2.end();
10323
10718
  }
10324
10719
  function extractOpenResponsesText(result) {
@@ -10334,7 +10729,7 @@ function extractOpenResponsesText(result) {
10334
10729
  }
10335
10730
  return parts.length ? parts.join("") : void 0;
10336
10731
  }
10337
- function safeStringify14(value) {
10732
+ function safeStringify15(value) {
10338
10733
  if (typeof value === "string") return value;
10339
10734
  try {
10340
10735
  return JSON.stringify(value) ?? "";
@@ -10342,12 +10737,12 @@ function safeStringify14(value) {
10342
10737
  return "";
10343
10738
  }
10344
10739
  }
10345
- function recordError8(span2, err) {
10740
+ function recordError9(span2, err) {
10346
10741
  if (err instanceof Error) {
10347
- span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: err.message });
10742
+ span2.setStatus({ code: import_api22.SpanStatusCode.ERROR, message: err.message });
10348
10743
  span2.recordException(err);
10349
10744
  } else {
10350
- span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: String(err) });
10745
+ span2.setStatus({ code: import_api22.SpanStatusCode.ERROR, message: String(err) });
10351
10746
  }
10352
10747
  span2.end();
10353
10748
  }
@@ -10504,7 +10899,7 @@ var protoRoot = import_protobufjs.default.Root.fromJSON(OTLP_PROTO_JSON);
10504
10899
  var ExportTraceServiceRequest = protoRoot.lookupType(
10505
10900
  "opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest"
10506
10901
  );
10507
- var SpanStatusCode16 = { UNSET: 0, OK: 1, ERROR: 2 };
10902
+ var SpanStatusCode17 = { UNSET: 0, OK: 1, ERROR: 2 };
10508
10903
  function randomBytes(length) {
10509
10904
  const out = new Uint8Array(length);
10510
10905
  const crypto = globalThis.crypto;
@@ -10711,7 +11106,7 @@ var NeatlogsOpencodePlugin = async (_ctx) => {
10711
11106
  startTimeUnixNano: st.rootSpan.startNano,
10712
11107
  endTimeUnixNano: nowNanoString(),
10713
11108
  attributes: attrs,
10714
- status: { code: SpanStatusCode16.OK }
11109
+ status: { code: SpanStatusCode17.OK }
10715
11110
  });
10716
11111
  const m = nowNanoString();
10717
11112
  shipper.enqueue({
@@ -10798,18 +11193,18 @@ var NeatlogsOpencodePlugin = async (_ctx) => {
10798
11193
  { key: "neatlogs.conversation.id", value: { stringValue: sessionID } }
10799
11194
  ];
10800
11195
  if (start.args !== void 0) {
10801
- setIO(attrs, "TOOL", safeStringify15(start.args), void 0);
10802
- push(attrs, attrStr("neatlogs.tool.input", safeStringify15(start.args)));
11196
+ setIO(attrs, "TOOL", safeStringify16(start.args), void 0);
11197
+ push(attrs, attrStr("neatlogs.tool.input", safeStringify16(start.args)));
10803
11198
  }
10804
11199
  if (result?.title) push(attrs, attrStr("neatlogs.tool.title", String(result.title)));
10805
11200
  const out = result?.output ?? result?.result;
10806
11201
  if (out !== void 0) {
10807
- const o = typeof out === "string" ? out : safeStringify15(out);
11202
+ const o = typeof out === "string" ? out : safeStringify16(out);
10808
11203
  setIO(attrs, "TOOL", void 0, o);
10809
11204
  push(attrs, attrStr("neatlogs.tool.output", o));
10810
11205
  }
10811
11206
  if (result?.metadata !== void 0) {
10812
- push(attrs, attrStr("neatlogs.tool.metadata", safeStringify15(result.metadata)));
11207
+ push(attrs, attrStr("neatlogs.tool.metadata", safeStringify16(result.metadata)));
10813
11208
  }
10814
11209
  shipper.enqueue({
10815
11210
  traceId: st.traceId,
@@ -10820,7 +11215,7 @@ var NeatlogsOpencodePlugin = async (_ctx) => {
10820
11215
  startTimeUnixNano: start.startNano,
10821
11216
  endTimeUnixNano: nowNanoString(),
10822
11217
  attributes: attrs,
10823
- status: { code: SpanStatusCode16.OK }
11218
+ status: { code: SpanStatusCode17.OK }
10824
11219
  });
10825
11220
  } catch {
10826
11221
  }
@@ -10907,10 +11302,10 @@ function emitLlmSpan2(shipper, st, info, sessionID) {
10907
11302
  if (toolCalls.length) {
10908
11303
  toolCalls.forEach((tc, j) => {
10909
11304
  push(attrs, attrStr(`neatlogs.llm.tool_calls.${j}.name`, tc.name));
10910
- push(attrs, attrStr(`neatlogs.llm.tool_calls.${j}.arguments`, safeStringify15(tc.input ?? {})));
11305
+ push(attrs, attrStr(`neatlogs.llm.tool_calls.${j}.arguments`, safeStringify16(tc.input ?? {})));
10911
11306
  });
10912
11307
  if (!outText) {
10913
- const rendered = toolCalls.map((tc) => `\u2192 ${tc.name}(${safeStringify15(tc.input ?? {})})`).join("\n");
11308
+ const rendered = toolCalls.map((tc) => `\u2192 ${tc.name}(${safeStringify16(tc.input ?? {})})`).join("\n");
10914
11309
  push(attrs, attrStr("neatlogs.llm.output_messages.0.role", "assistant"));
10915
11310
  push(attrs, attrStr("neatlogs.llm.output_messages.0.content", rendered));
10916
11311
  setIO(attrs, "LLM", void 0, rendered);
@@ -10939,7 +11334,7 @@ function emitLlmSpan2(shipper, st, info, sessionID) {
10939
11334
  startTimeUnixNano: startNano,
10940
11335
  endTimeUnixNano: nowNanoString(),
10941
11336
  attributes: attrs,
10942
- status: { code: SpanStatusCode16.OK }
11337
+ status: { code: SpanStatusCode17.OK }
10943
11338
  });
10944
11339
  if (info?.id) {
10945
11340
  st.outputParts.delete(String(info.id));
@@ -10975,7 +11370,7 @@ function messageText2(info) {
10975
11370
  }
10976
11371
  return out.join("");
10977
11372
  }
10978
- function safeStringify15(value) {
11373
+ function safeStringify16(value) {
10979
11374
  if (typeof value === "string") return value;
10980
11375
  try {
10981
11376
  return JSON.stringify(value) ?? "";
@@ -11072,6 +11467,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
11072
11467
  traceToolAnthropic,
11073
11468
  traceToolAzureOpenAI,
11074
11469
  traceToolBedrock,
11470
+ traceToolGoogleGenAI,
11075
11471
  traceToolOpenAI,
11076
11472
  traceToolVertexAI,
11077
11473
  updatePrompt,
@@ -11081,6 +11477,8 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
11081
11477
  wrapBedrock,
11082
11478
  wrapCallModel,
11083
11479
  wrapClaudeAgentSDK,
11480
+ wrapGoogleGenAI,
11481
+ wrapGoogleGenAIChat,
11084
11482
  wrapMastra,
11085
11483
  wrapOpenAI,
11086
11484
  wrapOpenRouterAgent,