trustgraph-cli 2.2.14__tar.gz → 2.2.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.
Files changed (86) hide show
  1. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/PKG-INFO +1 -1
  2. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/dump_queues.py +15 -34
  3. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/init_trustgraph.py +54 -34
  4. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/monitor_prompts.py +39 -53
  5. trustgraph_cli-2.2.16/trustgraph/cli_version.py +1 -0
  6. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph_cli.egg-info/PKG-INFO +1 -1
  7. trustgraph_cli-2.2.14/trustgraph/cli_version.py +0 -1
  8. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/README.md +0 -0
  9. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/pyproject.toml +0 -0
  10. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/setup.cfg +0 -0
  11. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/__init__.py +0 -0
  12. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/add_library_document.py +0 -0
  13. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/delete_collection.py +0 -0
  14. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/delete_config_item.py +0 -0
  15. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/delete_flow_blueprint.py +0 -0
  16. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/delete_kg_core.py +0 -0
  17. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/delete_mcp_tool.py +0 -0
  18. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/delete_tool.py +0 -0
  19. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/dump_msgpack.py +0 -0
  20. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/get_config_item.py +0 -0
  21. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/get_document_content.py +0 -0
  22. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/get_flow_blueprint.py +0 -0
  23. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/get_kg_core.py +0 -0
  24. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/graph_to_turtle.py +0 -0
  25. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/init_pulsar_manager.py +0 -0
  26. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_agent.py +0 -0
  27. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_document_embeddings.py +0 -0
  28. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_document_rag.py +0 -0
  29. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_embeddings.py +0 -0
  30. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_graph_embeddings.py +0 -0
  31. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_graph_rag.py +0 -0
  32. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_llm.py +0 -0
  33. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_mcp_tool.py +0 -0
  34. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_nlp_query.py +0 -0
  35. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_prompt.py +0 -0
  36. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_row_embeddings.py +0 -0
  37. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_rows_query.py +0 -0
  38. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/invoke_structured_query.py +0 -0
  39. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/list_collections.py +0 -0
  40. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/list_config_items.py +0 -0
  41. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/list_explain_traces.py +0 -0
  42. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/load_doc_embeds.py +0 -0
  43. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/load_kg_core.py +0 -0
  44. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/load_knowledge.py +0 -0
  45. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/load_sample_documents.py +0 -0
  46. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/load_structured_data.py +0 -0
  47. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/load_turtle.py +0 -0
  48. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/put_config_item.py +0 -0
  49. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/put_flow_blueprint.py +0 -0
  50. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/put_kg_core.py +0 -0
  51. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/query_graph.py +0 -0
  52. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/remove_library_document.py +0 -0
  53. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/save_doc_embeds.py +0 -0
  54. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/set_collection.py +0 -0
  55. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/set_mcp_tool.py +0 -0
  56. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/set_prompt.py +0 -0
  57. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/set_token_costs.py +0 -0
  58. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/set_tool.py +0 -0
  59. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_config.py +0 -0
  60. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_explain_trace.py +0 -0
  61. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_extraction_provenance.py +0 -0
  62. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_flow_blueprints.py +0 -0
  63. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_flow_state.py +0 -0
  64. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_flows.py +0 -0
  65. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_graph.py +0 -0
  66. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_kg_cores.py +0 -0
  67. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_library_documents.py +0 -0
  68. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_library_processing.py +0 -0
  69. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_mcp_tools.py +0 -0
  70. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_parameter_types.py +0 -0
  71. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_processor_state.py +0 -0
  72. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_prompts.py +0 -0
  73. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_token_costs.py +0 -0
  74. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_token_rate.py +0 -0
  75. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/show_tools.py +0 -0
  76. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/start_flow.py +0 -0
  77. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/start_library_processing.py +0 -0
  78. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/stop_flow.py +0 -0
  79. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/stop_library_processing.py +0 -0
  80. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/unload_kg_core.py +0 -0
  81. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph/cli/verify_system_status.py +0 -0
  82. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph_cli.egg-info/SOURCES.txt +0 -0
  83. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
  84. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph_cli.egg-info/entry_points.txt +0 -0
  85. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.16}/trustgraph_cli.egg-info/requires.txt +0 -0
  86. {trustgraph_cli-2.2.14 → trustgraph_cli-2.2.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.2.14
3
+ Version: 2.2.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
@@ -8,8 +8,6 @@ message flows, diagnosing stuck services, and understanding system behavior.
8
8
  Uses TrustGraph's Subscriber abstraction for future-proof pub/sub compatibility.
9
9
  """
10
10
 
11
- import pulsar
12
- from pulsar.schema import BytesSchema
13
11
  import sys
14
12
  import json
15
13
  import asyncio
@@ -17,7 +15,7 @@ from datetime import datetime
17
15
  import argparse
18
16
 
19
17
  from trustgraph.base.subscriber import Subscriber
20
- from trustgraph.base.pubsub import get_pubsub
18
+ from trustgraph.base.pubsub import get_pubsub, add_pubsub_args
21
19
 
22
20
  def decode_json_strings(obj):
23
21
  """Recursively decode JSON-encoded string values within a dict/list."""
@@ -172,15 +170,13 @@ async def log_writer(central_queue, file_handle, shutdown_event, console_output=
172
170
  break
173
171
 
174
172
 
175
- async def async_main(queues, output_file, pulsar_host, listener_name, subscriber_name, append_mode):
173
+ async def async_main(queues, output_file, subscriber_name, append_mode, **pubsub_config):
176
174
  """
177
175
  Main async function to monitor multiple queues concurrently.
178
176
 
179
177
  Args:
180
178
  queues: List of queue names to monitor
181
179
  output_file: Path to output file
182
- pulsar_host: Pulsar connection URL
183
- listener_name: Pulsar listener name
184
180
  subscriber_name: Base name for subscribers
185
181
  append_mode: Whether to append to existing file
186
182
  """
@@ -194,9 +190,9 @@ async def async_main(queues, output_file, pulsar_host, listener_name, subscriber
194
190
 
195
191
  # Create backend connection
196
192
  try:
197
- backend = get_pubsub(pulsar_host=pulsar_host, pulsar_listener=listener_name, pubsub_backend='pulsar')
193
+ backend = get_pubsub(**pubsub_config)
198
194
  except Exception as e:
199
- print(f"Error connecting to backend at {pulsar_host}: {e}", file=sys.stderr)
195
+ print(f"Error connecting to backend: {e}", file=sys.stderr)
200
196
  sys.exit(1)
201
197
 
202
198
  # Create Subscribers and central queue
@@ -291,25 +287,20 @@ def main():
291
287
  description='Monitor and dump messages from multiple Pulsar queues',
292
288
  epilog="""
293
289
  Examples:
294
- # Monitor agent and prompt queues
295
- tg-dump-queues non-persistent://tg/request/agent:default \\
296
- non-persistent://tg/request/prompt:default
290
+ # Monitor agent and prompt flow queues
291
+ tg-dump-queues flow:tg:agent-request:default \\
292
+ flow:tg:prompt-request:default
297
293
 
298
294
  # Monitor with custom output file
299
- tg-dump-queues non-persistent://tg/request/agent:default \\
295
+ tg-dump-queues flow:tg:agent-request:default \\
300
296
  --output debug.log
301
297
 
302
298
  # Append to existing log file
303
- tg-dump-queues non-persistent://tg/request/agent:default \\
299
+ tg-dump-queues flow:tg:agent-request:default \\
304
300
  --output queue.log --append
305
301
 
306
- Common queue patterns:
307
- - Agent requests: non-persistent://tg/request/agent:default
308
- - Agent responses: non-persistent://tg/response/agent:default
309
- - Prompt requests: non-persistent://tg/request/prompt:default
310
- - Prompt responses: non-persistent://tg/response/prompt:default
311
- - LLM requests: non-persistent://tg/request/text-completion:default
312
- - LLM responses: non-persistent://tg/response/text-completion:default
302
+ # Raw Pulsar URIs also accepted
303
+ tg-dump-queues persistent://tg/flow/agent-request:default
313
304
 
314
305
  IMPORTANT:
315
306
  This tool subscribes to queues without a schema (schema-less mode). To avoid
@@ -340,17 +331,7 @@ IMPORTANT:
340
331
  help='Append to output file instead of overwriting'
341
332
  )
