key: string → value: string GetValidationConfigJSON returns the validation configuration as indented JSON. If enabledTypes is empty or nil, returns all validation configs. If enabledTypes is provided, returns only configs for the specified types. If mentions is non-empty, a top-level "mentions" key
(enabledTypes []string, mentions map[string]any)
| 472 | // during the initial sanitization pass (mirroring what the publish-side handlers |
| 473 | // receive via GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG). |
| 474 | func GetValidationConfigJSON(enabledTypes []string, mentions map[string]any) (string, error) { |
| 475 | safeOutputValidationLog.Printf("Getting validation config JSON for %d types (mentions=%t)", len(enabledTypes), len(mentions) > 0) |
| 476 | |
| 477 | // Cache only the schema-only path; mentions are workflow-specific and cheap to remarshal. |
| 478 | if len(mentions) == 0 { |
| 479 | cacheKey := buildValidationConfigCacheKey(enabledTypes) |
| 480 | if cached, ok := validationConfigJSONCache.Load(cacheKey); ok { |
| 481 | safeOutputValidationLog.Print("Returning cached validation config JSON") |
| 482 | result, ok := cached.(string) |
| 483 | if !ok { |
| 484 | // The cache exclusively stores string values; a non-string indicates a programmer error. |
| 485 | return "", fmt.Errorf("validationConfigJSONCache: unexpected type %T for key %s", cached, cacheKey) |
| 486 | } |
| 487 | return result, nil |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | configToMarshal := ValidationConfig |
| 492 | if len(enabledTypes) > 0 { |
| 493 | safeOutputValidationLog.Printf("Filtering validation configs to enabled types: %v", enabledTypes) |
| 494 | configToMarshal = make(map[string]TypeValidationConfig) |
| 495 | for _, typeName := range enabledTypes { |
| 496 | if config, ok := ValidationConfig[typeName]; ok { |
| 497 | configToMarshal[typeName] = config |
| 498 | } |
| 499 | } |
| 500 | } else { |
| 501 | safeOutputValidationLog.Print("Returning all validation configs") |
| 502 | } |
| 503 | |
| 504 | var data []byte |
| 505 | var err error |
| 506 | if len(mentions) > 0 { |
| 507 | composite := make(map[string]any, len(configToMarshal)+1) |
| 508 | for k, v := range configToMarshal { |
| 509 | composite[k] = v |
| 510 | } |
| 511 | composite["mentions"] = mentions |
| 512 | data, err = json.MarshalIndent(composite, "", " ") |
| 513 | } else { |
| 514 | data, err = json.MarshalIndent(configToMarshal, "", " ") |
| 515 | } |
| 516 | if err != nil { |
| 517 | safeOutputValidationLog.Printf("Failed to marshal validation config: %v", err) |
| 518 | return "", err |
| 519 | } |
| 520 | result := string(data) |
| 521 | safeOutputValidationLog.Printf("Generated validation config JSON with %d bytes", len(result)) |
| 522 | if len(mentions) == 0 { |
| 523 | validationConfigJSONCache.Store(buildValidationConfigCacheKey(enabledTypes), result) |
| 524 | } |
| 525 | return result, nil |
| 526 | } |
| 527 | |
| 528 | // buildValidationConfigCacheKey returns a stable cache key for GetValidationConfigJSON. |
| 529 | // For nil/empty enabledTypes the key is "" (full config). Otherwise the sorted type |