From ab1ca16fc69f3749b8991fde6e48ea6e5fa28821 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Fri, 5 Sep 2025 14:29:54 +0100 Subject: [PATCH] Structured data loader CLI --- .../trustgraph/cli/load_structured_data.py | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/trustgraph-cli/trustgraph/cli/load_structured_data.py b/trustgraph-cli/trustgraph/cli/load_structured_data.py index 74b61d84..a19c3927 100644 --- a/trustgraph-cli/trustgraph/cli/load_structured_data.py +++ b/trustgraph-cli/trustgraph/cli/load_structured_data.py @@ -79,19 +79,50 @@ def load_structured_data( logger.error(f"Failed to read input file: {e}") raise - # Use TrustGraph prompt service for schema suggestion + # Fetch available schemas from Config API try: from trustgraph.api import Api + from trustgraph.api.types import ConfigKey api = Api(api_url) + config_api = api.config() + + # Get list of available schema keys + logger.info("Fetching available schemas from Config API...") + schema_keys = config_api.list("schema") + logger.info(f"Found {len(schema_keys)} schemas: {schema_keys}") + + if not schema_keys: + logger.warning("No schemas found in configuration") + print("No schemas available in TrustGraph configuration") + return + + # Fetch each schema definition + schemas = [] + config_keys = [ConfigKey(type="schema", key=key) for key in schema_keys] + schema_values = config_api.get(config_keys) + + for value in schema_values: + try: + # Schema values are JSON strings, parse them + schema_def = json.loads(value.value) if isinstance(value.value, str) else value.value + schemas.append(schema_def) + logger.debug(f"Loaded schema: {value.key}") + except json.JSONDecodeError as e: + logger.warning(f"Failed to parse schema {value.key}: {e}") + continue + + logger.info(f"Successfully loaded {len(schemas)} schema definitions") + + # Use TrustGraph prompt service for schema suggestion flow_api = api.flow().id("default") - # Call schema-selection prompt with placeholder schema and data sample + # Call schema-selection prompt with actual schemas and data sample logger.info("Calling TrustGraph schema-selection prompt...") response = flow_api.prompt( id="schema-selection", variables={ - "schema": "**PLACEHOLDER**", + "schemas": schemas, # Array of actual schema definitions (note: plural 'schemas') "data": sample_data } )