mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-09 05:12:12 +02:00
Remove Pulsar-specific concepts from application code so that the pub/sub backend is swappable via configuration. Rename translators: - to_pulsar/from_pulsar → decode/encode across all translator classes, dispatch handlers, and tests (55+ files) - from_response_with_completion → encode_with_completion - Remove pulsar.schema.Record from translator base class Queue naming (CLASS:TOPICSPACE:TOPIC): - Replace topic() helper with queue() using new format: flow:tg:name, request:tg:name, response:tg:name, state:tg:name - Queue class implies persistence/TTL (no QoS in names) - Update Pulsar backend map_topic() to parse new format - Librarian queues use flow class (persistent, for chunking) - Config push uses state class (persistent, last-value) - Remove 15 dead topic imports from schema files - Update init_trustgraph.py namespace: config → state Confine Pulsar to pulsar_backend.py: - Delete legacy PulsarClient class from pubsub.py - Move add_args to add_pubsub_args() with standalone flag for CLI tools (defaults to localhost) - PulsarBackendConsumer.receive() catches _pulsar.Timeout, raises standard TimeoutError - Remove Pulsar imports from: async_processor, flow_processor, log_level, all 11 client files, 4 storage writers, gateway service, gateway config receiver - Remove log_level/LoggerLevel from client API - Rewrite tg-monitor-prompts to use backend abstraction - Update tg-dump-queues to use add_pubsub_args Also: pubsub-abstraction.md tech spec covering problem statement, design goals, as-is requirements, candidate broker assessment, approach, and implementation order.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import json
|
|
from typing import Dict, Any, Tuple
|
|
from ...schema import ToolRequest, ToolResponse
|
|
from .base import MessageTranslator
|
|
|
|
class ToolRequestTranslator(MessageTranslator):
|
|
"""Translator for ToolRequest schema objects"""
|
|
|
|
def decode(self, data: Dict[str, Any]) -> ToolRequest:
|
|
# Handle both "name" and "parameters" input keys
|
|
name = data.get("name", "")
|
|
if "parameters" in data:
|
|
parameters = json.dumps(data["parameters"])
|
|
else:
|
|
parameters = None
|
|
|
|
return ToolRequest(
|
|
name = name,
|
|
parameters = parameters,
|
|
)
|
|
|
|
def encode(self, obj: ToolRequest) -> Dict[str, Any]:
|
|
result = {}
|
|
|
|
if obj.name:
|
|
result["name"] = obj.name
|
|
if obj.parameters is not None:
|
|
result["parameters"] = json.loads(obj.parameters)
|
|
|
|
return result
|
|
|
|
class ToolResponseTranslator(MessageTranslator):
|
|
"""Translator for ToolResponse schema objects"""
|
|
|
|
def decode(self, data: Dict[str, Any]) -> ToolResponse:
|
|
raise NotImplementedError("Response translation to Pulsar not typically needed")
|
|
|
|
def encode(self, obj: ToolResponse) -> Dict[str, Any]:
|
|
|
|
result = {}
|
|
|
|
if obj.text:
|
|
result["text"] = obj.text
|
|
if obj.object:
|
|
result["object"] = json.loads(obj.object)
|
|
|
|
return result
|
|
|
|
def encode_with_completion(self, obj: ToolResponse) -> Tuple[Dict[str, Any], bool]:
|
|
"""Returns (response_dict, is_final)"""
|
|
return self.encode(obj), True
|