342
333
 
343
- parser.add_argument(
344
- '--pulsar-host',
345
- default='pulsar://localhost:6650',
346
- help='Pulsar host URL (default: pulsar://localhost:6650)'
347
- )
348
-
349
- parser.add_argument(
350
- '--listener-name',
351
- default='localhost',
352
- help='Pulsar listener name (default: localhost)'
353
- )
334
+ add_pubsub_args(parser, standalone=True)
354
335
 
355
336
  parser.add_argument(
356
337
  '--subscriber',
@@ -371,10 +352,10 @@ IMPORTANT:
371
352
  asyncio.run(async_main(
372
353
  queues=queues,
373
354
  output_file=args.output,
374
- pulsar_host=args.pulsar_host,
375
- listener_name=args.listener_name,
376
355
  subscriber_name=args.subscriber,
377
- append_mode=args.append
356
+ append_mode=args.append,
357
+ **{k: v for k, v in vars(args).items()
358
+ if k not in ('queues', 'output', 'subscriber', 'append')},
378
359
  ))
379
360
  except KeyboardInterrupt:
380
361
  # Already handled in async_main
@@ -1,5 +1,8 @@
1
1
  """
2
- Initialises Pulsar with Trustgraph tenant / namespaces & policy.
2
+ Initialises TrustGraph pub/sub infrastructure and pushes initial config.
3
+
4
+ For Pulsar: creates tenant, namespaces, and retention policies.
5
+ For RabbitMQ: queues are auto-declared, so only config push is needed.
3
6
  """
4
7
 
5
8
  import requests
@@ -8,10 +11,11 @@ import argparse
8
11
  import json
9
12
 
10
13
  from trustgraph.clients.config_client import ConfigClient
14
+ from trustgraph.base.pubsub import add_pubsub_args
11
15
 
12
16
  default_pulsar_admin_url = "http://pulsar:8080"
13
- default_pulsar_host = "pulsar://pulsar:6650"
14
- subscriber = "tg-init-pulsar"
17
+ subscriber = "tg-init-pubsub"
18
+
15
19
 
16
20
  def get_clusters(url):
17
21
 
@@ -65,12 +69,11 @@ def ensure_namespace(url, tenant, namespace, config):
65
69
 
66
70
  print(f"Namespace {tenant}/{namespace} created.", flush=True)
67
71
 
68
- def ensure_config(config, pulsar_host, pulsar_api_key):
72
+ def ensure_config(config, **pubsub_config):
69
73
 
70
74
  cli = ConfigClient(
71
75
  subscriber=subscriber,
72
- pulsar_host=pulsar_host,
73
- pulsar_api_key=pulsar_api_key,
76
+ **pubsub_config,
74
77
  )
75
78
 
76
79
  while True:
@@ -115,11 +118,9 @@ def ensure_config(config, pulsar_host, pulsar_api_key):
115
118
  time.sleep(2)
116
119
  print("Retrying...", flush=True)
117
120
  continue
118
-
119
- def init(
120
- pulsar_admin_url, pulsar_host, pulsar_api_key, tenant,
121
- config, config_file,
122
- ):
121
+
122
+ def init_pulsar(pulsar_admin_url, tenant):
123
+ """Pulsar-specific setup: create tenant, namespaces, retention policies."""
123
124
 
124
125
  clusters = get_clusters(pulsar_admin_url)
125
126
 
@@ -137,7 +138,7 @@ def init(
137
138
  }
138
139
  })
