// src/trace/attribute-vocabulary.ts
import {
  GEN_AI_INPUT_TOKEN_KEYS,
  GEN_AI_MODEL_KEYS,
  GEN_AI_OUTPUT_TOKEN_KEYS
} from "@tangle-network/agent-core/telemetry";
var OPENINFERENCE_SPAN_KIND = "openinference.span.kind";
var LLM_MODEL_NAME = "llm.model_name";
var LLM_INPUT_TOKENS = "llm.token_count.prompt";
var LLM_OUTPUT_TOKENS = "llm.token_count.completion";
var LLM_REASONING_TOKENS = "llm.token_count.reasoning";
var LLM_CACHED_TOKENS = "llm.token_count.prompt_cache_hit";
var LLM_CACHE_WRITE_TOKENS = "llm.token_count.prompt_cache_write";
var LLM_CONTEXT_TOKENS = "tangle.llm.context_tokens";
var LLM_COST_USD = "llm.cost_usd";
var TOOL_NAME = "tool.name";
var TOOL_ARGS_CAPTURED = "tool.args_captured";
var TOOL_LATENCY_MS = "tool.latency_ms";
var INPUT_VALUE = "input.value";
var OUTPUT_VALUE = "output.value";
var SPAN_KIND_ATTR_KEYS = [OPENINFERENCE_SPAN_KIND, "inference.observation_kind"];
var LLM_MODEL_ATTR_KEYS = [
  LLM_MODEL_NAME,
  "inference.llm.model_name",
  "llm.model",
  ...GEN_AI_MODEL_KEYS,
  "tangle.model"
];
var LLM_INPUT_TOKEN_ATTR_KEYS = [
  LLM_INPUT_TOKENS,
  "inference.llm.input_tokens",
  "llm.input_tokens",
  ...GEN_AI_INPUT_TOKEN_KEYS,
  "tangle.tokens.in",
  "tokens.in"
];
var LLM_OUTPUT_TOKEN_ATTR_KEYS = [
  LLM_OUTPUT_TOKENS,
  "inference.llm.output_tokens",
  "llm.output_tokens",
  ...GEN_AI_OUTPUT_TOKEN_KEYS,
  "tangle.tokens.out",
  "tokens.out"
];
var LLM_REASONING_TOKEN_ATTR_KEYS = [
  LLM_REASONING_TOKENS,
  "inference.llm.reasoning_tokens",
  "llm.reasoning_tokens",
  "gen_ai.usage.reasoning_tokens",
  "gen_ai.usage.reasoning_output_tokens",
  "reasoning_tokens",
  "reasoning_output_tokens",
  "tangle.tokens.reasoning",
  "gen_ai.usage.output_tokens_details.reasoning_tokens",
  "gen_ai.usage.completion_tokens_details.reasoning_tokens"
];
var LLM_CACHED_TOKEN_ATTR_KEYS = [
  LLM_CACHED_TOKENS,
  "inference.llm.cached_tokens",
  "llm.cached_tokens",
  "gen_ai.usage.cached_tokens",
  "gen_ai.usage.prompt_tokens_details.cached_tokens",
  "gen_ai.usage.input_tokens_details.cached_tokens",
  "gen_ai.usage.cache_read_tokens",
  "gen_ai.usage.cache_read_input_tokens",
  "cache_read_tokens",
  "cache_read_input_tokens",
  "input_cache_read",
  "tangle.tokens.cached"
];
var LLM_CACHE_WRITE_TOKEN_ATTR_KEYS = [
  LLM_CACHE_WRITE_TOKENS,
  "inference.llm.cache_write_tokens",
  "llm.cache_write_tokens",
  "gen_ai.usage.cache_creation_tokens",
  "gen_ai.usage.cache_creation_input_tokens",
  "cache_creation_tokens",
  "cache_creation_input_tokens",
  "input_cache_creation",
  "tangle.tokens.cache_write"
];
var LLM_COST_ATTR_KEYS = [
  LLM_COST_USD,
  "inference.llm.cost.total",
  "llm.cost.total",
  "gen_ai.usage.cost",
  "gen_ai.usage.cost_usd",
  "tangle.cost.usd",
  "cost.usd",
  "cost"
];
var RUN_COST_ATTR_KEYS = ["tangle.cost.usd", "cost.usd"];
var TOOL_NAME_ATTR_KEYS = [TOOL_NAME, "inference.tool.name"];
function asNumber(value) {
  if (typeof value === "number") return Number.isFinite(value) ? value : null;
  if (typeof value === "string" && value.length > 0) {
    const parsed = Number(value);
    return Number.isFinite(parsed) ? parsed : null;
  }
  return null;
}
function firstNumberAttr(attributes, keys) {
  for (const key of keys) {
    const value = asNumber(attributes[key]);
    if (value !== null) return value;
  }
  return null;
}
function contextInputTokens(usage) {
  if (usage.inputTokens === void 0 || usage.inputTokens === null) return void 0;
  return usage.inputTokens + (usage.cachedTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
}
function applyLlmSpanOtlpAttributes(attributes, span) {
  if (span.model !== void 0) attributes[LLM_MODEL_NAME] = span.model;
  if (span.inputTokens !== void 0) attributes[LLM_INPUT_TOKENS] = span.inputTokens;
  if (span.outputTokens !== void 0) attributes[LLM_OUTPUT_TOKENS] = span.outputTokens;
  if (span.reasoningTokens !== void 0) attributes[LLM_REASONING_TOKENS] = span.reasoningTokens;
  if (span.cachedTokens !== void 0) attributes[LLM_CACHED_TOKENS] = span.cachedTokens;
  if (span.cacheWriteTokens !== void 0) {
    attributes[LLM_CACHE_WRITE_TOKENS] = span.cacheWriteTokens;
  }
  const contextTokens = contextInputTokens(span);
  if (contextTokens !== void 0) attributes[LLM_CONTEXT_TOKENS] = contextTokens;
  if (span.costUsd !== void 0) attributes[LLM_COST_USD] = span.costUsd;
  if (span.finishReason) attributes["llm.finish_reason"] = span.finishReason;
}

export {
  OPENINFERENCE_SPAN_KIND,
  LLM_MODEL_NAME,
  LLM_INPUT_TOKENS,
  LLM_OUTPUT_TOKENS,
  LLM_REASONING_TOKENS,
  LLM_CACHED_TOKENS,
  LLM_CACHE_WRITE_TOKENS,
  LLM_CONTEXT_TOKENS,
  LLM_COST_USD,
  TOOL_NAME,
  TOOL_ARGS_CAPTURED,
  TOOL_LATENCY_MS,
  INPUT_VALUE,
  OUTPUT_VALUE,
  SPAN_KIND_ATTR_KEYS,
  LLM_MODEL_ATTR_KEYS,
  LLM_INPUT_TOKEN_ATTR_KEYS,
  LLM_OUTPUT_TOKEN_ATTR_KEYS,
  LLM_REASONING_TOKEN_ATTR_KEYS,
  LLM_CACHED_TOKEN_ATTR_KEYS,
  LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,
  LLM_COST_ATTR_KEYS,
  RUN_COST_ATTR_KEYS,
  TOOL_NAME_ATTR_KEYS,
  asNumber,
  firstNumberAttr,
  contextInputTokens,
  applyLlmSpanOtlpAttributes
};
//# sourceMappingURL=chunk-K4DBDHLK.js.map