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.
- ioc_scope_api-1.0.0.dist-info/METADATA +306 -0
- ioc_scope_api-1.0.0.dist-info/RECORD +106 -0
- ioc_scope_api-1.0.0.dist-info/WHEEL +4 -0
- ioc_scope_api-1.0.0.dist-info/entry_points.txt +2 -0
- scope/__init__.py +27 -0
- scope/api/__init__.py +119 -0
- scope/api/api_v1/__init__.py +2 -0
- scope/api/api_v1/api.py +71 -0
- scope/api/api_v1/endpoints/__init__.py +2 -0
- scope/api/api_v1/endpoints/agentic_protocols_metrics.py +39 -0
- scope/api/api_v1/endpoints/applications.py +440 -0
- scope/api/api_v1/endpoints/cache.py +50 -0
- scope/api/api_v1/endpoints/concepts.py +123 -0
- scope/api/api_v1/endpoints/features.py +19 -0
- scope/api/api_v1/endpoints/helpers.py +65 -0
- scope/api/api_v1/endpoints/kg.py +195 -0
- scope/api/api_v1/endpoints/labels.py +71 -0
- scope/api/api_v1/endpoints/live_topology.py +89 -0
- scope/api/api_v1/endpoints/metrics.py +1014 -0
- scope/api/api_v1/endpoints/reasoning.py +62 -0
- scope/api/api_v1/endpoints/semanticgroups.py +144 -0
- scope/api/api_v1/endpoints/sessions.py +339 -0
- scope/api/api_v1/endpoints/spans.py +41 -0
- scope/api/api_v1/endpoints/symbolic.py +186 -0
- scope/api/api_v1/endpoints/ui.py +145 -0
- scope/api/api_v1/endpoints/waste_estimation.py +182 -0
- scope/api/api_v2/__init__.py +3 -0
- scope/api/api_v2/api.py +23 -0
- scope/api/api_v2/endpoints/__init__.py +3 -0
- scope/api/api_v2/endpoints/metrics.py +193 -0
- scope/app.py +30 -0
- scope/cache.py +64 -0
- scope/client/__init__.py +27 -0
- scope/client/_concepts.py +137 -0
- scope/client/_kg.py +64 -0
- scope/client/_labels.py +86 -0
- scope/client/_live_topology.py +912 -0
- scope/client/_metrics.py +561 -0
- scope/client/_semanticgroups.py +166 -0
- scope/client/_sessions.py +168 -0
- scope/client/_symbolic.py +1354 -0
- scope/client/_ui.py +599 -0
- scope/client/agentic_protocols.py +289 -0
- scope/client/application_charts.py +1786 -0
- scope/client/applications.py +2246 -0
- scope/client/base.py +49 -0
- scope/client/cognition_protocols.py +302 -0
- scope/client/constants.py +81 -0
- scope/client/dal.py +2382 -0
- scope/client/failures.py +70 -0
- scope/client/local.py +161 -0
- scope/client/mock/__init__.py +7 -0
- scope/client/mock/client.py +1034 -0
- scope/client/sessions.py +1688 -0
- scope/client/spans.py +95 -0
- scope/client/utils.py +392 -0
- scope/connectors/__init__.py +13 -0
- scope/connectors/base.py +52 -0
- scope/connectors/clickhouse.py +105 -0
- scope/connectors/neo4j.py +220 -0
- scope/connectors/sqlalchemy.py +131 -0
- scope/core/config.py +530 -0
- scope/core/exceptions.py +64 -0
- scope/dependencies.py +164 -0
- scope/health.py +10 -0
- scope/interfaces/__init__.py +33 -0
- scope/interfaces/data_provider.py +61 -0
- scope/interfaces/integration_example.py +310 -0
- scope/interfaces/kg_provider.py +91 -0
- scope/interfaces/metrics_provider.py +92 -0
- scope/interfaces/models.py +185 -0
- scope/models/kg.py +48 -0
- scope/models/live_topology.py +78 -0
- scope/models/otel_traces.py +1595 -0
- scope/providers/__init__.py +277 -0
- scope/providers/_graph.py +59 -0
- scope/providers/cognition_protocols.py +178 -0
- scope/providers/kg.py +702 -0
- scope/providers/kg_query_runner.py +109 -0
- scope/providers/neo4j_mce.py +18 -0
- scope/providers/scope_metrics.py +7 -0
- scope/query_builders/__init__.py +14 -0
- scope/query_builders/cognition_protocol_graph.py +191 -0
- scope/query_builders/concepts.py +112 -0
- scope/query_builders/dal.py +931 -0
- scope/query_builders/failure_graph.py +102 -0
- scope/query_builders/features.py +5 -0
- scope/query_builders/kg.py +416 -0
- scope/query_builders/labels.py +53 -0
- scope/query_builders/live_topology.py +503 -0
- scope/query_builders/metric_graph.py +196 -0
- scope/query_builders/metrics.py +354 -0
- scope/query_builders/semanticgroups.py +46 -0
- scope/query_builders/sessions.py +208 -0
- scope/query_builders/symbolic.py +615 -0
- scope/query_builders/trajectory.py +76 -0
- scope/query_builders/types.py +20 -0
- scope/query_builders/ui.py +3278 -0
- scope/query_builders/waste_estimation.py +221 -0
- scope/repositories/__init__.py +28 -0
- scope/repositories/clickhouse_otel_repository.py +135 -0
- scope/repositories/otel_repository.py +97 -0
- scope/repositories/sqlite_repository.py +215 -0
- scope/scripts/__init__.py +2 -0
- scope/scripts/seed.py +35 -0
- scope/workarounds.py +38 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Legacy route migrations preserved at their historical API paths."""
|
|
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
|
+
|
|
15
|
+
router = APIRouter()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
|
|
19
|
+
"""Resolve a Neo4j-backed client for migrated legacy routes."""
|
|
20
|
+
return get_client(api_client=db)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@router.get("/session-reasoning-path", tags=["symbolic"])
|
|
24
|
+
def get_session_reasoning_path(
|
|
25
|
+
session_id: str = Query(
|
|
26
|
+
..., description="Session ID to build the reasoning path for"
|
|
27
|
+
),
|
|
28
|
+
symbolic_client=Depends(_client), # noqa: B008
|
|
29
|
+
) -> dict[str, Any]:
|
|
30
|
+
return symbolic_client.get_session_reasoning_path(session_id=session_id)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@router.get("/application-reasoning-path", tags=["symbolic"])
|
|
34
|
+
def get_application_reasoning_path(
|
|
35
|
+
mas_name: str = Query(..., description="MAS name (e.g. noa-trip-planner-mas)"),
|
|
36
|
+
symbolic_client=Depends(_client), # noqa: B008
|
|
37
|
+
) -> dict[str, Any]:
|
|
38
|
+
return symbolic_client.get_application_reasoning_path(mas_name=mas_name)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@router.get("/timeline-reasoning-path", tags=["symbolic"])
|
|
42
|
+
def get_timeline_reasoning_path(
|
|
43
|
+
session_id: str = Query(..., description="Session ID"),
|
|
44
|
+
symbolic_client=Depends(_client), # noqa: B008
|
|
45
|
+
) -> dict[str, Any]:
|
|
46
|
+
return symbolic_client.get_timeline_reasoning_path(session_id=session_id)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@router.get("/applications-with-stateful-eval", tags=["stateful-eval"])
|
|
50
|
+
def get_applications_with_stateful_eval(
|
|
51
|
+
start_time: int | None = Query(
|
|
52
|
+
default=None, description="Start of date range (unix epoch seconds)"
|
|
53
|
+
),
|
|
54
|
+
end_time: int | None = Query(
|
|
55
|
+
default=None, description="End of date range (unix epoch seconds)"
|
|
56
|
+
),
|
|
57
|
+
symbolic_client=Depends(_client), # noqa: B008
|
|
58
|
+
) -> list[dict[str, Any]]:
|
|
59
|
+
return symbolic_client.get_applications_with_stateful_eval(
|
|
60
|
+
start_time=start_time,
|
|
61
|
+
end_time=end_time,
|
|
62
|
+
)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /semanticgroups 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
|
|
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_neo4j_db, get_redis
|
|
17
|
+
from scope.models.otel_traces import (
|
|
18
|
+
SemanticgroupAnomalyResponse,
|
|
19
|
+
SemanticgroupConsistencyResponse,
|
|
20
|
+
SemanticgroupDetailsResponse,
|
|
21
|
+
SemanticgroupNormalBehaviorResponse,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
router = APIRouter()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
|
|
28
|
+
"""Lazily resolve the semantic-groups client from the shared Neo4j dependency."""
|
|
29
|
+
return get_client(api_client=db)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# ── Endpoints ─────────────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@router.get(
|
|
36
|
+
"/{semanticgroup_id}/normal_behavior",
|
|
37
|
+
response_model=SemanticgroupNormalBehaviorResponse,
|
|
38
|
+
)
|
|
39
|
+
def get_semanticgroup_normal_behavior(
|
|
40
|
+
semanticgroup_id: str,
|
|
41
|
+
start_time: str = Query(""),
|
|
42
|
+
end_time: str = Query(""),
|
|
43
|
+
sg_client=Depends(_client), # noqa: B008
|
|
44
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
45
|
+
) -> Any:
|
|
46
|
+
"""Return normal behaviour report for a semantic group."""
|
|
47
|
+
key = make_cache_key(
|
|
48
|
+
"semanticgroups:normal_behavior",
|
|
49
|
+
{"sg": semanticgroup_id, "start": start_time, "end": end_time},
|
|
50
|
+
)
|
|
51
|
+
return cached(
|
|
52
|
+
redis_client=redis_client,
|
|
53
|
+
key=key,
|
|
54
|
+
fetch=lambda: sg_client.get_semanticgroup_normal_behavior(
|
|
55
|
+
semanticgroup_id=semanticgroup_id,
|
|
56
|
+
start_time=start_time,
|
|
57
|
+
end_time=end_time,
|
|
58
|
+
),
|
|
59
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
60
|
+
enabled=settings.CACHE_ENABLED,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@router.get(
|
|
65
|
+
"/{semanticgroup_id}/consistency_report",
|
|
66
|
+
response_model=SemanticgroupConsistencyResponse,
|
|
67
|
+
)
|
|
68
|
+
def get_semanticgroup_consistency_report(
|
|
69
|
+
semanticgroup_id: str,
|
|
70
|
+
start_time: str = Query(""),
|
|
71
|
+
end_time: str = Query(""),
|
|
72
|
+
sg_client=Depends(_client), # noqa: B008
|
|
73
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
74
|
+
) -> Any:
|
|
75
|
+
"""Return consistency report for a semantic group."""
|
|
76
|
+
key = make_cache_key(
|
|
77
|
+
"semanticgroups:consistency_report",
|
|
78
|
+
{"sg": semanticgroup_id, "start": start_time, "end": end_time},
|
|
79
|
+
)
|
|
80
|
+
return cached(
|
|
81
|
+
redis_client=redis_client,
|
|
82
|
+
key=key,
|
|
83
|
+
fetch=lambda: sg_client.get_semanticgroup_consistency_report(
|
|
84
|
+
semanticgroup_id=semanticgroup_id,
|
|
85
|
+
start_time=start_time,
|
|
86
|
+
end_time=end_time,
|
|
87
|
+
),
|
|
88
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
89
|
+
enabled=settings.CACHE_ENABLED,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@router.get(
|
|
94
|
+
"/{semanticgroup_id}/anomaly_report", response_model=SemanticgroupAnomalyResponse
|
|
95
|
+
)
|
|
96
|
+
def get_semanticgroup_anomaly_report(
|
|
97
|
+
semanticgroup_id: str,
|
|
98
|
+
start_time: str = Query(""),
|
|
99
|
+
end_time: str = Query(""),
|
|
100
|
+
sg_client=Depends(_client), # noqa: B008
|
|
101
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
102
|
+
) -> Any:
|
|
103
|
+
"""Return anomaly report for a semantic group."""
|
|
104
|
+
key = make_cache_key(
|
|
105
|
+
"semanticgroups:anomaly_report",
|
|
106
|
+
{"sg": semanticgroup_id, "start": start_time, "end": end_time},
|
|
107
|
+
)
|
|
108
|
+
return cached(
|
|
109
|
+
redis_client=redis_client,
|
|
110
|
+
key=key,
|
|
111
|
+
fetch=lambda: sg_client.get_semanticgroup_anomaly_report(
|
|
112
|
+
semanticgroup_id=semanticgroup_id,
|
|
113
|
+
start_time=start_time,
|
|
114
|
+
end_time=end_time,
|
|
115
|
+
),
|
|
116
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
117
|
+
enabled=settings.CACHE_ENABLED,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@router.get("/{semanticgroup_id}", response_model=SemanticgroupDetailsResponse)
|
|
122
|
+
def get_semanticgroup_details(
|
|
123
|
+
semanticgroup_id: str,
|
|
124
|
+
start_time: str = Query(""),
|
|
125
|
+
end_time: str = Query(""),
|
|
126
|
+
sg_client=Depends(_client), # noqa: B008
|
|
127
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
128
|
+
) -> Any:
|
|
129
|
+
"""Return details for a semantic group."""
|
|
130
|
+
key = make_cache_key(
|
|
131
|
+
"semanticgroups:details",
|
|
132
|
+
{"sg": semanticgroup_id, "start": start_time, "end": end_time},
|
|
133
|
+
)
|
|
134
|
+
return cached(
|
|
135
|
+
redis_client=redis_client,
|
|
136
|
+
key=key,
|
|
137
|
+
fetch=lambda: sg_client.get_semanticgroup_details(
|
|
138
|
+
semanticgroup_id=semanticgroup_id,
|
|
139
|
+
start_time=start_time,
|
|
140
|
+
end_time=end_time,
|
|
141
|
+
),
|
|
142
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
143
|
+
enabled=settings.CACHE_ENABLED,
|
|
144
|
+
)
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /sessions endpoint."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
|
|
9
|
+
import redis as redis_lib
|
|
10
|
+
from fastapi import APIRouter, Depends, Query
|
|
11
|
+
|
|
12
|
+
from scope.api.api_v1.endpoints.applications import _kg_client
|
|
13
|
+
from scope.api.api_v1.endpoints.helpers import get_client
|
|
14
|
+
from scope.cache import cached, make_cache_key
|
|
15
|
+
from scope.connectors.base import Connector
|
|
16
|
+
from scope.core.config import settings
|
|
17
|
+
from scope.dependencies import get_db, get_neo4j_db, get_redis
|
|
18
|
+
from scope.models.otel_traces import (
|
|
19
|
+
AgentConversationResponse,
|
|
20
|
+
AgentDetailsResponse,
|
|
21
|
+
GraphResponse,
|
|
22
|
+
ImpactAssessmentResponse,
|
|
23
|
+
LatentSpaceResponse,
|
|
24
|
+
SessionCognitionProtocolsResponse,
|
|
25
|
+
SessionSpansResponse,
|
|
26
|
+
SessionSummaryResponse,
|
|
27
|
+
TrajectoryResponse,
|
|
28
|
+
WaterfallResponse,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
router = APIRouter()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _client(db: Connector = Depends(get_db)): # noqa: B008
|
|
35
|
+
"""Lazily resolve the UI client from the current DB dependency."""
|
|
36
|
+
return get_client(api_client=db)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _graph_client(db: Connector = Depends(get_neo4j_db)): # noqa: B008
|
|
40
|
+
"""Resolve the Neo4j-backed client for execution graph queries."""
|
|
41
|
+
return get_client(api_client=db)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@router.get("/count")
|
|
45
|
+
def get_sessions_count(
|
|
46
|
+
application_id: str = Query(
|
|
47
|
+
..., description="MAS application name (e.g. noa-trip-planner-mas)"
|
|
48
|
+
),
|
|
49
|
+
start_time: int | None = Query(
|
|
50
|
+
default=None, description="Start of date range (unix epoch seconds)"
|
|
51
|
+
),
|
|
52
|
+
end_time: int | None = Query(
|
|
53
|
+
default=None, description="End of date range (unix epoch seconds)"
|
|
54
|
+
),
|
|
55
|
+
ui_client=Depends(_graph_client), # noqa: B008
|
|
56
|
+
) -> dict[str, int]:
|
|
57
|
+
"""Return session count for an application, optionally filtered by time range."""
|
|
58
|
+
return ui_client.get_sessions_count(
|
|
59
|
+
application_id=application_id,
|
|
60
|
+
start_time=start_time,
|
|
61
|
+
end_time=end_time,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@router.get("/", response_model=SessionSummaryResponse)
|
|
66
|
+
def list_sessions(
|
|
67
|
+
start_time: Optional[str] = Query(None),
|
|
68
|
+
end_time: Optional[str] = Query(None),
|
|
69
|
+
limit: int = Query(50, ge=1),
|
|
70
|
+
offset: int = Query(0, ge=0),
|
|
71
|
+
ui_client=Depends(_client), # noqa: B008
|
|
72
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
73
|
+
) -> Any:
|
|
74
|
+
"""Return ``session_id`` + ``timestamp`` for each session."""
|
|
75
|
+
key = make_cache_key(
|
|
76
|
+
"sessions:list",
|
|
77
|
+
{"start": start_time, "end": end_time, "limit": limit, "offset": offset},
|
|
78
|
+
)
|
|
79
|
+
return cached(
|
|
80
|
+
redis_client=redis_client,
|
|
81
|
+
key=key,
|
|
82
|
+
fetch=lambda: ui_client.list_sessions(
|
|
83
|
+
start_time=start_time,
|
|
84
|
+
end_time=end_time,
|
|
85
|
+
limit=limit,
|
|
86
|
+
offset=offset,
|
|
87
|
+
),
|
|
88
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
89
|
+
enabled=settings.CACHE_ENABLED,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@router.get(
|
|
94
|
+
"/sessions/{session_id}/agent/{agent_id}/details",
|
|
95
|
+
response_model=AgentDetailsResponse,
|
|
96
|
+
)
|
|
97
|
+
def get_session_agent_details(
|
|
98
|
+
session_id: str,
|
|
99
|
+
agent_id: str,
|
|
100
|
+
ui_client=Depends(_client), # noqa: B008
|
|
101
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
102
|
+
) -> Any:
|
|
103
|
+
key = make_cache_key(
|
|
104
|
+
"sessions:agent_details",
|
|
105
|
+
{"session": session_id, "agent": agent_id},
|
|
106
|
+
)
|
|
107
|
+
return cached(
|
|
108
|
+
redis_client=redis_client,
|
|
109
|
+
key=key,
|
|
110
|
+
fetch=lambda: ui_client.get_session_agent_details(
|
|
111
|
+
session_id=session_id, agent_id=agent_id
|
|
112
|
+
),
|
|
113
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
114
|
+
enabled=settings.CACHE_ENABLED,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@router.get(
|
|
119
|
+
"/sessions/{session_id}/impact_assessment", response_model=ImpactAssessmentResponse
|
|
120
|
+
)
|
|
121
|
+
def get_session_impact_assessment(
|
|
122
|
+
session_id: str,
|
|
123
|
+
ui_client=Depends(_kg_client), # noqa: B008
|
|
124
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
125
|
+
) -> Any:
|
|
126
|
+
key = make_cache_key(
|
|
127
|
+
"sessions:impact_assessment",
|
|
128
|
+
{"session": session_id},
|
|
129
|
+
)
|
|
130
|
+
return cached(
|
|
131
|
+
redis_client=redis_client,
|
|
132
|
+
key=key,
|
|
133
|
+
fetch=lambda: ui_client.get_session_impact_assessment(session_id=session_id),
|
|
134
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
135
|
+
enabled=settings.CACHE_ENABLED,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@router.get(
|
|
140
|
+
"/{session_id}/cognition-protocols",
|
|
141
|
+
response_model=SessionCognitionProtocolsResponse,
|
|
142
|
+
)
|
|
143
|
+
def get_session_cognition_protocols(
|
|
144
|
+
session_id: str,
|
|
145
|
+
kg_client=Depends(_kg_client), # noqa: B008
|
|
146
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
147
|
+
) -> Any:
|
|
148
|
+
"""Return the Cognition protocols of a session, with the metrics of each activated protocol."""
|
|
149
|
+
key = make_cache_key("sessions:cognition_protocols", {"session": session_id})
|
|
150
|
+
return cached(
|
|
151
|
+
redis_client=redis_client,
|
|
152
|
+
key=key,
|
|
153
|
+
fetch=lambda: kg_client.get_session_cognition_protocols(session_id=session_id),
|
|
154
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
155
|
+
enabled=settings.CACHE_ENABLED,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@router.get("/{session_id}/spans", response_model=SessionSpansResponse)
|
|
160
|
+
def get_session_spans(
|
|
161
|
+
session_id: str,
|
|
162
|
+
span_types: Optional[list[str]] = Query(None, alias="spanTypes"),
|
|
163
|
+
limit: int = Query(500, ge=1),
|
|
164
|
+
offset: int = Query(0, ge=0),
|
|
165
|
+
order: str = Query("asc", pattern="^(asc|desc)$"),
|
|
166
|
+
ui_client=Depends(_client), # noqa: B008
|
|
167
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
168
|
+
) -> Any:
|
|
169
|
+
"""Return traces/spans for a session with basic filters."""
|
|
170
|
+
key = make_cache_key(
|
|
171
|
+
"sessions:spans",
|
|
172
|
+
{
|
|
173
|
+
"session": session_id,
|
|
174
|
+
"types": sorted(span_types or []),
|
|
175
|
+
"limit": limit,
|
|
176
|
+
"offset": offset,
|
|
177
|
+
"order": order,
|
|
178
|
+
},
|
|
179
|
+
)
|
|
180
|
+
return cached(
|
|
181
|
+
redis_client=redis_client,
|
|
182
|
+
key=key,
|
|
183
|
+
fetch=lambda: ui_client.get_session_spans(
|
|
184
|
+
session_ids=[session_id],
|
|
185
|
+
span_types=span_types,
|
|
186
|
+
limit=limit,
|
|
187
|
+
offset=offset,
|
|
188
|
+
order=order,
|
|
189
|
+
),
|
|
190
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
191
|
+
enabled=settings.CACHE_ENABLED,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@router.get("/{session_id}/timeline-waterfall", response_model=WaterfallResponse)
|
|
196
|
+
def get_session_timeline_waterfall(
|
|
197
|
+
session_id: str,
|
|
198
|
+
ui_client=Depends(_client), # noqa: B008
|
|
199
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
200
|
+
) -> Any:
|
|
201
|
+
"""Build a waterfall span tree for a session."""
|
|
202
|
+
key = make_cache_key("sessions:timeline_waterfall", {"session": session_id})
|
|
203
|
+
return cached(
|
|
204
|
+
redis_client=redis_client,
|
|
205
|
+
key=key,
|
|
206
|
+
fetch=lambda: ui_client.get_session_timeline_waterfall(session_id=session_id),
|
|
207
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
208
|
+
enabled=settings.CACHE_ENABLED,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@router.get("/{session_id}/timeline", response_model=GraphResponse)
|
|
213
|
+
def get_session_timeline(
|
|
214
|
+
session_id: str,
|
|
215
|
+
level: Optional[str] = Query(None),
|
|
216
|
+
ui_client=Depends(_graph_client), # noqa: B008
|
|
217
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
218
|
+
) -> Any:
|
|
219
|
+
"""Build a state-machine timeline graph for a session."""
|
|
220
|
+
key = make_cache_key("sessions:timeline", {"session": session_id, "level": level})
|
|
221
|
+
return cached(
|
|
222
|
+
redis_client=redis_client,
|
|
223
|
+
key=key,
|
|
224
|
+
fetch=lambda: ui_client.get_session_timeline(
|
|
225
|
+
session_id=session_id, level=level
|
|
226
|
+
),
|
|
227
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
228
|
+
enabled=settings.CACHE_ENABLED,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
@router.get("/{session_id}/trajectory", response_model=TrajectoryResponse)
|
|
233
|
+
def get_session_trajectory(
|
|
234
|
+
session_id: str,
|
|
235
|
+
ui_client=Depends(_client), # noqa: B008
|
|
236
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
237
|
+
) -> Any:
|
|
238
|
+
"""Trajectory."""
|
|
239
|
+
key = make_cache_key("sessions:trajectory", {"session": session_id})
|
|
240
|
+
return cached(
|
|
241
|
+
redis_client=redis_client,
|
|
242
|
+
key=key,
|
|
243
|
+
fetch=lambda: ui_client.get_session_trajectory(session_id=session_id),
|
|
244
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
245
|
+
enabled=settings.CACHE_ENABLED,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
@router.get("/{session_id}/execution-graph", response_model=GraphResponse)
|
|
250
|
+
def get_session_execution_graph(
|
|
251
|
+
session_id: str,
|
|
252
|
+
ui_client=Depends(_graph_client), # noqa: B008
|
|
253
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
254
|
+
) -> Any:
|
|
255
|
+
"""Build an execution_graph for a session."""
|
|
256
|
+
key = make_cache_key("sessions:execution_graph", {"session": session_id})
|
|
257
|
+
return cached(
|
|
258
|
+
redis_client=redis_client,
|
|
259
|
+
key=key,
|
|
260
|
+
fetch=lambda: ui_client.get_session_execution_graph(session_id=session_id),
|
|
261
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
262
|
+
enabled=settings.CACHE_ENABLED,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@router.get("/{session_id}/conversation", response_model=AgentConversationResponse)
|
|
267
|
+
def get_session_conversation(
|
|
268
|
+
session_id: str,
|
|
269
|
+
ui_client=Depends(_graph_client), # noqa: B008
|
|
270
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
271
|
+
) -> Any:
|
|
272
|
+
"""Return the ordered list of agent-level turns (the agent conversation) for a session."""
|
|
273
|
+
key = make_cache_key("sessions:conversation", {"session": session_id})
|
|
274
|
+
return cached(
|
|
275
|
+
redis_client=redis_client,
|
|
276
|
+
key=key,
|
|
277
|
+
fetch=lambda: ui_client.get_session_conversation(session_id=session_id),
|
|
278
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
279
|
+
enabled=settings.CACHE_ENABLED,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@router.get("/{session_id}/latent-space", response_model=LatentSpaceResponse)
|
|
284
|
+
def get_session_latent_space(
|
|
285
|
+
session_id: str,
|
|
286
|
+
n_neighbors: int = Query(
|
|
287
|
+
default=15,
|
|
288
|
+
ge=2,
|
|
289
|
+
le=200,
|
|
290
|
+
description="UMAP n_neighbors parameter (controls local vs global structure, will be adjusted if larger than n_samples-1)",
|
|
291
|
+
),
|
|
292
|
+
min_dist: float = Query(
|
|
293
|
+
default=0.1,
|
|
294
|
+
ge=0.0,
|
|
295
|
+
le=1.0,
|
|
296
|
+
description="UMAP min_dist parameter (controls how tightly points cluster together)",
|
|
297
|
+
),
|
|
298
|
+
ui_client=Depends(_graph_client), # noqa: B008
|
|
299
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
300
|
+
) -> Any:
|
|
301
|
+
"""
|
|
302
|
+
Get session states projected to 2D latent space using UMAP.
|
|
303
|
+
|
|
304
|
+
Projects state embeddings from the agent hierarchy level to a 2D space
|
|
305
|
+
for visualization. Uses UMAP with cosine distance metric.
|
|
306
|
+
|
|
307
|
+
Nodes: States with x,y coordinates from UMAP projection
|
|
308
|
+
Edges: Transitions between states (same as state machine graph)
|
|
309
|
+
|
|
310
|
+
The embeddings are retrieved from Embedding nodes connected to State nodes
|
|
311
|
+
via the represents relationship.
|
|
312
|
+
|
|
313
|
+
Args:
|
|
314
|
+
session_id: Session ID to fetch
|
|
315
|
+
n_neighbors: UMAP n_neighbors (default 15, auto-adjusted if needed)
|
|
316
|
+
min_dist: UMAP min_dist (default 0.1, controls clustering tightness)
|
|
317
|
+
|
|
318
|
+
Returns:
|
|
319
|
+
LatentSpaceResponse with nodes positioned in 2D space
|
|
320
|
+
|
|
321
|
+
Example:
|
|
322
|
+
GET /graph/latent-space/0c589041-888a-449d-983e-19c6af599494
|
|
323
|
+
GET /graph/latent-space/0c589041-888a-449d-983e-19c6af599494?n_neighbors=10&min_dist=0.2
|
|
324
|
+
"""
|
|
325
|
+
key = make_cache_key(
|
|
326
|
+
"sessions:latent_space",
|
|
327
|
+
{"session": session_id, "n_neighbors": n_neighbors, "min_dist": min_dist},
|
|
328
|
+
)
|
|
329
|
+
return cached(
|
|
330
|
+
redis_client=redis_client,
|
|
331
|
+
key=key,
|
|
332
|
+
fetch=lambda: ui_client.get_session_latent_space(
|
|
333
|
+
session_id=session_id,
|
|
334
|
+
n_neighbors=n_neighbors,
|
|
335
|
+
min_dist=min_dist,
|
|
336
|
+
),
|
|
337
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
338
|
+
enabled=settings.CACHE_ENABLED,
|
|
339
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""FastAPI router for the /spans 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
|
|
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_redis
|
|
17
|
+
from scope.models.otel_traces import SpanDetailsResponse
|
|
18
|
+
|
|
19
|
+
router = APIRouter()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _client(db: Connector = Depends(get_db)): # noqa: B008
|
|
23
|
+
"""Lazily resolve the UI client from the current DB dependency."""
|
|
24
|
+
return get_client(api_client=db)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@router.get("/{span_id}", response_model=SpanDetailsResponse)
|
|
28
|
+
def get_span_details(
|
|
29
|
+
span_id: str,
|
|
30
|
+
ui_client=Depends(_client), # noqa: B008
|
|
31
|
+
redis_client: redis_lib.Redis = Depends(get_redis), # noqa: B008
|
|
32
|
+
) -> Any:
|
|
33
|
+
"""Return detailed information about a single span."""
|
|
34
|
+
key = make_cache_key("spans:details", {"span": span_id})
|
|
35
|
+
return cached(
|
|
36
|
+
redis_client=redis_client,
|
|
37
|
+
key=key,
|
|
38
|
+
fetch=lambda: ui_client.get_spans(span_id=span_id),
|
|
39
|
+
ttl=settings.CACHE_TTL_SECONDS,
|
|
40
|
+
enabled=settings.CACHE_ENABLED,
|
|
41
|
+
)
|