hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

status.mojo (6434B)


      1 from json import Value, loads
      2 
      3 from hyf_assist.contract import max_local_query_rewrite_route
      4 from hyf_runtime.config import assisted_runtime_configured
      5 from hyf_runtime.diagnostics import (
      6     diagnostics_debug_override_dir_from_env,
      7     effective_diagnostics_dir_for_runtime_paths,
      8 )
      9 from hyf_runtime.secrets import (
     10     default_secret_backend_name,
     11     identity_material_configured_for_runtime_paths,
     12     identity_material_created_by_startup,
     13     identity_material_loaded,
     14     protected_local_data_configured_for_runtime_paths,
     15     protected_local_data_dir_for_runtime_paths,
     16     protected_local_data_support_implemented,
     17     protected_local_data_status_name,
     18     protected_local_data_store_open,
     19     secret_storage_backend_implemented,
     20     secret_storage_status_name,
     21 )
     22 from hyf_runtime.startup import RuntimeStartupContext
     23 
     24 
     25 def _runtime_paths_status_value(context: RuntimeStartupContext) raises -> Value:
     26     var paths = loads("{}")
     27     paths.set("config_dir", Value(String(context.paths.config_dir)))
     28     paths.set("config_path", Value(String(context.paths.config_path)))
     29     paths.set("data_dir", Value(String(context.paths.data_dir)))
     30     paths.set("cache_dir", Value(String(context.paths.cache_dir)))
     31     paths.set("logs_dir", Value(String(context.paths.logs_dir)))
     32     paths.set("diagnostics_dir", Value(String(context.paths.diagnostics_dir)))
     33     paths.set("run_dir", Value(String(context.paths.run_dir)))
     34     paths.set("secrets_dir", Value(String(context.paths.secrets_dir)))
     35     paths.set("identity_path", Value(String(context.paths.identity_path)))
     36     return paths^
     37 
     38 
     39 def build_runtime_status_value(context: RuntimeStartupContext) raises -> Value:
     40     var status = loads("{}")
     41     status.set("id", Value("hyf_runtime"))
     42     status.set("namespace", Value(String(context.paths.namespace)))
     43     status.set("paths_profile", Value(String(context.paths_profile)))
     44     status.set(
     45         "repo_local_base_root", Value(String(context.repo_local_base_root))
     46     )
     47     status.set("paths", _runtime_paths_status_value(context))
     48 
     49     var config = loads("{}")
     50     config.set("artifact_path", Value(String(context.startup_config_path)))
     51     config.set(
     52         "artifact_path_source",
     53         Value(String(context.startup_config_path_source)),
     54     )
     55     config.set("artifact_present", Value(context.config.artifact_present))
     56     config.set("loaded", Value(context.config.loaded))
     57     config.set("load_state", Value(String(context.config.load_state)))
     58     config.set(
     59         "compiled_defaults_active",
     60         Value(context.config.compiled_defaults_active),
     61     )
     62     if context.config.load_error != "":
     63         config.set("load_error", Value(String(context.config.load_error)))
     64 
     65     var effective = loads("{}")
     66     effective.set(
     67         "service_transport",
     68         Value(String(context.config.effective.service.transport)),
     69     )
     70     effective.set(
     71         "default_execution_mode",
     72         Value(String(context.config.effective.runtime.default_execution_mode)),
     73     )
     74     effective.set(
     75         "allow_assisted",
     76         Value(context.config.effective.runtime.allow_assisted),
     77     )
     78     effective.set(
     79         "assisted_runtime_enabled",
     80         Value(context.config.effective.runtime.allow_assisted),
     81     )
     82     effective.set(
     83         "assisted_runtime_configured",
     84         Value(assisted_runtime_configured(context.config)),
     85     )
     86     effective.set(
     87         "assisted_provider",
     88         Value(String(context.config.effective.assisted.provider)),
     89     )
     90     effective.set(
     91         "max_local_enabled",
     92         Value(context.config.effective.assisted.max_local.enabled),
     93     )
     94     effective.set(
     95         "max_local_model",
     96         Value(String(context.config.effective.assisted.max_local.model)),
     97     )
     98     effective.set(
     99         "max_local_route",
    100         Value(max_local_query_rewrite_route()),
    101     )
    102     effective.set(
    103         "max_local_request_timeout_ms",
    104         Value(context.config.effective.assisted.max_local.request_timeout_ms),
    105     )
    106     config.set("effective", effective)
    107     status.set("config", config)
    108 
    109     status.set("diagnostics", _diagnostics_status_value(context))
    110     status.set("secret_storage", _secret_storage_status_value(context))
    111     status.set(
    112         "protected_local_data", _protected_local_data_status_value(context)
    113     )
    114 
    115     return status^
    116 
    117 
    118 def _secret_storage_status_value(
    119     context: RuntimeStartupContext,
    120 ) raises -> Value:
    121     var secret_storage = loads("{}")
    122     secret_storage.set("default_backend", Value(default_secret_backend_name()))
    123     secret_storage.set("status", Value(secret_storage_status_name()))
    124     secret_storage.set(
    125         "backend_implemented", Value(secret_storage_backend_implemented())
    126     )
    127     secret_storage.set(
    128         "identity_path", Value(String(context.paths.identity_path))
    129     )
    130     secret_storage.set(
    131         "identity_material_configured",
    132         Value(identity_material_configured_for_runtime_paths(context.paths)),
    133     )
    134     secret_storage.set(
    135         "identity_material_loaded", Value(identity_material_loaded())
    136     )
    137     secret_storage.set(
    138         "identity_material_created_by_startup",
    139         Value(identity_material_created_by_startup()),
    140     )
    141     secret_storage.set("secret_values_reported", Value(False))
    142     return secret_storage^
    143 
    144 
    145 def _diagnostics_status_value(context: RuntimeStartupContext) raises -> Value:
    146     var diagnostics = loads("{}")
    147     var debug_override_dir = diagnostics_debug_override_dir_from_env()
    148     diagnostics.set(
    149         "canonical_dir", Value(String(context.paths.diagnostics_dir))
    150     )
    151     diagnostics.set(
    152         "effective_dir",
    153         Value(effective_diagnostics_dir_for_runtime_paths(context.paths)),
    154     )
    155     diagnostics.set("debug_override_active", Value(debug_override_dir != ""))
    156     return diagnostics^
    157 
    158 
    159 def _protected_local_data_status_value(
    160     context: RuntimeStartupContext,
    161 ) raises -> Value:
    162     var protected_data = loads("{}")
    163     protected_data.set("status", Value(protected_local_data_status_name()))
    164     protected_data.set(
    165         "default_dir",
    166         Value(protected_local_data_dir_for_runtime_paths(context.paths)),
    167     )
    168     protected_data.set(
    169         "configured",
    170         Value(protected_local_data_configured_for_runtime_paths(context.paths)),
    171     )
    172     protected_data.set(
    173         "support_implemented", Value(protected_local_data_support_implemented())
    174     )
    175     protected_data.set("store_open", Value(protected_local_data_store_open()))
    176     return protected_data^