use std::collections::HashMap;
use std::sync::LazyLock;
static FIELD_MAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("type", "t");
m.insert("subject", "s");
m.insert("relation", "r");
m.insert("object", "o");
m.insert("confidence", "c");
m.insert("source_type", "st");
m.insert("created_at", "ca");
m.insert("temporal_type", "tt");
m.insert("valid_from", "vf");
m.insert("valid_to", "vt");
m.insert("system_valid_from", "svf");
m.insert("system_valid_to", "svt");
m.insert("context", "ctx");
m.insert("superseded_by", "sb");
m.insert("importance", "im");
m.insert("author_did", "adid");
m.insert("namespace", "ns");
m.insert("user_id", "user");
m.insert("structural_tags", "tags");
m.insert("derived_from", "df");
m.insert("consolidation_level", "cl");
m.insert("success_count", "sc");
m.insert("failure_count", "fc");
m.insert("provenance_chain", "pc");
m.insert("origin_did", "odid");
m.insert("origin_namespace", "ons");
m.insert("content_refs", "cr");
m.insert("embedding_refs", "er");
m.insert("related_to", "rt");
m.insert("_elided", "_e");
m.insert("_disclosure_of", "_do");
m.insert("invalidation_policy", "ip");
m.insert("supersession_justification", "sj");
m.insert("supersession_auth", "sa");
m.insert("verification_status", "vstatus");
m.insert("owner", "own");
m.insert("category", "cat");
m.insert("run_id", "rid");
m.insert("role", "role");
m.insert("access_count", "ac");
m.insert("last_accessed_at", "laa");
m.insert("timestamp_ms", "tms");
m.insert("observer_did", "obsdid");
m.insert("subject_did", "sdid");
m.insert("session_id", "sid2");
m.insert("entity_id", "eid");
m.insert("epistemic_status", "epstat");
m.insert("requires_human_review", "rhr");
m.insert("processing_basis", "pbasis");
m.insert("identity_state", "idst");
m.insert("license", "lic");
m.insert("trusted_timestamp", "tts");
m.insert("invalidation_type", "itype");
m.insert("invalidation_reason", "ireason");
m.insert("invalidation_initiator", "iinit");
m.insert("retention_policy", "rpol");
m.insert("recall_priority", "rpri");
m.insert("tool_name", "tn");
m.insert("input", "inp"); m.insert("tool_content", "cnt"); m.insert("is_error", "iserr"); m.insert("error", "err");
m.insert("duration_ms", "dur");
m.insert("parent_task_id", "ptid");
m.insert("tool_phase", "aphase");
m.insert("tool_call_id", "tcid");
m.insert("call_batch_id", "cbid");
m.insert("tool_type", "ttype");
m.insert("tool_version", "tver");
m.insert("execution_mode", "emode");
m.insert("code", "code");
m.insert("stdout", "stdout");
m.insert("stderr", "stderr");
m.insert("exit_code", "xcode");
m.insert("interpreter_id", "iid");
m.insert("error_type", "etype");
m.insert("tool_description", "tdesc");
m.insert("input_schema", "ischema");
m.insert("strict", "strict");
m.insert("async_mode", "amode");
m.insert("output_schema", "osch");
m.insert("kind", "aknd");
m.insert("executor_uri", "axu");
m.insert("locked_params", "lprm");
m.insert("examples", "exmp");
m.insert("annotations", "anno");
m.insert("spec_hash", "shsh");
m.insert("executor_kind", "exk");
m.insert("status", "ast");
m.insert("correlation_id", "acid");
m.insert("expires_at_sec", "axp");
m.insert("transient_definition_hash", "tdh");
m.insert("failure_cause", "afc");
m.insert("failure_detail", "afd");
m.insert("actor_execution_environment", "aex");
m.insert("int:base_url", "ib");
m.insert("int:http_method", "ihm"); m.insert("int:http_path", "ihp"); m.insert("int:path_params", "ipp");
m.insert("int:query_params", "iqp");
m.insert("int:body_params", "ibp");
m.insert("int:response_mapping", "irm");
m.insert("int:auth_type", "iat");
m.insert("int:auth_scopes", "ias");
m.insert("int:read_only", "iro");
m.insert("int:connector", "ic");
m.insert("int:docs_url", "idu");
m.insert("int:rate_limit", "irl");
m.insert("int:category", "icat");
m.insert("int:sunset_date", "isd");
m.insert("int:content_type", "ict");
m.insert("int:poll_interval_secs", "ipis");
m.insert("int:cursor_field", "icf");
m.insert("int:cursor_type", "icft");
m.insert("int:webhook_path", "iwp");
m.insert("int:webhook_secret_header", "iwsh");
m.insert("int:cron_expression", "icron");
m.insert("int:timezone", "itz");
m.insert("int:config_schema", "icfg");
m.insert("int:event_schema", "ievt");
m.insert("observer_id", "oid");
m.insert("observer_type", "otype");
m.insert("frame_id", "fid");
m.insert("sync_group", "sg");
m.insert("observation_mode", "omode");
m.insert("observation_scope", "oscope");
m.insert("observer_model", "omdl");
m.insert("compression_ratio", "ocmp");
m.insert("description", "desc");
m.insert("goal_state", "gs");
m.insert("criteria", "crit");
m.insert("criteria_structured", "crs");
m.insert("priority", "pri");
m.insert("parent_goals", "pgs");
m.insert("state_reason", "sr");
m.insert("satisfaction_evidence", "se");
m.insert("progress", "prog");
m.insert("delegate_to", "dto");
m.insert("delegate_from", "dfo");
m.insert("expiry_policy", "ep");
m.insert("recurrence", "rec");
m.insert("evidence_required", "evreq");
m.insert("rollback_on_failure", "rof");
m.insert("allowed_transitions", "atr");
m.insert("depends_on", "depg");
m.insert("assigned_agent", "asgn");
m.insert("expected_output", "expout");
m.insert("output_grain", "outg");
m.insert("deadline", "dline");
m.insert("content_blocks", "cblocks");
m.insert("model_id", "mdl");
m.insert("stop_reason", "stopr");
m.insert("token_usage", "toku");
m.insert("parent_message_id", "pmid");
m.insert("premises", "prem");
m.insert("conclusion", "conc");
m.insert("inference_method", "imethod");
m.insert("alternatives_considered", "altc");
m.insert("thinking_content", "think");
m.insert("thinking_redacted", "tredact");
m.insert("statistical_context", "statctx");
m.insert("software_environment", "swenv");
m.insert("parameter_set", "params");
m.insert("random_seed", "rseed");
m.insert("participating_observers", "pobs");
m.insert("threshold", "thr");
m.insert("agreement_count", "agrc");
m.insert("dissent_count", "disc");
m.insert("dissent_grains", "dgrains");
m.insert("agreed_content", "acnt");
m.insert("grantee_did", "gdid");
m.insert("scope", "scope");
m.insert("is_withdrawal", "isw");
m.insert("basis", "basis");
m.insert("jurisdiction", "jur");
m.insert("prior_consent", "pcon");
m.insert("witness_dids", "wdids");
m.insert("name", "skname");
m.insert("instructions", "instr");
m.insert("when_to_use", "wtu");
m.insert("version", "sver");
m.insert("allowed_tools", "atls");
m.insert("resources", "res");
m.insert("dependencies", "deps");
m.insert("input_modalities", "imod");
m.insert("output_modalities", "omod");
m.insert("domain", "dom");
m.insert("holder_did", "hdid");
m.insert("proficiency", "prof");
m.insert("practice_count", "prcnt");
m.insert("last_practiced_at", "lpa");
m.insert("strategies", "strat");
m.insert("transferable", "xfer");
m.insert("embedding_text", "et");
m.insert("scope_path", "scp");
m.insert("scope_depth", "scd");
m.insert("authorized_namespaces", "ans");
m.insert("authorized_types", "atypes");
m.insert("authorized_tools", "atools");
m.insert("delegation_depth", "ddepth");
m.insert("delegation_expiry", "dexp");
m.insert("context_grains", "cgrains");
m.insert("return_to", "retdid");
m.insert("bindings", "bind");
m
});
static REVERSE_FIELD_MAP: LazyLock<HashMap<&'static str, &'static str>> =
LazyLock::new(|| FIELD_MAP.iter().map(|(&k, &v)| (v, k)).collect());
static CONTENT_REF_FIELD_MAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("uri", "u");
m.insert("modality", "m");
m.insert("mime_type", "mt");
m.insert("size_bytes", "sz");
m.insert("checksum", "ck");
m.insert("metadata", "md");
m
});
static EMBEDDING_REF_FIELD_MAP: LazyLock<HashMap<&'static str, &'static str>> =
LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("vector_id", "vi");
m.insert("model", "mo");
m.insert("dimensions", "dm");
m.insert("modality_source", "ms");
m.insert("distance_metric", "di");
m.insert("chunk_index", "ci");
m.insert("chunk_text", "ct");
m.insert("chunk_strategy", "cs");
m.insert("chunk_overlap", "co");
m
});
static RELATED_TO_FIELD_MAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("hash", "h");
m.insert("relation_type", "rl");
m.insert("weight", "w");
m
});
static WORKFLOW_EDGE_FIELD_MAP: LazyLock<HashMap<&'static str, &'static str>> =
LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("max_cycles", "mxc");
m
});
pub fn compact_field(name: &str) -> &str {
FIELD_MAP.get(name).copied().unwrap_or(name)
}
pub fn expand_field(short: &str) -> &str {
REVERSE_FIELD_MAP.get(short).copied().unwrap_or(short)
}
pub fn compact_content_ref_field(name: &str) -> &str {
CONTENT_REF_FIELD_MAP.get(name).copied().unwrap_or(name)
}
pub fn compact_embedding_ref_field(name: &str) -> &str {
EMBEDDING_REF_FIELD_MAP.get(name).copied().unwrap_or(name)
}
pub fn compact_related_to_field(name: &str) -> &str {
RELATED_TO_FIELD_MAP.get(name).copied().unwrap_or(name)
}
pub fn compact_workflow_edge_field(name: &str) -> &str {
WORKFLOW_EDGE_FIELD_MAP.get(name).copied().unwrap_or(name)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compact_field() {
assert_eq!(compact_field("subject"), "s");
assert_eq!(compact_field("relation"), "r");
assert_eq!(compact_field("object"), "o");
assert_eq!(compact_field("confidence"), "c");
assert_eq!(compact_field("type"), "t");
assert_eq!(compact_field("created_at"), "ca");
assert_eq!(compact_field("namespace"), "ns");
assert_eq!(compact_field("author_did"), "adid");
assert_eq!(compact_field("source_type"), "st");
assert_eq!(compact_field("unknown_field"), "unknown_field");
assert_eq!(compact_field("input"), "inp");
assert_eq!(compact_field("is_error"), "iserr");
assert_eq!(compact_field("verification_status"), "vstatus");
assert_eq!(compact_field("premises"), "prem");
assert_eq!(compact_field("conclusion"), "conc");
assert_eq!(compact_field("output_schema"), "osch");
assert_eq!(compact_field("int:base_url"), "ib");
assert_eq!(compact_field("int:http_method"), "ihm");
assert_eq!(compact_field("int:connector"), "ic");
assert_eq!(compact_field("int:poll_interval_secs"), "ipis");
assert_eq!(compact_field("int:webhook_path"), "iwp");
assert_eq!(compact_field("status"), "ast");
assert_eq!(compact_field("correlation_id"), "acid");
assert_eq!(compact_field("expires_at_sec"), "axp");
assert_eq!(compact_field("transient_definition_hash"), "tdh");
assert_eq!(compact_field("failure_cause"), "afc");
assert_eq!(compact_field("failure_detail"), "afd");
assert_eq!(compact_field("actor_execution_environment"), "aex");
}
#[test]
fn test_expand_field() {
assert_eq!(expand_field("s"), "subject");
assert_eq!(expand_field("r"), "relation");
assert_eq!(expand_field("o"), "object");
assert_eq!(expand_field("t"), "type");
assert_eq!(expand_field("unknown"), "unknown");
assert_eq!(expand_field("inp"), "input");
assert_eq!(expand_field("iserr"), "is_error");
assert_eq!(expand_field("vstatus"), "verification_status");
assert_eq!(expand_field("args"), "args");
assert_eq!(expand_field("ok"), "ok");
assert_eq!(expand_field("ct"), "ct");
assert_eq!(expand_field("osch"), "output_schema");
assert_eq!(expand_field("ib"), "int:base_url");
assert_eq!(expand_field("ihm"), "int:http_method");
assert_eq!(expand_field("ic"), "int:connector");
assert_eq!(expand_field("ipis"), "int:poll_interval_secs");
assert_eq!(expand_field("ast"), "status");
assert_eq!(expand_field("acid"), "correlation_id");
assert_eq!(expand_field("axp"), "expires_at_sec");
assert_eq!(expand_field("tdh"), "transient_definition_hash");
assert_eq!(expand_field("afc"), "failure_cause");
assert_eq!(expand_field("afd"), "failure_detail");
assert_eq!(expand_field("aex"), "actor_execution_environment");
}
#[test]
fn test_nested_compaction() {
assert_eq!(compact_content_ref_field("uri"), "u");
assert_eq!(compact_content_ref_field("mime_type"), "mt");
assert_eq!(compact_embedding_ref_field("vector_id"), "vi");
assert_eq!(compact_related_to_field("hash"), "h");
assert_eq!(compact_related_to_field("relation_type"), "rl");
assert_eq!(compact_embedding_ref_field("chunk_index"), "ci");
assert_eq!(compact_embedding_ref_field("chunk_text"), "ct");
}
#[test]
fn test_no_compact_key_collisions() {
let map = &*FIELD_MAP;
let reverse = &*REVERSE_FIELD_MAP;
assert_eq!(map.len(), reverse.len(),
"FIELD_MAP has {} entries but REVERSE_FIELD_MAP has {} — compact key collision detected",
map.len(), reverse.len());
}
#[test]
fn test_integration_profile_roundtrip() {
let int_keys = [
"int:base_url",
"int:http_method",
"int:http_path",
"int:path_params",
"int:query_params",
"int:body_params",
"int:response_mapping",
"int:auth_type",
"int:auth_scopes",
"int:read_only",
"int:connector",
"int:docs_url",
"int:rate_limit",
"int:category",
"int:sunset_date",
"int:content_type",
"int:poll_interval_secs",
"int:cursor_field",
"int:cursor_type",
"int:webhook_path",
"int:webhook_secret_header",
"int:cron_expression",
"int:timezone",
"int:config_schema",
"int:event_schema",
];
for key in &int_keys {
let short = compact_field(key);
assert_ne!(short, *key, "int:* key '{}' has no compact mapping", key);
let expanded = expand_field(short);
assert_eq!(
expanded, *key,
"roundtrip failed for '{}' → '{}' → '{}'",
key, short, expanded
);
}
}
}