ioc-scope-api 1.0.0__py3-none-any.whl

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.
Files changed (106) hide show
  1. ioc_scope_api-1.0.0.dist-info/METADATA +306 -0
  2. ioc_scope_api-1.0.0.dist-info/RECORD +106 -0
  3. ioc_scope_api-1.0.0.dist-info/WHEEL +4 -0
  4. ioc_scope_api-1.0.0.dist-info/entry_points.txt +2 -0
  5. scope/__init__.py +27 -0
  6. scope/api/__init__.py +119 -0
  7. scope/api/api_v1/__init__.py +2 -0
  8. scope/api/api_v1/api.py +71 -0
  9. scope/api/api_v1/endpoints/__init__.py +2 -0
  10. scope/api/api_v1/endpoints/agentic_protocols_metrics.py +39 -0
  11. scope/api/api_v1/endpoints/applications.py +440 -0
  12. scope/api/api_v1/endpoints/cache.py +50 -0
  13. scope/api/api_v1/endpoints/concepts.py +123 -0
  14. scope/api/api_v1/endpoints/features.py +19 -0
  15. scope/api/api_v1/endpoints/helpers.py +65 -0
  16. scope/api/api_v1/endpoints/kg.py +195 -0
  17. scope/api/api_v1/endpoints/labels.py +71 -0
  18. scope/api/api_v1/endpoints/live_topology.py +89 -0
  19. scope/api/api_v1/endpoints/metrics.py +1014 -0
  20. scope/api/api_v1/endpoints/reasoning.py +62 -0
  21. scope/api/api_v1/endpoints/semanticgroups.py +144 -0
  22. scope/api/api_v1/endpoints/sessions.py +339 -0
  23. scope/api/api_v1/endpoints/spans.py +41 -0
  24. scope/api/api_v1/endpoints/symbolic.py +186 -0
  25. scope/api/api_v1/endpoints/ui.py +145 -0
  26. scope/api/api_v1/endpoints/waste_estimation.py +182 -0
  27. scope/api/api_v2/__init__.py +3 -0
  28. scope/api/api_v2/api.py +23 -0
  29. scope/api/api_v2/endpoints/__init__.py +3 -0
  30. scope/api/api_v2/endpoints/metrics.py +193 -0
  31. scope/app.py +30 -0
  32. scope/cache.py +64 -0
  33. scope/client/__init__.py +27 -0
  34. scope/client/_concepts.py +137 -0
  35. scope/client/_kg.py +64 -0
  36. scope/client/_labels.py +86 -0
  37. scope/client/_live_topology.py +912 -0
  38. scope/client/_metrics.py +561 -0
  39. scope/client/_semanticgroups.py +166 -0
  40. scope/client/_sessions.py +168 -0
  41. scope/client/_symbolic.py +1354 -0
  42. scope/client/_ui.py +599 -0
  43. scope/client/agentic_protocols.py +289 -0
  44. scope/client/application_charts.py +1786 -0
  45. scope/client/applications.py +2246 -0
  46. scope/client/base.py +49 -0
  47. scope/client/cognition_protocols.py +302 -0
  48. scope/client/constants.py +81 -0
  49. scope/client/dal.py +2382 -0
  50. scope/client/failures.py +70 -0
  51. scope/client/local.py +161 -0
  52. scope/client/mock/__init__.py +7 -0
  53. scope/client/mock/client.py +1034 -0
  54. scope/client/sessions.py +1688 -0
  55. scope/client/spans.py +95 -0
  56. scope/client/utils.py +392 -0
  57. scope/connectors/__init__.py +13 -0
  58. scope/connectors/base.py +52 -0
  59. scope/connectors/clickhouse.py +105 -0
  60. scope/connectors/neo4j.py +220 -0
  61. scope/connectors/sqlalchemy.py +131 -0
  62. scope/core/config.py +530 -0
  63. scope/core/exceptions.py +64 -0
  64. scope/dependencies.py +164 -0
  65. scope/health.py +10 -0
  66. scope/interfaces/__init__.py +33 -0
  67. scope/interfaces/data_provider.py +61 -0
  68. scope/interfaces/integration_example.py +310 -0
  69. scope/interfaces/kg_provider.py +91 -0
  70. scope/interfaces/metrics_provider.py +92 -0
  71. scope/interfaces/models.py +185 -0
  72. scope/models/kg.py +48 -0
  73. scope/models/live_topology.py +78 -0
  74. scope/models/otel_traces.py +1595 -0
  75. scope/providers/__init__.py +277 -0
  76. scope/providers/_graph.py +59 -0
  77. scope/providers/cognition_protocols.py +178 -0
  78. scope/providers/kg.py +702 -0
  79. scope/providers/kg_query_runner.py +109 -0
  80. scope/providers/neo4j_mce.py +18 -0
  81. scope/providers/scope_metrics.py +7 -0
  82. scope/query_builders/__init__.py +14 -0
  83. scope/query_builders/cognition_protocol_graph.py +191 -0
  84. scope/query_builders/concepts.py +112 -0
  85. scope/query_builders/dal.py +931 -0
  86. scope/query_builders/failure_graph.py +102 -0
  87. scope/query_builders/features.py +5 -0
  88. scope/query_builders/kg.py +416 -0
  89. scope/query_builders/labels.py +53 -0
  90. scope/query_builders/live_topology.py +503 -0
  91. scope/query_builders/metric_graph.py +196 -0
  92. scope/query_builders/metrics.py +354 -0
  93. scope/query_builders/semanticgroups.py +46 -0
  94. scope/query_builders/sessions.py +208 -0
  95. scope/query_builders/symbolic.py +615 -0
  96. scope/query_builders/trajectory.py +76 -0
  97. scope/query_builders/types.py +20 -0
  98. scope/query_builders/ui.py +3278 -0
  99. scope/query_builders/waste_estimation.py +221 -0
  100. scope/repositories/__init__.py +28 -0
  101. scope/repositories/clickhouse_otel_repository.py +135 -0
  102. scope/repositories/otel_repository.py +97 -0
  103. scope/repositories/sqlite_repository.py +215 -0
  104. scope/scripts/__init__.py +2 -0
  105. scope/scripts/seed.py +35 -0
  106. scope/workarounds.py +38 -0
