// src/schemas/filter-fields.ts
var filterFields = [
  {
    field: "topics.topics",
    description: "Main topic classification of the trace",
    example: "billing"
  },
  {
    field: "topics.subtopics",
    description: "Subtopic classification",
    example: "refund-request"
  },
  {
    field: "metadata.user_id",
    description: "User ID from trace metadata",
    example: "user-123"
  },
  {
    field: "metadata.thread_id",
    description: "Conversation thread ID",
    example: "thread-456"
  },
  {
    field: "metadata.customer_id",
    description: "Customer/organization ID",
    example: "customer-789"
  },
  {
    field: "metadata.labels",
    description: "Custom labels attached to traces",
    example: "production"
  },
  {
    field: "metadata.key",
    description: "Custom metadata key",
    example: "environment"
  },
  {
    field: "metadata.value",
    description: "Custom metadata value (used with metadata.key)",
    example: "staging"
  },
  {
    field: "metadata.prompt_ids",
    description: "Prompt IDs used in the trace"
  },
  {
    field: "traces.error",
    description: "Whether the trace has errors",
    example: "true"
  },
  {
    field: "spans.type",
    description: "Span type (llm, tool, agent, chain, rag)",
    example: "llm"
  },
  {
    field: "spans.model",
    description: "LLM model name used in spans",
    example: "gpt-4o"
  },
  {
    field: "evaluations.evaluator_id",
    description: "Evaluator that ran on the trace"
  },
  {
    field: "evaluations.evaluator_id.guardrails_only",
    description: "Evaluator ID filtered to guardrails only"
  },
  {
    field: "evaluations.passed",
    description: "Whether evaluations passed",
    example: "true"
  },
  {
    field: "evaluations.score",
    description: "Evaluation score (numeric)"
  },
  {
    field: "evaluations.state",
    description: "Evaluation state (processed, error, skipped)"
  },
  {
    field: "evaluations.label",
    description: "Evaluation label result"
  },
  {
    field: "events.event_type",
    description: "Type of event (thumbs_up_down, custom)",
    example: "thumbs_up_down"
  },
  {
    field: "events.metrics.key",
    description: "Event metric key"
  },
  {
    field: "events.metrics.value",
    description: "Event metric value (numeric)"
  },
  {
    field: "events.event_details.key",
    description: "Event detail key"
  },
  {
    field: "annotations.hasAnnotation",
    description: "Whether trace has human annotations",
    example: "true"
  },
  {
    field: "sentiment.input_sentiment",
    description: "Detected sentiment of input",
    example: "positive"
  }
];

// src/schemas/analytics-metrics.ts
var analyticsMetrics = [
  // metadata
  {
    category: "metadata",
    name: "trace_id",
    label: "Traces",
    allowedAggregations: ["cardinality"],
    description: "Count of unique traces"
  },
  {
    category: "metadata",
    name: "user_id",
    label: "Users",
    allowedAggregations: ["cardinality"],
    description: "Count of unique users"
  },
  {
    category: "metadata",
    name: "thread_id",
    label: "Threads",
    allowedAggregations: ["cardinality"],
    description: "Count of unique conversation threads"
  },
  {
    category: "metadata",
    name: "span_type",
    label: "Span Type",
    allowedAggregations: ["cardinality"],
    description: "Count of spans, optionally filtered by span type"
  },
  // sentiment
  {
    category: "sentiment",
    name: "input_sentiment",
    label: "Input Sentiment Score",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Sentiment analysis score of inputs"
  },
  {
    category: "sentiment",
    name: "thumbs_up_down",
    label: "Thumbs Up/Down Score",
    allowedAggregations: [
      "terms",
      "cardinality",
      "avg",
      "sum",
      "min",
      "max",
      "median",
      "p99",
      "p95",
      "p90"
    ],
    description: "User feedback score (-1 to 1)"
  },
  // performance
  {
    category: "performance",
    name: "completion_time",
    label: "Completion Time",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Time to complete the trace (ms)"
  },
  {
    category: "performance",
    name: "first_token",
    label: "Time to First Token",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Time to first token (ms)"
  },
  {
    category: "performance",
    name: "total_cost",
    label: "Total Cost",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Cost per trace in USD"
  },
  {
    category: "performance",
    name: "prompt_tokens",
    label: "Prompt Tokens",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Input token count"
  },
  {
    category: "performance",
    name: "completion_tokens",
    label: "Completion Tokens",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Output token count"
  },
  {
    category: "performance",
    name: "total_tokens",
    label: "Total Tokens",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Total token count (input + output)"
  },
  {
    category: "performance",
    name: "tokens_per_second",
    label: "Tokens per Second",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Token generation speed"
  },
  // events
  {
    category: "events",
    name: "event_type",
    label: "Event Type",
    allowedAggregations: ["cardinality"],
    description: "Count of events, optionally filtered by event type"
  },
  {
    category: "events",
    name: "event_score",
    label: "Event Score",
    allowedAggregations: [
      "terms",
      "avg",
      "sum",
      "min",
      "max",
      "median",
      "p99",
      "p95",
      "p90"
    ],
    description: "Numeric score from events (requires event_type key and metrics key)"
  },
  {
    category: "events",
    name: "event_details",
    label: "Event Details",
    allowedAggregations: ["cardinality"],
    description: "Event detail key/value distribution (requires event_type key and details key)"
  },
  // evaluations
  {
    category: "evaluations",
    name: "evaluation_score",
    label: "Evaluation Score",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Numeric evaluation score (requires evaluator_id key)"
  },
  {
    category: "evaluations",
    name: "evaluation_pass_rate",
    label: "Evaluation Pass Rate",
    allowedAggregations: ["avg", "sum", "min", "max", "median", "p99", "p95", "p90"],
    description: "Percentage of traces passing evaluation (requires evaluator_id key)"
  },
  {
    category: "evaluations",
    name: "evaluation_runs",
    label: "Evaluation Runs",
    allowedAggregations: ["cardinality"],
    description: "Count of evaluation executions"
  },
  // threads
  {
    category: "threads",
    name: "average_duration_per_thread",
    label: "Thread Duration",
    allowedAggregations: ["avg"],
    description: "Average duration of conversation threads (ms)"
  }
];