139
140
 
140
- ensure_namespace(pulsar_admin_url, tenant, "config", {
141
+ ensure_namespace(pulsar_admin_url, tenant, "state", {
141
142
  "retention_policies": {
142
143
  "retentionSizeInMB": 10,
143
144
  "retentionTimeInMinutes": -1,
@@ -145,17 +146,21 @@ def init(
145
146
  }
146
147
  })
147
148
 
148
- if config is not None:
149
+
150
+ def push_config(config_json, config_file, **pubsub_config):
151
+ """Push initial config if provided."""
152
+
153
+ if config_json is not None:
149
154
 
150
155
  try:
151
156
  print("Decoding config...", flush=True)
152
- dec = json.loads(config)
157
+ dec = json.loads(config_json)
153
158
  print("Decoded.", flush=True)
154
159
  except Exception as e:
155
160
  print("Exception:", e, flush=True)
156
161
  raise e
157
162
 
158
- ensure_config(dec, pulsar_host, pulsar_api_key)
163
+ ensure_config(dec, **pubsub_config)
159
164
 
160
165
  elif config_file is not None:
161
166
 
@@ -167,11 +172,12 @@ def init(
167
172
  print("Exception:", e, flush=True)
168
173
  raise e
169
174
 
170
- ensure_config(dec, pulsar_host, pulsar_api_key)
175
+ ensure_config(dec, **pubsub_config)
171
176
 
172
177
  else:
173
178
  print("No config to update.", flush=True)
174
179
 
180
+
175
181
  def main():
176
182
 
177
183
  parser = argparse.ArgumentParser(
@@ -180,22 +186,11 @@ def main():
180
186
  )
181
187
 
182
188
  parser.add_argument(
183
- '-p', '--pulsar-admin-url',
189
+ '--pulsar-admin-url',
184
190
  default=default_pulsar_admin_url,
185
191
  help=f'Pulsar admin URL (default: {default_pulsar_admin_url})',
186
192
  )
187
193
 
188
- parser.add_argument(
189
- '--pulsar-host',
190
- default=default_pulsar_host,
191
- help=f'Pulsar host (default: {default_pulsar_host})',
192
- )
193
-
194
- parser.add_argument(
195
- '--pulsar-api-key',
196
- help=f'Pulsar API key',
197
- )
198
-
199
194
  parser.add_argument(
200
195
  '-c', '--config',
201
196
  help=f'Initial configuration to load',
@@ -212,18 +207,43 @@ def main():
212
207
  help=f'Tenant (default: tg)',
213
208
  )
214
209
 
210
+ add_pubsub_args(parser)
211
+
215
212
  args = parser.parse_args()
216
213
 
214
+ backend_type = args.pubsub_backend
215
+
216
+ # Extract pubsub config from args
217
+ pubsub_config = {
218
+ k: v for k, v in vars(args).items()
219
+ if k not in ('pulsar_admin_url', 'config', 'config_file', 'tenant')
220
+ }
221
+
217
222
  while True:
218
223
 
219
224
  try:
220
225
 
221
- print(flush=True)
222
- print(
223
- f"Initialising with Pulsar {args.pulsar_admin_url}...",
224
- flush=True
226
+ # Pulsar-specific setup (tenants, namespaces)
227
+ if backend_type == 'pulsar':
228
+ print(flush=True)
229
+ print(
230
+ f"Initialising Pulsar at {args.pulsar_admin_url}...",
231
+ flush=True,
232
+ )
233
+ init_pulsar(args.pulsar_admin_url, args.tenant)
234
+ else:
235
+ print(flush=True)
236
+ print(
237
+ f"Using {backend_type} backend (no admin setup needed).",
238
+ flush=True,
239
+ )
240
+
241
+ # Push config (works with any backend)
242
+ push_config(
243
+ args.config, args.config_file,
244
+ **pubsub_config,
225
245
  )
226
- init(**vars(args))
246
+
227
247
  print("Initialisation complete.", flush=True)
228
248
  break
229
249
 
@@ -236,4 +256,4 @@ def main():
236
256
  print("Will retry...", flush=True)
237
257
 
238
258
  if __name__ == "__main__":
239
- main()
259
+ main()
@@ -1,7 +1,7 @@
1
1
  """
2
2
  Monitor prompt request/response queues and log activity with timing.
3
3
 
4
- Subscribes to prompt request and response Pulsar queues, correlates
4
+ Subscribes to prompt request and response queues, correlates
5
5
  them by message ID, and logs a summary of each request/response with
6
6
  elapsed time. Streaming responses are accumulated and shown once at
7
7
  completion.
@@ -19,8 +19,7 @@ import argparse
19
19
  from datetime import datetime
20
20
  from collections import OrderedDict
21
21
 
22
- import pulsar
23
- from pulsar.schema import BytesSchema
22
+ from trustgraph.base.pubsub import get_pubsub, add_pubsub_args
24
23
 
25
24
 
26
25
  default_flow = "default"
@@ -85,7 +84,7 @@ def format_terms(terms, max_lines, max_width):
85
84
 
86
85
 
87
86
  def parse_raw_message(msg):
88
- """Parse a raw Pulsar message into (correlation_id, body_dict)."""
87
+ """Parse a raw message into (correlation_id, body_dict)."""
89
88
  try:
90
89
  props = msg.properties()
91
90
  corr_id = props.get("id", "")
@@ -94,53 +93,46 @@ def parse_raw_message(msg):
94
93
 
95
94
  try:
96
95
  value = msg.value()
97
- if isinstance(value, bytes):
98
- value = value.decode("utf-8")
99
- body = json.loads(value) if isinstance(value, str) else {}
96
+ if isinstance(value, dict):
97
+ body = value
98
+ elif isinstance(value, bytes):
99
+ body = json.loads(value.decode("utf-8"))
100
+ elif isinstance(value, str):
101
+ body = json.loads(value)
102
+ else:
103
+ body = {}
100
104
  except Exception:
101
105
  body = {}
102
106
 
103
107
  return corr_id, body
104
108
 
105
109
 
106
- def receive_with_timeout(consumer, timeout_ms=500):
107
- """Receive a message with timeout, returning None on timeout."""
108
- try:
109
- return consumer.receive(timeout_millis=timeout_ms)
110
- except Exception:
111
- return None
112
-
113
-
114
- async def monitor(flow, queue_type, max_lines, max_width,
115
- pulsar_host, listener_name):
110
+ async def monitor(flow, queue_type, max_lines, max_width, **config):
116
111
 
117
- request_queue = f"non-persistent://tg/request/{queue_type}:{flow}"
118
- response_queue = f"non-persistent://tg/response/{queue_type}:{flow}"
112
+ request_queue = f"request:tg:{queue_type}:{flow}"
113
+ response_queue = f"response:tg:{queue_type}:{flow}"
119
114
 
120
115
  print(f"Monitoring prompt queues:")
121
116
  print(f" Request: {request_queue}")
122
117
  print(f" Response: {response_queue}")
123
118
  print(f"Press Ctrl+C to stop\n")
124
119
 
125
- client = pulsar.Client(
126
- pulsar_host,
127
- listener_name=listener_name,
128
- )
120
+ backend = get_pubsub(**config)
129
121
 
130
- req_consumer = client.subscribe(
131
- request_queue,
132
- subscription_name="prompt-monitor-req",
133
- consumer_type=pulsar.ConsumerType.Shared,
134
- schema=BytesSchema(),
135
- initial_position=pulsar.InitialPosition.Latest,
122
+ req_consumer = backend.create_consumer(
123
+ topic=request_queue,
124
+ subscription="prompt-monitor-req",
125
+ schema=None,
126
+ consumer_type='shared',
127
+ initial_position='latest',
136
128
  )
137
129
 
138
- resp_consumer = client.subscribe(
139
- response_queue,
140
- subscription_name="prompt-monitor-resp",
141
- consumer_type=pulsar.ConsumerType.Shared,
142
- schema=BytesSchema(),
143
- initial_position=pulsar.InitialPosition.Latest,
130
+ resp_consumer = backend.create_consumer(
131
+ topic=response_queue,
132
+ subscription="prompt-monitor-resp",
133
+ schema=None,
134
+ consumer_type='shared',
135
+ initial_position='latest',
144
136
  )
145
137
 
146
138
  # Track in-flight requests: corr_id -> (timestamp, template_id)
@@ -156,8 +148,8 @@ async def monitor(flow, queue_type, max_lines, max_width,
156
148
  got_message = False
157
149
 
158
150
  # Poll request queue
159
- msg = receive_with_timeout(req_consumer, 100)
160
- if msg:
151
+ try:
152
+ msg = req_consumer.receive(timeout_millis=100)
161
153
  got_message = True
162
154
  timestamp = datetime.now()
163
155
  corr_id, body = parse_raw_message(msg)
@@ -182,10 +174,12 @@ async def monitor(flow, queue_type, max_lines, max_width,
182
174
  print(format_terms(terms, max_lines, max_width))
183
175
 
184
176
  req_consumer.acknowledge(msg)
177
+ except TimeoutError:
178
+ pass
185
179
 
186
180
  # Poll response queue
187
- msg = receive_with_timeout(resp_consumer, 100)
188
- if msg:
181
+ try:
182
+ msg = resp_consumer.receive(timeout_millis=100)
189
183
  got_message = True
190
184
  timestamp = datetime.now()
191
185
  corr_id, body = parse_raw_message(msg)
@@ -265,6 +259,8 @@ async def monitor(flow, queue_type, max_lines, max_width,
265
259
  print(f" {truncated}")
266
260
 
267
261
  resp_consumer.acknowledge(msg)
262
+ except TimeoutError:
263
+ pass
268
264
 
269
265
  if not got_message:
270
266
  await asyncio.sleep(0.05)
@@ -274,7 +270,7 @@ async def monitor(flow, queue_type, max_lines, max_width,
274
270
  finally:
275
271
  req_consumer.close()
276
272
  resp_consumer.close()
277
- client.close()
273
+ backend.close()
278
274
 
279
275
 
280
276
  def main():
@@ -310,17 +306,7 @@ def main():
310
306
  help=f"Max width per line (default: {default_max_width})",
311
307
  )
312
308
 
313
- parser.add_argument(
314
- "--pulsar-host",
315
- default="pulsar://localhost:6650",
316
- help="Pulsar host URL (default: pulsar://localhost:6650)",
317
- )
318
-
319
- parser.add_argument(
320
- "--listener-name",
321
- default="localhost",
322
- help="Pulsar listener name (default: localhost)",
323
- )
309
+ add_pubsub_args(parser, standalone=True)
324
310
 
325
311
  args = parser.parse_args()
326
312
 
@@ -330,8 +316,8 @@ def main():
330
316
  queue_type=args.queue_type,
331
317
  max_lines=args.max_lines,
332
318
  max_width=args.max_width,
333
- pulsar_host=args.pulsar_host,
334
- listener_name=args.listener_name,
319
+ **{k: v for k, v in vars(args).items()
320
+ if k not in ('flow', 'queue_type', 'max_lines', 'max_width')},
335
321
  ))
336
322
  except KeyboardInterrupt:
337
323
  pass
@@ -0,0 +1 @@
1
+ __version__ = "2.2.16"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trustgraph-cli
3
- Version: 2.2.14
3
+ Version: 2.2.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
@@ -1 +0,0 @@
1
- __version__ = "2.2.14"