scope/core/config.py ADDED
@@ -0,0 +1,530 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ import json
4
+ import os
5
+ from typing import Any, Dict, Union
6
+
7
+ from pydantic import ConfigDict, field_validator
8
+ from pydantic_settings import BaseSettings
9
+
10
+ _QUALITY_CATEGORY: Dict[str, dict] = {
11
+ "IntentRecognitionAccuracy": {
12
+ "name": "Intent recognition accuracy",
13
+ "description": "Session-level intent recognition accuracy.",
14
+ "operation": "average",
15
+ "response_key": "intentRecognitionAccuracy",
16
+ "source_metrics": ["IntentRecognitionAccuracy", "IntentRecognition"],
17
+ "unit": "PERCENTAGE",
18
+ },
19
+ "Groundedness": {
20
+ "name": "Groundedness",
21
+ "description": "Session-level groundedness score.",
22
+ "operation": "average",
23
+ "response_key": "groundedness",
24
+ "source_metrics": ["Groundedness", "GroundednessMetric"],
25
+ "unit": "PERCENTAGE",
26
+ },
27
+ "ToolUtilizationAccuracy": {
28
+ "name": "Tool utilization accuracy",
29
+ "description": "Call-level tool utilization accuracy.",
30
+ "operation": "average",
31
+ "response_key": "toolUtilizationAccuracy",
32
+ "source_metrics": ["ToolUtilizationAccuracy"],
33
+ "unit": "PERCENTAGE",
34
+ },
35
+ "deepeval.AnswerRelevancy": {
36
+ "name": "Answer relevancy",
37
+ "description": "Session-level answer relevancy score.",
38
+ "operation": "average",
39
+ "response_key": "answerRelevancy",
40
+ "source_metrics": [
41
+ "deepeval.AnswerRelevancy",
42
+ "AnswerRelevancyMetric",
43
+ "Relevancy",
44
+ ],
45
+ "unit": "PERCENTAGE",
46
+ },
47
+ "ResponseCompleteness": {
48
+ "name": "Response completeness",
49
+ "description": "Session-level response completeness score.",
50
+ "operation": "average",
51
+ "response_key": "responseCompleteness",
52
+ "source_metrics": ["ResponseCompleteness"],
53
+ "unit": "PERCENTAGE",
54
+ },
55
+ "MDT": {
56
+ "name": "MDT",
57
+ "description": "Trajectory quality score.",
58
+ "operation": "average",
59
+ "response_key": "trajectoryQuality",
60
+ "source_metrics": ["MDT", "TrajectoryScore"],
61
+ "unit": "PERCENTAGE",
62
+ },
63
+ "NeuroSymbolicEvaluation": {
64
+ "name": "Neuro-symbolic evaluation",
65
+ "description": "Neuro-symbolic evaluation score when available.",
66
+ "operation": None,
67
+ "is_card": True,
68
+ "response_key": "neuroSymbolicEvaluation",
69
+ "source_metrics": ["NeuroSymbolicEvaluation", "neuro_symbolic_evaluation"],
70
+ "unit": "PERCENTAGE",
71
+ },
72
+ }
73
+
74
+ _RELIABILITY_CATEGORY: Dict[str, dict] = {
75
+ "PassiveEvalAppCompletionRate": {
76
+ "name": "Completion rate",
77
+ "description": "Application completion rate from PassiveEvalApp.",
78
+ "operation": None,
79
+ "is_card": True,
80
+ "response_key": "completionRate",
81
+ "source_metrics": ["PassiveEvalApp"],
82
+ "value_path": ["value", "eval.app.completion_rate"],
83
+ "unit": "PERCENTAGE",
84
+ },
85
+ "Consistency": {
86
+ "name": "Consistency",
87
+ "description": "Consistency score when available.",
88
+ "operation": None,
89
+ "is_card": True,
90
+ "response_key": "consistency",
91
+ "source_metrics": ["Consistency", "LogicalConsistency"],
92
+ "unit": "PERCENTAGE",
93
+ },
94
+ }
95
+
96
+ _TOOLS_CATEGORY: Dict[str, dict] = {
97
+ "listOfTools": {
98
+ "name": "List of tools",
99
+ "description": "The list of tools used by the agent.",
100
+ "operation": "sum",
101
+ "response_key": "listOfTools",
102
+ "unit": "SCALAR",
103
+ },
104
+ }
105
+
106
+ _PERFORMANCE_CATEGORY: Dict[str, dict] = {
107
+ "WorkflowEfficiency": {
108
+ "name": "Workflow efficiency",
109
+ "description": "Session-level workflow efficiency score.",
110
+ "operation": "average",
111
+ "response_key": "workflowEfficiency",
112
+ "source_metrics": ["WorkflowEfficiency"],
113
+ "unit": "PERCENTAGE",
114
+ },
115
+ "CyclesCount": {
116
+ "name": "Cycle efficiency",
117
+ "description": "Derived as 1 / (1 + CyclesCount).",
118
+ "operation": "average",
119
+ "response_key": "cycleEfficiency",
120
+ "source_metrics": ["CyclesCount"],
121
+ "formula": "inverse_one_plus",
122
+ "unit": "PERCENTAGE",
123
+ },
124
+ "LLMErrorRate": {
125
+ "name": "LLM error rate",
126
+ "description": "Derived from PassiveEvalApp llm_fails / llm_calls.",
127
+ "operation": "average",
128
+ "response_key": "llmErrorRate",
129
+ "source_metrics": ["PassiveEvalApp"],
130
+ "formula": "ratio",
131
+ "numerator_path": ["value", "eval.app.llm_fails"],
132
+ "denominator_path": ["value", "eval.app.llm_calls"],
133
+ "unit": "PERCENTAGE",
134
+ },
135
+ "ToolErrorRate": {
136
+ "name": "Tool error rate",
137
+ "description": "Derived from PassiveEvalApp tool_fails / tool_calls.",
138
+ "operation": "average",
139
+ "response_key": "toolErrorRate",
140
+ "source_metrics": ["PassiveEvalApp"],
141
+ "formula": "ratio",
142
+ "numerator_path": ["value", "eval.app.tool_fails"],
143
+ "denominator_path": ["value", "eval.app.tool_calls"],
144
+ "unit": "PERCENTAGE",
145
+ },
146
+ }
147
+
148
+
149
+ # Top-level category constants referenced from _DEFAULT_METRIC_CATEGORIES
150
+ _GENERAL_CATEGORY: Dict[str, dict] = {
151
+ "Duration": {
152
+ "name": "Total LLM invocations duration",
153
+ "description": "The total duration of all the LLM invocations for an agent.",
154
+ "operation": "average",
155
+ "response_key": "totalLLMInvocationDuration",
156
+ "unit": "MILLISECONDS",
157
+ "min_value": 0,
158
+ "max_value": 86400000,
159
+ },
160
+ "Cost": {
161
+ "name": "Total agent cost",
162
+ "description": "Sums of LLM and Tools cost.",
163
+ "operation": "sum",
164
+ "response_key": "totalAgentCost",
165
+ "unit": "DOLLAR",
166
+ },
167
+ "GoalSuccessRate": {
168
+ "name": "Overall task completion",
169
+ "description": "Assesses whether the agents successfully achieved the user's goal.",
170
+ "operation": "average",
171
+ "response_key": "overallTaskCompletion",
172
+ "unit": "PERCENTAGE",
173
+ },
174
+ "Relevancy": {
175
+ "name": "Average answer relevancy",
176
+ "description": "Measures how closely the answer aligns to the user query.",
177
+ "operation": "average",
178
+ "response_key": "averageAnswerRelevancy",
179
+ "unit": "PERCENTAGE",
180
+ },
181
+ "successRate": {
182
+ "name": "Completion rate",
183
+ "description": "The completion rate of the agent.",
184
+ "operation": "average",
185
+ "response_key": "successRate",
186
+ "unit": "PERCENTAGE",
187
+ },
188
+ }
189
+
190
+
191
+ _COST_CATEGORY: Dict[str, dict] = {
192
+ "Cost": {
193
+ "name": "Total LLM cost",
194
+ "description": "The total cost of LLM operations.",
195
+ "operation": "sum",
196
+ "response_key": "totalLLMCost",
197
+ "unit": "DOLLAR",
198
+ },
199
+ "totalToolCost": {
200
+ "name": "Total tool cost",
201
+ "description": "The total cost of tool operations.",
202
+ "operation": "sum",
203
+ "response_key": "totalToolCost",
204
+ "unit": "DOLLAR",
205
+ },
206
+ "averageLLMCost": {
207
+ "name": "Average LLM cost",
208
+ "description": "The average cost per LLM operation.",
209
+ "operation": "average",
210
+ "response_key": "averageLLMCost",
211
+ "unit": "DOLLAR",
212
+ },
213
+ "averageToolCost": {
214
+ "name": "Average Tool cost",
215
+ "description": "Should be broken down per tool.",
216
+ "operation": "average",
217
+ "response_key": "averageToolCost",
218
+ "unit": "DOLLAR",
219
+ },
220
+ "numberOfLLMCalls": {
221
+ "name": "Number of LLM calls",
222
+ "description": "The total number of LLM calls.",
223
+ "operation": "sum",
224
+ "response_key": "numberOfLLMCalls",
225
+ "unit": "SCALAR",
226
+ },
227
+ "numberOfToolCalls": {
228
+ "name": "Number of tool calls",
229
+ "description": "The total number of tool calls.",
230
+ "operation": "sum",
231
+ "response_key": "numberOfToolCalls",
232
+ "unit": "SCALAR",
233
+ },
234
+ }
235
+
236
+
237
+ _LLM_CATEGORY: Dict[str, dict] = {
238
+ "Cost": {
239
+ "name": "Total LLM cost",
240
+ "description": "The total cost of LLM operations.",
241
+ "operation": "sum",
242
+ "response_key": "totalLLMCost",
243
+ "unit": "DOLLAR",
244
+ },
245
+ "TokenCount": {
246
+ "name": "Total tokens",
247
+ "description": "Number of total tokens.",
248
+ "operation": "sum",
249
+ "response_key": "totalTokens",
250
+ "unit": "TOKENS",
251
+ },
252
+ "inputTokens": {
253
+ "name": "Input tokens",
254
+ "description": "Number of input tokens.",
255
+ "operation": "sum",
256
+ "response_key": "inputTokens",
257
+ "unit": "TOKENS",
258
+ },
259
+ "outputTokens": {
260
+ "name": "Output tokens",
261
+ "description": "Number of output tokens.",
262
+ "operation": "sum",
263
+ "response_key": "outputTokens",
264
+ "unit": "TOKENS",
265
+ },
266
+ "Duration": {
267
+ "name": "Inference duration",
268
+ "description": "Duration of the LLM call.",
269
+ "operation": "average",
270
+ "response_key": "inferenceDuration",
271
+ "unit": "MILLISECONDS",
272
+ "min_value": 0,
273
+ "max_value": 3600000,
274
+ },
275
+ "answerCorrectness": {
276
+ "name": "Answer correctness",
277
+ "description": "Measures if the answer if factually correct. (ground truth needed)",
278
+ "operation": "average",
279
+ "response_key": "answerCorrectness",
280
+ "unit": "PERCENTAGE",
281
+ },
282
+ "Relevancy": {
283
+ "name": "Answer relevancy",
284
+ "description": "Measures how closely the answer aligns to the user query.",
285
+ "operation": "average",
286
+ "response_key": "answerRelevancy",
287
+ "unit": "PERCENTAGE",
288
+ },
289
+ "Groundedness": {
290
+ "name": "Answer groundedness",
291
+ "description": "Measures how much the answer is inferred from the given context.",
292
+ "operation": "average",
293
+ "response_key": "answerFaithfulness",
294
+ "unit": "PERCENTAGE",
295
+ },
296
+ "LogicalConsistency": {
297
+ "name": "Coherence",
298
+ "description": "Evaluates whether the response is logically structured, internally consistent, and easy to follow.",
299
+ "operation": "average",
300
+ "response_key": "coherence",
301
+ "unit": "PERCENTAGE",
302
+ },
303
+ "tonality": {
304
+ "name": "Tonality",
305
+ "description": "Evaluates whether the output matches the intended communication style.",
306
+ "operation": "average",
307
+ "response_key": "tonality",
308
+ "unit": "PERCENTAGE",
309
+ },
310
+ "llmErrorRate": {
311
+ "name": "LLM error rate",
312
+ "description": "The rate of error in LLM calls for an agent.",
313
+ "operation": "average",
314
+ "response_key": "llmErrorRate",
315
+ "unit": "PERCENTAGE",
316
+ },
317
+ "llmSuccessRate": {
318
+ "name": "LLM completion rate",
319
+ "description": "The completion rate of LLM calls for an agent.",
320
+ "operation": "average",
321
+ "response_key": "llmSuccessRate",
322
+ "unit": "PERCENTAGE",
323
+ },
324
+ "llmRecoveryRate": {
325
+ "name": "LLM recovery rate",
326
+ "description": "The recovery rate of the LLM calls for an agent.",
327
+ "operation": "average",
328
+ "response_key": "llmRecoveryRate",
329
+ "unit": "PERCENTAGE",
330
+ },
331
+ "llmRetryRate": {
332
+ "name": "LLM retry rate",
333
+ "description": "The rate of retry for a LLM call for an agent.",
334
+ "operation": "average",
335
+ "response_key": "llmRetryRate",
336
+ "unit": "PERCENTAGE",
337
+ },
338
+ "toxicity": {
339
+ "name": "Toxicity",
340
+ "description": "Detects the presence of offensive, harmful, or inappropriate language in model outputs.",
341
+ "operation": "average",
342
+ "response_key": "toxicity",
343
+ "unit": "PERCENTAGE",
344
+ },
345
+ "bias": {
346
+ "name": "Bias",
347
+ "description": "Identifies presence of unwanted bias in LLM outputs.",
348
+ "operation": "average",
349
+ "response_key": "bias",
350
+ "unit": "PERCENTAGE",
351
+ },
352
+ }
353
+
354
+
355
+ _CONVERSATION_CATEGORY: Dict[str, dict] = {
356
+ "Relevancy": {
357
+ "name": "Relevancy",
358
+ "description": "Judges if each turn is pertinent and contributes constructively to the overall dialogue flow.",
359
+ "operation": "average",
360
+ "response_key": "relevancy",
361
+ "unit": "PERCENTAGE",
362
+ },
363
+ "ResponseCompleteness": {
364
+ "name": "Completeness",
365
+ "description": "Judges whether the conversation fully addresses user needs, covering all requested points or sub-queries across turns.",
366
+ "operation": "average",
367
+ "response_key": "completeness",
368
+ "unit": "PERCENTAGE",
369
+ },
370
+ "roleAdherence": {
371
+ "name": "Role adherence",
372
+ "description": "Assesses whether the Agent consistently maintains a defined persona, style, or role throughout a conversation.",
373
+ "operation": "average",
374
+ "response_key": "roleAdherence",
375
+ "unit": "PERCENTAGE",
376
+ },
377
+ "IntentRecognition": {
378
+ "name": "Intent recognition accuracy",
379
+ "description": "Measure how well the Assistant understands and correctly identifies user intents.",
380
+ "operation": "average",
381
+ "response_key": "intentRecognitionAccuracy",
382
+ "unit": "PERCENTAGE",
383
+ },
384
+ "GoalSuccessRate": {
385
+ "name": "Goal success rate",
386
+ "description": "Measure how well the Assistant achieves the goals provided by the user.",
387
+ "operation": "average",
388
+ "response_key": "goalSuccessRate",
389
+ "unit": "PERCENTAGE",
390
+ },
391
+ }
392
+
393
+ # Default category → metric definitions. Override with the
394
+ # ``METRIC_CATEGORIES`` env var (JSON object).
395
+ # Each metric entry carries:
396
+ # name – human-readable display name
397
+ # description – short explanation
398
+ # operation – target aggregation: "sum", "average", or null (card-only)
399
+ # is_card – whether the metric is a KPI card (no time-series chart)
400
+ _DEFAULT_METRIC_CATEGORIES: Dict[str, Dict[str, dict]] = {
401
+ # Keys = Neo4j metricName (PascalCase, used for Cypher queries).
402
+ # ``response_key`` = camelCase key returned to the frontend.
403
+ "general": _GENERAL_CATEGORY,
404
+ "performance": _PERFORMANCE_CATEGORY,
405
+ "quality": _QUALITY_CATEGORY,
406
+ "reliability": _RELIABILITY_CATEGORY,
407
+ "tools": _TOOLS_CATEGORY,
408
+ "cost": _COST_CATEGORY,
409
+ "llm": _LLM_CATEGORY,
410
+ "conversation": _CONVERSATION_CATEGORY,
411
+ }
412
+
413
+
414
+ # Optional human-friendly metadata for each category. Kept separate to preserve
415
+ # the original shape of `METRIC_CATEGORIES` (mapping -> metric definitions)
416
+ # while providing additional fields for UI/clients.
417
+ _DEFAULT_METRIC_CATEGORIES_META: Dict[str, Dict[str, Any]] = {
418
+ "general": {
419
+ "name": "General",
420
+ "description": "General session-level metrics",
421
+ "key": "general",
422
+ "metrics_list": list(_GENERAL_CATEGORY.keys()),
423
+ },
424
+ "performance": {
425
+ "name": "Performance",
426
+ "description": "Performance-related metrics",
427
+ "key": "performance",
428
+ "metrics_list": list(_PERFORMANCE_CATEGORY.keys()),
429
+ },
430
+ "quality": {
431
+ "name": "Quality",
432
+ "description": "Quality and evaluation metrics",
433
+ "key": "quality",
434
+ "metrics_list": list(_QUALITY_CATEGORY.keys()),
435
+ },
436
+ "reliability": {
437
+ "name": "Reliability",
438
+ "description": "Reliability and safety metrics",
439
+ "key": "reliability",
440
+ "metrics_list": list(_RELIABILITY_CATEGORY.keys()),
441
+ },
442
+ "tools": {
443
+ "name": "Tools",
444
+ "description": "Tool usage and related metrics",
445
+ "key": "tools",
446
+ "metrics_list": list(_TOOLS_CATEGORY.keys()),
447
+ },
448
+ "cost": {
449
+ "name": "Cost",
450
+ "description": "Cost-related metrics",
451
+ "key": "cost",
452
+ "metrics_list": list(_COST_CATEGORY.keys()),
453
+ },
454
+ "llm": {
455
+ "name": "LLM",
456
+ "description": "LLM-specific metrics",
457
+ "key": "llm",
458
+ "metrics_list": list(_LLM_CATEGORY.keys()),
459
+ },
460
+ "conversation": {
461
+ "name": "Conversation",
462
+ "description": "Conversation-level metrics",
463
+ "key": "conversation",
464
+ "metrics_list": list(_CONVERSATION_CATEGORY.keys()),
465
+ },
466
+ }
467
+
468
+
469
+ def resolve_neo4j_auth(
470
+ *,
471
+ default_username: str = "neo4j",
472
+ default_password: str = "",
473
+ ) -> tuple[str, str]:
474
+ """Resolve Neo4j credentials with NEO4J_AUTH compatibility.
475
+
476
+ Priority:
477
+ 1) NEO4J_AUTH (username/password)
478
+ 2) Legacy split vars (NEO4J_USERNAME/NEO4J_PASSWORD)
479
+ 3) Defaults
480
+ """
481
+
482
+ auth_username: str | None = None
483
+ auth_password: str | None = None
484
+ neo4j_auth = os.getenv("NEO4J_AUTH")
485
+ if neo4j_auth and "/" in neo4j_auth:
486
+ auth_username, auth_password = neo4j_auth.split("/", 1)
487
+
488
+ username = auth_username or os.getenv("NEO4J_USERNAME") or default_username
489
+ password = auth_password or os.getenv("NEO4J_PASSWORD") or default_password
490
+ return username, password
491
+
492
+
493
+ _DEFAULT_NEO4J_USERNAME, _DEFAULT_NEO4J_PASSWORD = resolve_neo4j_auth(
494
+ default_username="neo4j",
495
+ default_password="",
496
+ )
497
+
498
+
499
+ class Settings(BaseSettings):
500
+ model_config = ConfigDict(case_sensitive=True)
501
+ API_V1_STR: str = "/api/v1"
502
+ API_V2_STR: str = "/api/v2"
503
+ CLICKHOUSE_HOST: str = os.getenv("CLICKHOUSE_HOST", "localhost")
504
+ CLICKHOUSE_PORT: int = int(os.getenv("CLICKHOUSE_PORT", "8123"))
505
+ CLICKHOUSE_USERNAME: str = os.getenv("CLICKHOUSE_USERNAME", "admin")
506
+ CLICKHOUSE_PASSWORD: str = os.getenv("CLICKHOUSE_PASSWORD", "admin")
507
+ CLICKHOUSE_DATABASE: str = os.getenv("CLICKHOUSE_DATABASE", "default")
508
+ NEO4J_HOST: str = os.getenv("NEO4J_HOST", "localhost")
509
+ NEO4J_PORT: int = int(os.getenv("NEO4J_PORT", "7687"))
510
+ NEO4J_USERNAME: str = _DEFAULT_NEO4J_USERNAME
511
+ NEO4J_PASSWORD: str = _DEFAULT_NEO4J_PASSWORD
512
+ NEO4J_DATABASE: str = os.getenv("NEO4J_DATABASE", "neo4j")
513
+
514
+ CACHE_REDIS_URL: str = os.getenv("CACHE_REDIS_URL", "redis://localhost:6379/0")
515
+ CACHE_ENABLED: bool = os.getenv("CACHE_ENABLED", "true").lower() == "true"
516
+ CACHE_TTL_SECONDS: int = int(os.getenv("CACHE_TTL_SECONDS", "55"))
517
+
518
+ METRIC_CATEGORIES: Dict[str, Dict[str, dict]] = _DEFAULT_METRIC_CATEGORIES
519
+ METRIC_CATEGORIES_META: Dict[str, Dict[str, Any]] = _DEFAULT_METRIC_CATEGORIES_META
520
+
521
+ @field_validator("METRIC_CATEGORIES", mode="before")
522
+ def assemble_metric_categories(
523
+ cls, v: Union[str, Dict[str, Dict[str, dict]]]
524
+ ) -> Dict[str, Dict[str, dict]]:
525
+ if isinstance(v, str):
526
+ return json.loads(v)
527
+ return v
528
+
529
+
530
+ settings = Settings()
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """SCOPE application exceptions.
4
+
5
+ Each exception maps to an HTTP status code and carries enough context
6
+ for the centralized error handler to build a proper JSON response.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+
12
+ class SCOPEError(Exception):
13
+ """Base class for all SCOPE application errors."""
14
+
15
+ status_code: int = 500
16
+
17
+ def __init__(self, message: str = "Internal server error") -> None:
18
+ self.message = message
19
+ super().__init__(message)
20
+
21
+
22
+ class NotFoundError(SCOPEError):
23
+ """Requested resource does not exist (404)."""
24
+
25
+ status_code = 404
26
+
27
+ def __init__(self, message: str = "Resource not found") -> None:
28
+ super().__init__(message)
29
+
30
+
31
+ class ValidationError(SCOPEError):
32
+ """Client sent invalid or incomplete data (422)."""
33
+
34
+ status_code = 422
35
+
36
+ def __init__(self, message: str = "Validation error") -> None:
37
+ super().__init__(message)
38
+
39
+
40
+ class DatabaseError(SCOPEError):
41
+ """A database query failed (500)."""
42
+
43
+ status_code = 500
44
+
45
+ def __init__(self, message: str = "Database error") -> None:
46
+ super().__init__(message)
47
+
48
+
49
+ class ConnectorError(SCOPEError):
50
+ """Unable to reach a backend data store (503)."""
51
+
52
+ status_code = 503
53
+
54
+ def __init__(self, message: str = "Service unavailable") -> None:
55
+ super().__init__(message)
56
+
57
+
58
+ class ExternalServiceError(SCOPEError):
59
+ """A call to an external service (Neo4j, ClickHouse, …) failed (502)."""
60
+
61
+ status_code = 502
62
+
63
+ def __init__(self, message: str = "External service error") -> None:
64
+ super().__init__(message)