// src/schemas/analytics-groups.ts
var analyticsGroups = [
  {
    name: "topics.topics",
    label: "Topic",
    description: "Group by topic classification"
  },
  {
    name: "metadata.user_id",
    label: "User",
    description: "Group by user ID"
  },
  {
    name: "metadata.thread_id",
    label: "Thread",
    description: "Group by conversation thread"
  },
  {
    name: "metadata.customer_id",
    label: "Customer ID",
    description: "Group by customer/organization"
  },
  {
    name: "metadata.labels",
    label: "Label",
    description: "Group by custom labels"
  },
  {
    name: "metadata.model",
    label: "Model",
    description: "Group by LLM model name"
  },
  {
    name: "metadata.span_type",
    label: "Span Type",
    description: "Group by span type (llm, tool, agent, etc.)"
  },
  {
    name: "sentiment.input_sentiment",
    label: "Input Sentiment",
    description: "Group by detected input sentiment (positive, negative, neutral)"
  },
  {
    name: "sentiment.thumbs_up_down",
    label: "Thumbs Up/Down",
    description: "Group by user feedback (positive, negative, neutral)"
  },
  {
    name: "events.event_type",
    label: "Event Type",
    description: "Group by event type"
  },
  {
    name: "evaluations.evaluation_passed",
    label: "Evaluation Passed",
    description: "Group by evaluation pass/fail status"
  },
  {
    name: "evaluations.evaluation_label",
    label: "Evaluation Label",
    description: "Group by evaluation label result"
  },
  {
    name: "evaluations.evaluation_processing_state",
    label: "Evaluation Processing State",
    description: "Group by evaluation processing state"
  },
  {
    name: "error.has_error",
    label: "Contains Error",
    description: "Group by whether the trace contains an error"
  }
];

// src/tools/discover-schema.ts
function formatSchema(category) {
  const sections = [];
  if (category === "filters" || category === "all") {
    sections.push(formatFilters());
  }
  if (category === "metrics" || category === "all") {
    sections.push(formatMetrics());
  }
  if (category === "aggregations" || category === "all") {
    sections.push(formatAggregations());
  }
  if (category === "groups" || category === "all") {
    sections.push(formatGroups());
  }
  return sections.join("\n\n");
}
function formatFilters() {
  const lines = ["## Available Filter Fields", ""];
  lines.push(
    "Use these in the `filters` parameter of `search_traces` and `get_analytics`."
  );
  lines.push('Format: `{ "field_name": ["value1", "value2"] }`');
  lines.push("");
  for (const f of filterFields) {
    lines.push(
      `- **${f.field}**: ${f.description}${f.example ? ` (e.g., \`${f.example}\`)` : ""}`
    );
  }
  return lines.join("\n");
}
function formatMetrics() {
  const lines = ["## Available Metrics", ""];
  lines.push(
    "Use these in `get_analytics` as `metric` parameter in `category.name` format."
  );
  lines.push("");
  const byCategory = /* @__PURE__ */ new Map();
  for (const m of analyticsMetrics) {
    const list = byCategory.get(m.category) || [];
    list.push(m);
    byCategory.set(m.category, list);
  }
  for (const [cat, metrics] of byCategory) {
    lines.push(`### ${cat}`);
    for (const m of metrics) {
      lines.push(`- **${cat}.${m.name}** (${m.label}): ${m.description}`);
      lines.push(`  Aggregations: ${m.allowedAggregations.join(", ")}`);
    }
    lines.push("");
  }
  return lines.join("\n");
}
function formatAggregations() {
  return [
    "## Available Aggregation Types",
    "",
    "- **cardinality**: Count unique values",
    "- **terms**: Distribution/breakdown of values",
    "- **avg**: Average",
    "- **sum**: Sum total",
    "- **min**: Minimum",
    "- **max**: Maximum",
    "- **median**: 50th percentile",
    "- **p90**: 90th percentile",
    "- **p95**: 95th percentile",
    "- **p99**: 99th percentile",
    "",
    "Note: Not all aggregations are available for all metrics. Check the metric's allowed aggregations."
  ].join("\n");
}
function formatGroups() {
  const lines = ["## Available Group-By Options", ""];
  lines.push(
    "Use these in the `groupBy` parameter of `get_analytics`."
  );
  lines.push("");
  for (const g of analyticsGroups) {
    lines.push(`- **${g.name}** (${g.label}): ${g.description}`);
  }
  return lines.join("\n");
}
export {
  formatSchema
};
//# sourceMappingURL=discover-schema-3T52ORPB.js.map