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
@@ -0,0 +1,186 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """FastAPI router for the /symbolic endpoint."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+ from fastapi import APIRouter, Depends, Query
10
+
11
+ from scope.api.api_v1.endpoints.helpers import get_client
12
+ from scope.connectors.base import Connector
13
+ from scope.dependencies import get_neo4j_db
14
+ from scope.models.otel_traces import (
15
+ SymbolicModelDeleteResponse,
16
+ SymbolicModelResponse,
17
+ SymbolicModelsResponse,
18
+ SymbolicModelWriteRequest,
19
+ SymbolicModelWriteResponse,
20
+ SymbolicSessionStateResponse,
21
+ SymbolicSessionValuesResponse,
22
+ SymbolicSessionValuesWriteRequest,
23
+ SymbolicSessionValuesWriteResponse,
24
+ SymbolicVariablesResponse,
25
+ SymbolicVariablesWriteRequest,
26
+ SymbolicVariablesWriteResponse,
27
+ )
28
+
29
+ router = APIRouter()
30
+
31
+
32
+ def _client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
33
+ """Resolve a Neo4j-backed client for symbolic endpoints."""
34
+ return get_client(api_client=db)
35
+
36
+
37
+ @router.get(
38
+ "/applications/{application_id}/variables", response_model=SymbolicVariablesResponse
39
+ )
40
+ def get_application_symbolic_variables(
41
+ application_id: str,
42
+ model_id: str | None = Query(None, alias="modelId"),
43
+ evaluation_only: bool = Query(False, alias="evaluationOnly"),
44
+ symbolic_client=Depends(_client), # noqa: B008
45
+ ) -> Any:
46
+ """Return symbolic variable definitions for an application model."""
47
+ return symbolic_client.get_application_symbolic_variables(
48
+ application_id,
49
+ model_id=model_id,
50
+ evaluation_only=evaluation_only,
51
+ )
52
+
53
+
54
+ @router.post(
55
+ "/applications/{application_id}/variables",
56
+ response_model=SymbolicVariablesWriteResponse,
57
+ )
58
+ def post_application_symbolic_variables(
59
+ application_id: str,
60
+ body: SymbolicVariablesWriteRequest,
61
+ symbolic_client=Depends(_client), # noqa: B008
62
+ ) -> Any:
63
+ """Upsert symbolic variable definitions for an application."""
64
+ return symbolic_client.write_application_symbolic_variables(
65
+ application_id,
66
+ model_id=body.modelId,
67
+ variables=[variable.model_dump() for variable in body.variables],
68
+ dependencies=[dependency.model_dump() for dependency in body.dependencies],
69
+ min_discriminative_score=body.minDiscriminativeScore,
70
+ )
71
+
72
+
73
+ @router.post(
74
+ "/applications/{application_id}/models", response_model=SymbolicModelWriteResponse
75
+ )
76
+ def post_application_symbolic_model(
77
+ application_id: str,
78
+ body: SymbolicModelWriteRequest,
79
+ symbolic_client=Depends(_client), # noqa: B008
80
+ ) -> Any:
81
+ """Create or update symbolic model metadata for an application."""
82
+ return symbolic_client.write_application_symbolic_model(
83
+ application_id,
84
+ model_id=body.modelId,
85
+ version=body.version,
86
+ is_active=body.isActive,
87
+ model_name=body.modelName,
88
+ task_description=body.taskDescription,
89
+ updated_at=body.updatedAt,
90
+ created_at=body.createdAt,
91
+ )
92
+
93
+
94
+ @router.get(
95
+ "/applications/{application_id}/models", response_model=SymbolicModelsResponse
96
+ )
97
+ def get_application_symbolic_models(
98
+ application_id: str,
99
+ active_only: bool = Query(False, alias="activeOnly"),
100
+ latest: bool = Query(False),
101
+ symbolic_client=Depends(_client), # noqa: B008
102
+ ) -> Any:
103
+ """Return symbolic models attached to an application.
104
+
105
+ Default returns all models (active and inactive).
106
+ Set ``activeOnly=true`` to filter to active models.
107
+ """
108
+ return symbolic_client.get_application_symbolic_models(
109
+ application_id,
110
+ active_only=active_only,
111
+ latest=latest,
112
+ )
113
+
114
+
115
+ @router.get(
116
+ "/applications/{application_id}/models/{model_id}",
117
+ response_model=SymbolicModelResponse,
118
+ )
119
+ def get_application_symbolic_model(
120
+ application_id: str,
121
+ model_id: str,
122
+ symbolic_client=Depends(_client), # noqa: B008
123
+ ) -> Any:
124
+ """Return one symbolic model by identifier for an application."""
125
+ return symbolic_client.get_application_symbolic_model(application_id, model_id)
126
+
127
+
128
+ @router.delete(
129
+ "/applications/{application_id}/models/{model_id}",
130
+ response_model=SymbolicModelDeleteResponse,
131
+ )
132
+ def delete_application_symbolic_model(
133
+ application_id: str,
134
+ model_id: str,
135
+ symbolic_client=Depends(_client), # noqa: B008
136
+ ) -> Any:
137
+ """Delete one symbolic model for an application."""
138
+ return symbolic_client.delete_application_symbolic_model(application_id, model_id)
139
+
140
+
141
+ @router.post(
142
+ "/sessions/{session_id}/values", response_model=SymbolicSessionValuesWriteResponse
143
+ )
144
+ def post_session_symbolic_values(
145
+ session_id: str,
146
+ body: SymbolicSessionValuesWriteRequest,
147
+ symbolic_client=Depends(_client), # noqa: B008
148
+ ) -> Any:
149
+ """Append symbolic value changes derived during session inference."""
150
+ return symbolic_client.write_session_symbolic_values(
151
+ session_id,
152
+ model_id=body.modelId,
153
+ values=[value.model_dump() for value in body.values],
154
+ )
155
+
156
+
157
+ @router.get(
158
+ "/sessions/{session_id}/values", response_model=SymbolicSessionValuesResponse
159
+ )
160
+ def get_session_symbolic_values(
161
+ session_id: str,
162
+ model_id: str | None = Query(None, alias="modelId"),
163
+ variable_id: str | None = Query(None, alias="variableId"),
164
+ variable_name: str | None = Query(None, alias="variableName"),
165
+ limit: int | None = Query(None, ge=1),
166
+ offset: int = Query(0, ge=0),
167
+ symbolic_client=Depends(_client), # noqa: B008
168
+ ) -> Any:
169
+ """Return symbolic value events for a session."""
170
+ return symbolic_client.get_session_symbolic_values(
171
+ session_id,
172
+ model_id=model_id,
173
+ variable_id=variable_id,
174
+ variable_name=variable_name,
175
+ limit=limit,
176
+ offset=offset,
177
+ )
178
+
179
+
180
+ @router.get("/sessions/{session_id}/state", response_model=SymbolicSessionStateResponse)
181
+ def get_session_symbolic_state(
182
+ session_id: str,
183
+ symbolic_client=Depends(_client), # noqa: B008
184
+ ) -> Any:
185
+ """Return the final symbolic state for a session."""
186
+ return symbolic_client.get_session_symbolic_state(session_id)
@@ -0,0 +1,145 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """FastAPI router for the /ui endpoint."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+ import redis as redis_lib
10
+ from fastapi import APIRouter, Depends, Query, Request
11
+
12
+ from scope.api.api_v1.endpoints.helpers import get_client
13
+ from scope.cache import cached, make_cache_key
14
+ from scope.connectors.base import Connector
15
+ from scope.core.config import settings
16
+ from scope.dependencies import get_db, get_neo4j_db, get_redis
17
+ from scope.models.otel_traces import (
18
+ ApplicationNamesResponse,
19
+ ApplicationsResponse,
20
+ )
21
+
22
+ router = APIRouter()
23
+
24
+
25
+ def _client(db: Connector = Depends(get_db)): # noqa: B008
26
+ """Lazily resolve the UI client from the current DB dependency."""
27
+ return get_client(api_client=db)
28
+
29
+
30
+ def _kg_client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
31
+ """Resolve a client backed by Neo4j for KG-only endpoints."""
32
+ return get_client(api_client=db)
33
+
34
+
35
+ # ── Endpoints ─────────────────────────────────────────────────────────────────
36
+
37
+
38
+ @router.get("/info")
39
+ def ui_info(request: Request, ui_client=Depends(_client)) -> Any: # noqa: B008
40
+ """Return descriptive information about this endpoint."""
41
+ return ui_client.info(domain="ui")
42
+
43
+
44
+ @router.get("/applications/names", response_model=ApplicationNamesResponse)
45
+ def get_application_names(
46
+ start_time: str = Query(""),
47
+ end_time: str = Query(""),
48
+ limit: int = Query(50),
49
+ offset: int = Query(0),
50
+ ui_client=Depends(_client), # noqa: B008
51
+ ) -> Any:
52
+ """Return the list of known applications."""
53
+ return ui_client.get_application_names(
54
+ start_time=start_time or None,
55
+ end_time=end_time or None,
56
+ limit=limit,
57
+ offset=offset,
58
+ )
59
+
60
+
61
+ @router.get("/applications", response_model=ApplicationsResponse)
62
+ def get_applications(
63
+ start_time: str = Query(""),
64
+ end_time: str = Query(""),
65
+ limit: int = Query(50),
66
+ offset: int = Query(0),
67
+ ui_client=Depends(_kg_client), # noqa: B008
68
+ redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
69
+ ) -> Any:
70
+ """Return the MAS applications from the KG that have sessions in range (cached)."""
71
+ key = make_cache_key(
72
+ "ui:applications",
73
+ {"start": start_time, "end": end_time, "limit": limit, "offset": offset},
74
+ )
75
+ return cached(
76
+ redis_client=redis_client,
77
+ key=key,
78
+ fetch=lambda: ui_client.get_applications(
79
+ start_time=start_time or None,
80
+ end_time=end_time or None,
81
+ limit=limit,
82
+ offset=offset,
83
+ ),
84
+ ttl=settings.CACHE_TTL_SECONDS,
85
+ enabled=settings.CACHE_ENABLED,
86
+ )
87
+
88
+
89
+ @router.get("/applications/multiquery", response_model=ApplicationsResponse)
90
+ def get_applications_multiquery(
91
+ start_time: str = Query(""),
92
+ end_time: str = Query(""),
93
+ limit: int = Query(50),
94
+ offset: int = Query(0),
95
+ ui_client=Depends(_client), # noqa: B008
96
+ redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
97
+ ) -> Any:
98
+ """Return the list of known applications (cached)."""
99
+ key = make_cache_key(
100
+ "ui:applications:multiquery",
101
+ {"start": start_time, "end": end_time, "limit": limit, "offset": offset},
102
+ )
103
+ return cached(
104
+ redis_client=redis_client,
105
+ key=key,
106
+ fetch=lambda: ui_client.get_applications_multiquery(
107
+ start_time=start_time or None,
108
+ end_time=end_time or None,
109
+ limit=limit,
110
+ offset=offset,
111
+ ),
112
+ ttl=settings.CACHE_TTL_SECONDS,
113
+ enabled=settings.CACHE_ENABLED,
114
+ )
115
+
116
+
117
+ @router.get(
118
+ "/applications-from-clickhouse",
119
+ response_model=ApplicationsResponse,
120
+ )
121
+ def get_applications_from_clickhouse(
122
+ start_time: str = Query(""),
123
+ end_time: str = Query(""),
124
+ limit: int = Query(50),
125
+ offset: int = Query(0),
126
+ ui_client=Depends(_client), # noqa: B008
127
+ redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
128
+ ) -> Any:
129
+ """Return the list of known applications from ClickHouse."""
130
+ key = make_cache_key(
131
+ "ui:applications:from-clickhouse",
132
+ {"start": start_time, "end": end_time, "limit": limit, "offset": offset},
133
+ )
134
+ return cached(
135
+ redis_client=redis_client,
136
+ key=key,
137
+ fetch=lambda: ui_client.get_applications_from_clickhouse(
138
+ start_time=start_time or None,
139
+ end_time=end_time or None,
140
+ limit=limit,
141
+ offset=offset,
142
+ ),
143
+ ttl=settings.CACHE_TTL_SECONDS,
144
+ enabled=settings.CACHE_ENABLED,
145
+ )
@@ -0,0 +1,182 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """FastAPI router for waste estimation and related insights endpoints."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+ from fastapi import APIRouter, Depends, Query
10
+
11
+ from scope.connectors.base import Connector
12
+ from scope.dependencies import ApplicationName, get_neo4j_db
13
+ from scope.query_builders import waste_estimation as waste_qb
14
+
15
+ router = APIRouter()
16
+
17
+
18
+ def _db(db: Connector = Depends(get_neo4j_db)): # noqa: B008
19
+ """Resolve the shared Neo4j connector dependency."""
20
+ return db
21
+
22
+
23
+ @router.get("/waste-estimations", tags=["waste-estimation"])
24
+ def get_waste_estimations(
25
+ limit: int = Query(default=1000, ge=1, le=1000),
26
+ db: Connector = Depends(_db), # noqa: B008
27
+ ) -> list[dict[str, Any]]:
28
+ """Return WasteEstimation nodes from Neo4j."""
29
+ query, params = waste_qb.waste_estimations_query(limit=limit)
30
+ rows = db.execute(query, params)
31
+ return [row["waste_estimation"] for row in rows]
32
+
33
+
34
+ @router.get("/{application_name}/top-wasteful-sessions", tags=["waste-estimation"])
35
+ def get_top_wasteful_sessions(
36
+ application_name: ApplicationName,
37
+ threshold: float = Query(default=0, description="Minimum estimatedWaste value"),
38
+ limit: int = Query(default=25, ge=1, le=1000),
39
+ start_time: int | None = Query(
40
+ default=None, description="Start of date range (unix epoch seconds)"
41
+ ),
42
+ end_time: int | None = Query(
43
+ default=None, description="End of date range (unix epoch seconds)"
44
+ ),
45
+ db: Connector = Depends(_db), # noqa: B008
46
+ ) -> list[dict[str, Any]]:
47
+ """Return wasteful sessions and semantic-group information."""
48
+ query, params = waste_qb.top_wasteful_sessions_query(
49
+ threshold=threshold,
50
+ limit=limit,
51
+ start_time=start_time,
52
+ end_time=end_time,
53
+ application_name=application_name,
54
+ )
55
+ rows = db.execute(query, params)
56
+ return [
57
+ {
58
+ **row["waste_estimation"],
59
+ "semanticGroup": row.get("semanticGroup"),
60
+ "semanticGroupId": row.get("semanticGroupId"),
61
+ }
62
+ for row in rows
63
+ ]
64
+
65
+
66
+ @router.get("/waste-estimations-semantic-groups", tags=["waste-estimation"])
67
+ def get_waste_estimations_by_semantic_group(
68
+ db: Connector = Depends(_db), # noqa: B008
69
+ ) -> list[dict[str, Any]]:
70
+ """Return the sum of WasteEstimation actualCost per leaf semantic group."""
71
+ query, params = waste_qb.waste_estimations_semantic_groups_query()
72
+ return db.execute(query, params)
73
+
74
+
75
+ @router.get(
76
+ "/{application_name}/cost-efficiency-groupped-sessions",
77
+ tags=["waste-estimation"],
78
+ )
79
+ def get_cost_efficiency_grouped_sessions(
80
+ application_name: ApplicationName,
81
+ db: Connector = Depends(_db), # noqa: B008
82
+ ) -> list[dict[str, Any]]:
83
+ """Return costEfficiency per session with its semantic group."""
84
+ query, params = waste_qb.cost_efficiency_grouped_sessions_query(
85
+ application_name=application_name,
86
+ )
87
+ return db.execute(query, params)
88
+
89
+
90
+ @router.get("/wasted-resources-features-score", tags=["waste-estimation"])
91
+ def get_wasted_resources_features_score(
92
+ session_id: str = Query(..., description="Session ID to look up"),
93
+ db: Connector = Depends(_db), # noqa: B008
94
+ ) -> list[dict[str, Any]]:
95
+ """Return top-5 and bottom-5 feature scores by rank per quality target."""
96
+ query, params = waste_qb.wasted_resources_features_score_query(
97
+ session_id=session_id
98
+ )
99
+ rows = db.execute(query, params)
100
+ return [row["item"] for row in rows]
101
+
102
+
103
+ @router.get("/{application_name}/semantic-groups-insights", tags=["insights"])
104
+ def get_semantic_groups_insights(
105
+ application_name: ApplicationName,
106
+ start_time: int | None = Query(
107
+ default=None, description="Start of date range (unix epoch seconds)"
108
+ ),
109
+ end_time: int | None = Query(
110
+ default=None, description="End of date range (unix epoch seconds)"
111
+ ),
112
+ db: Connector = Depends(_db), # noqa: B008
113
+ ) -> list[dict[str, Any]]:
114
+ """Return insights linked to semantic groups ordered by priority desc."""
115
+ query, params = waste_qb.semantic_groups_insights_query(
116
+ start_time=start_time,
117
+ end_time=end_time,
118
+ application_name=application_name,
119
+ )
120
+ return db.execute(query, params)
121
+
122
+
123
+ @router.get("/{application_name}/sessions-insights", tags=["insights"])
124
+ def get_session_insights(
125
+ application_name: ApplicationName,
126
+ start_time: int | None = Query(
127
+ default=None, description="Start of date range (unix epoch seconds)"
128
+ ),
129
+ end_time: int | None = Query(
130
+ default=None, description="End of date range (unix epoch seconds)"
131
+ ),
132
+ semantic_group_id: str | None = Query(
133
+ default=None, description="Filter by semantic group ID"
134
+ ),
135
+ limit: int = Query(
136
+ default=25,
137
+ ge=1,
138
+ le=1000,
139
+ description="Maximum number of results to return",
140
+ ),
141
+ offset: int = Query(default=0, ge=0, description="Number of results to skip"),
142
+ db: Connector = Depends(_db), # noqa: B008
143
+ ) -> list[dict[str, Any]]:
144
+ """Return insights linked to sessions, ordered by priority asc."""
145
+ query, params = waste_qb.sessions_insights_query(
146
+ start_time=start_time,
147
+ end_time=end_time,
148
+ semantic_group_id=semantic_group_id,
149
+ limit=limit,
150
+ offset=offset,
151
+ application_name=application_name,
152
+ )
153
+ return db.execute(query, params)
154
+
155
+
156
+ @router.get("/session-insights", tags=["insights"])
157
+ def get_single_session_insights(
158
+ session_id: str = Query(..., description="Session ID to look up insights for"),
159
+ start_time: int | None = Query(
160
+ default=None, description="Start of date range (unix epoch seconds)"
161
+ ),
162
+ end_time: int | None = Query(
163
+ default=None, description="End of date range (unix epoch seconds)"
164
+ ),
165
+ limit: int = Query(
166
+ default=25,
167
+ ge=1,
168
+ le=1000,
169
+ description="Maximum number of results to return",
170
+ ),
171
+ offset: int = Query(default=0, ge=0, description="Number of results to skip"),
172
+ db: Connector = Depends(_db), # noqa: B008
173
+ ) -> list[dict[str, Any]]:
174
+ """Return insights for a specific session, ordered by priority asc."""
175
+ query, params = waste_qb.session_insights_query(
176
+ session_id=session_id,
177
+ start_time=start_time,
178
+ end_time=end_time,
179
+ limit=limit,
180
+ offset=offset,
181
+ )
182
+ return db.execute(query, params)
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """API v2 package."""
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """API v2 router — composes all v2 sub-routers under ``/api/v2``."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from fastapi import APIRouter
8
+
9
+ from scope.api.api_v2.endpoints import metrics
10
+ from scope.health import healthz as _healthz
11
+
12
+ router = APIRouter(prefix="/api/v2", tags=["v2"])
13
+
14
+
15
+ @router.get("/healthz")
16
+ def healthz() -> dict:
17
+ """Version-scoped health check."""
18
+ return _healthz()
19
+
20
+
21
+ # ── Include domain sub-routers ────────────────────────────────────────────────
22
+
23
+ router.include_router(metrics.router, prefix="/metrics", tags=["metrics"])
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """API v2 endpoints package."""