trustgraph-cli 2.1.14__tar.gz → 2.1.16__tar.gz
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.
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/PKG-INFO +1 -1
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/pyproject.toml +3 -0
- trustgraph_cli-2.1.16/trustgraph/cli/list_explain_traces.py +304 -0
- trustgraph_cli-2.1.16/trustgraph/cli/show_document_hierarchy.py +431 -0
- trustgraph_cli-2.1.16/trustgraph/cli/show_explain_trace.py +784 -0
- trustgraph_cli-2.1.16/trustgraph/cli_version.py +1 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph_cli.egg-info/PKG-INFO +1 -1
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph_cli.egg-info/SOURCES.txt +3 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph_cli.egg-info/entry_points.txt +3 -0
- trustgraph_cli-2.1.14/trustgraph/cli_version.py +0 -1
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/README.md +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/setup.cfg +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/__init__.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/add_library_document.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/delete_collection.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/delete_config_item.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/delete_flow_blueprint.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/delete_kg_core.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/delete_mcp_tool.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/delete_tool.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/dump_msgpack.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/dump_queues.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/get_config_item.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/get_document_content.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/get_flow_blueprint.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/get_kg_core.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/graph_to_turtle.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/init_pulsar_manager.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/init_trustgraph.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_agent.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_document_embeddings.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_document_rag.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_embeddings.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_graph_embeddings.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_graph_rag.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_llm.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_mcp_tool.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_nlp_query.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_prompt.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_row_embeddings.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_rows_query.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/invoke_structured_query.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/list_collections.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/list_config_items.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/load_doc_embeds.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/load_kg_core.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/load_knowledge.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/load_sample_documents.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/load_structured_data.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/load_turtle.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/put_config_item.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/put_flow_blueprint.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/put_kg_core.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/query_graph.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/remove_library_document.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/save_doc_embeds.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/set_collection.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/set_mcp_tool.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/set_prompt.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/set_token_costs.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/set_tool.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_config.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_flow_blueprints.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_flow_state.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_flows.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_graph.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_kg_cores.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_library_documents.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_library_processing.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_mcp_tools.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_parameter_types.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_processor_state.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_prompts.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_token_costs.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_token_rate.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/show_tools.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/start_flow.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/start_library_processing.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/stop_flow.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/stop_library_processing.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/unload_kg_core.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph/cli/verify_system_status.py +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph_cli.egg-info/requires.txt +0 -0
- {trustgraph_cli-2.1.14 → trustgraph_cli-2.1.16}/trustgraph_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trustgraph-cli
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.16
|
|
4
4
|
Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
|
|
5
5
|
Author-email: "trustgraph.ai" <security@trustgraph.ai>
|
|
6
6
|
Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
|
|
@@ -96,6 +96,9 @@ tg-delete-config-item = "trustgraph.cli.delete_config_item:main"
|
|
|
96
96
|
tg-list-collections = "trustgraph.cli.list_collections:main"
|
|
97
97
|
tg-set-collection = "trustgraph.cli.set_collection:main"
|
|
98
98
|
tg-delete-collection = "trustgraph.cli.delete_collection:main"
|
|
99
|
+
tg-show-document-hierarchy = "trustgraph.cli.show_document_hierarchy:main"
|
|
100
|
+
tg-list-explain-traces = "trustgraph.cli.list_explain_traces:main"
|
|
101
|
+
tg-show-explain-trace = "trustgraph.cli.show_explain_trace:main"
|
|
99
102
|
|
|
100
103
|
[tool.setuptools.packages.find]
|
|
101
104
|
include = ["trustgraph*"]
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"""
|
|
2
|
+
List all explainability sessions (GraphRAG and Agent) in a collection.
|
|
3
|
+
|
|
4
|
+
Queries for all questions stored in the retrieval graph and displays them
|
|
5
|
+
with their session IDs, type (GraphRAG or Agent), and timestamps.
|
|
6
|
+
|
|
7
|
+
Examples:
|
|
8
|
+
tg-list-explain-traces -U trustgraph -C default
|
|
9
|
+
tg-list-explain-traces --limit 20 --format json
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
from tabulate import tabulate
|
|
17
|
+
from trustgraph.api import Api
|
|
18
|
+
|
|
19
|
+
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
20
|
+
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
|
21
|
+
default_user = 'trustgraph'
|
|
22
|
+
default_collection = 'default'
|
|
23
|
+
|
|
24
|
+
# Predicates
|
|
25
|
+
TG = "https://trustgraph.ai/ns/"
|
|
26
|
+
TG_QUERY = TG + "query"
|
|
27
|
+
TG_QUESTION = TG + "Question"
|
|
28
|
+
TG_ANALYSIS = TG + "Analysis"
|
|
29
|
+
TG_EXPLORATION = TG + "Exploration"
|
|
30
|
+
PROV = "http://www.w3.org/ns/prov#"
|
|
31
|
+
PROV_STARTED_AT_TIME = PROV + "startedAtTime"
|
|
32
|
+
PROV_WAS_DERIVED_FROM = PROV + "wasDerivedFrom"
|
|
33
|
+
PROV_WAS_GENERATED_BY = PROV + "wasGeneratedBy"
|
|
34
|
+
RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
|
|
35
|
+
|
|
36
|
+
# Retrieval graph
|
|
37
|
+
RETRIEVAL_GRAPH = "urn:graph:retrieval"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def query_triples(socket, flow_id, user, collection, s=None, p=None, o=None, g=None, limit=1000):
|
|
41
|
+
"""Query triples using the socket API."""
|
|
42
|
+
request = {
|
|
43
|
+
"user": user,
|
|
44
|
+
"collection": collection,
|
|
45
|
+
"limit": limit,
|
|
46
|
+
"streaming": False,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if s is not None:
|
|
50
|
+
request["s"] = {"t": "i", "i": s}
|
|
51
|
+
if p is not None:
|
|
52
|
+
request["p"] = {"t": "i", "i": p}
|
|
53
|
+
if o is not None:
|
|
54
|
+
if isinstance(o, str):
|
|
55
|
+
if o.startswith("http://") or o.startswith("https://") or o.startswith("urn:"):
|
|
56
|
+
request["o"] = {"t": "i", "i": o}
|
|
57
|
+
else:
|
|
58
|
+
request["o"] = {"t": "l", "v": o}
|
|
59
|
+
elif isinstance(o, dict):
|
|
60
|
+
request["o"] = o
|
|
61
|
+
if g is not None:
|
|
62
|
+
request["g"] = g
|
|
63
|
+
|
|
64
|
+
triples = []
|
|
65
|
+
try:
|
|
66
|
+
for response in socket._send_request_sync("triples", flow_id, request, streaming_raw=True):
|
|
67
|
+
if isinstance(response, dict):
|
|
68
|
+
triple_list = response.get("response", response.get("triples", []))
|
|
69
|
+
else:
|
|
70
|
+
triple_list = response
|
|
71
|
+
|
|
72
|
+
if not isinstance(triple_list, list):
|
|
73
|
+
triple_list = [triple_list] if triple_list else []
|
|
74
|
+
|
|
75
|
+
for t in triple_list:
|
|
76
|
+
s_val = extract_value(t.get("s", {}))
|
|
77
|
+
p_val = extract_value(t.get("p", {}))
|
|
78
|
+
o_val = extract_value(t.get("o", {}))
|
|
79
|
+
triples.append((s_val, p_val, o_val))
|
|
80
|
+
except Exception as e:
|
|
81
|
+
print(f"Error querying triples: {e}", file=sys.stderr)
|
|
82
|
+
|
|
83
|
+
return triples
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def extract_value(term):
|
|
87
|
+
"""Extract value from a term dict."""
|
|
88
|
+
if not term:
|
|
89
|
+
return ""
|
|
90
|
+
|
|
91
|
+
t = term.get("t") or term.get("type")
|
|
92
|
+
|
|
93
|
+
if t == "i":
|
|
94
|
+
return term.get("i") or term.get("iri", "")
|
|
95
|
+
elif t == "l":
|
|
96
|
+
return term.get("v") or term.get("value", "")
|
|
97
|
+
elif t == "t":
|
|
98
|
+
# Quoted triple
|
|
99
|
+
tr = term.get("tr") or term.get("triple", {})
|
|
100
|
+
return {
|
|
101
|
+
"s": extract_value(tr.get("s", {})),
|
|
102
|
+
"p": extract_value(tr.get("p", {})),
|
|
103
|
+
"o": extract_value(tr.get("o", {})),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# Fallback for raw values
|
|
107
|
+
if "i" in term:
|
|
108
|
+
return term["i"]
|
|
109
|
+
if "v" in term:
|
|
110
|
+
return term["v"]
|
|
111
|
+
|
|
112
|
+
return str(term)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def get_timestamp(socket, flow_id, user, collection, question_id):
|
|
116
|
+
"""Get timestamp for a question."""
|
|
117
|
+
triples = query_triples(
|
|
118
|
+
socket, flow_id, user, collection,
|
|
119
|
+
s=question_id, p=PROV_STARTED_AT_TIME, g=RETRIEVAL_GRAPH
|
|
120
|
+
)
|
|
121
|
+
for s, p, o in triples:
|
|
122
|
+
return o
|
|
123
|
+
return ""
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def get_session_type(socket, flow_id, user, collection, session_id):
|
|
127
|
+
"""
|
|
128
|
+
Get the type of session (Agent or GraphRAG).
|
|
129
|
+
|
|
130
|
+
Both have tg:Question type, so we distinguish by URI pattern
|
|
131
|
+
or by checking what's derived from it.
|
|
132
|
+
"""
|
|
133
|
+
# Fast path: check URI pattern
|
|
134
|
+
if session_id.startswith("urn:trustgraph:agent:"):
|
|
135
|
+
return "Agent"
|
|
136
|
+
if session_id.startswith("urn:trustgraph:question:"):
|
|
137
|
+
return "GraphRAG"
|
|
138
|
+
|
|
139
|
+
# Check what's derived from this entity
|
|
140
|
+
derived = query_triples(
|
|
141
|
+
socket, flow_id, user, collection,
|
|
142
|
+
p=PROV_WAS_DERIVED_FROM, o=session_id, g=RETRIEVAL_GRAPH
|
|
143
|
+
)
|
|
144
|
+
generated = query_triples(
|
|
145
|
+
socket, flow_id, user, collection,
|
|
146
|
+
p=PROV_WAS_GENERATED_BY, o=session_id, g=RETRIEVAL_GRAPH
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
for s, p, o in derived + generated:
|
|
150
|
+
child_types = query_triples(
|
|
151
|
+
socket, flow_id, user, collection,
|
|
152
|
+
s=s, p=RDF_TYPE, g=RETRIEVAL_GRAPH
|
|
153
|
+
)
|
|
154
|
+
for _, _, child_type in child_types:
|
|
155
|
+
if child_type == TG_ANALYSIS:
|
|
156
|
+
return "Agent"
|
|
157
|
+
if child_type == TG_EXPLORATION:
|
|
158
|
+
return "GraphRAG"
|
|
159
|
+
|
|
160
|
+
return "GraphRAG"
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def list_sessions(socket, flow_id, user, collection, limit):
|
|
164
|
+
"""List all explainability sessions (GraphRAG and Agent) by finding questions."""
|
|
165
|
+
# Query for all triples with predicate = tg:query
|
|
166
|
+
triples = query_triples(
|
|
167
|
+
socket, flow_id, user, collection,
|
|
168
|
+
p=TG_QUERY, g=RETRIEVAL_GRAPH, limit=limit
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
sessions = []
|
|
172
|
+
for question_id, _, query_text in triples:
|
|
173
|
+
# Get timestamp if available
|
|
174
|
+
timestamp = get_timestamp(socket, flow_id, user, collection, question_id)
|
|
175
|
+
# Get session type (Agent or GraphRAG)
|
|
176
|
+
session_type = get_session_type(socket, flow_id, user, collection, question_id)
|
|
177
|
+
|
|
178
|
+
sessions.append({
|
|
179
|
+
"id": question_id,
|
|
180
|
+
"type": session_type,
|
|
181
|
+
"question": query_text,
|
|
182
|
+
"time": timestamp,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
# Sort by timestamp (newest first) if available
|
|
186
|
+
sessions.sort(key=lambda x: x.get("time", ""), reverse=True)
|
|
187
|
+
|
|
188
|
+
return sessions
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def truncate_text(text, max_len=60):
|
|
192
|
+
"""Truncate text to max length with ellipsis."""
|
|
193
|
+
if not text:
|
|
194
|
+
return ""
|
|
195
|
+
if len(text) <= max_len:
|
|
196
|
+
return text
|
|
197
|
+
return text[:max_len - 3] + "..."
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def print_table(sessions):
|
|
201
|
+
"""Print sessions as a table."""
|
|
202
|
+
if not sessions:
|
|
203
|
+
print("No explainability sessions found.")
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
rows = []
|
|
207
|
+
for session in sessions:
|
|
208
|
+
rows.append([
|
|
209
|
+
session["id"],
|
|
210
|
+
session.get("type", "Unknown"),
|
|
211
|
+
truncate_text(session["question"], 45),
|
|
212
|
+
session.get("time", "")
|
|
213
|
+
])
|
|
214
|
+
|
|
215
|
+
headers = ["Session ID", "Type", "Question", "Time"]
|
|
216
|
+
print(tabulate(rows, headers=headers, tablefmt="simple"))
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def print_json(sessions):
|
|
220
|
+
"""Print sessions as JSON."""
|
|
221
|
+
print(json.dumps(sessions, indent=2))
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def main():
|
|
225
|
+
parser = argparse.ArgumentParser(
|
|
226
|
+
prog='tg-list-explain-traces',
|
|
227
|
+
description=__doc__,
|
|
228
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
parser.add_argument(
|
|
232
|
+
'-u', '--api-url',
|
|
233
|
+
default=default_url,
|
|
234
|
+
help=f'API URL (default: {default_url})',
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
parser.add_argument(
|
|
238
|
+
'-t', '--token',
|
|
239
|
+
default=default_token,
|
|
240
|
+
help='Auth token (default: $TRUSTGRAPH_TOKEN)',
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
parser.add_argument(
|
|
244
|
+
'-U', '--user',
|
|
245
|
+
default=default_user,
|
|
246
|
+
help=f'User ID (default: {default_user})',
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
parser.add_argument(
|
|
250
|
+
'-C', '--collection',
|
|
251
|
+
default=default_collection,
|
|
252
|
+
help=f'Collection (default: {default_collection})',
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
parser.add_argument(
|
|
256
|
+
'-f', '--flow-id',
|
|
257
|
+
default='default',
|
|
258
|
+
help='Flow ID (default: default)',
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
parser.add_argument(
|
|
262
|
+
'--limit',
|
|
263
|
+
type=int,
|
|
264
|
+
default=50,
|
|
265
|
+
help='Max results (default: 50)',
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
parser.add_argument(
|
|
269
|
+
'--format',
|
|
270
|
+
choices=['table', 'json'],
|
|
271
|
+
default='table',
|
|
272
|
+
help='Output format: table (default), json',
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
args = parser.parse_args()
|
|
276
|
+
|
|
277
|
+
try:
|
|
278
|
+
api = Api(args.api_url, token=args.token)
|
|
279
|
+
socket = api.socket()
|
|
280
|
+
|
|
281
|
+
try:
|
|
282
|
+
sessions = list_sessions(
|
|
283
|
+
socket=socket,
|
|
284
|
+
flow_id=args.flow_id,
|
|
285
|
+
user=args.user,
|
|
286
|
+
collection=args.collection,
|
|
287
|
+
limit=args.limit,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
if args.format == 'json':
|
|
291
|
+
print_json(sessions)
|
|
292
|
+
else:
|
|
293
|
+
print_table(sessions)
|
|
294
|
+
|
|
295
|
+
finally:
|
|
296
|
+
socket.close()
|
|
297
|
+
|
|
298
|
+
except Exception as e:
|
|
299
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
300
|
+
sys.exit(1)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
if __name__ == "__main__":
|
|
304
|
+
main()
|