Skip to content

Commit 8e0c431

Browse files
committed
feat: implement decision-based routing with plugin architecture
Signed-off-by: bitliu <[email protected]>
1 parent 2df8461 commit 8e0c431

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/semantic-router/pkg/config/config.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ func unmarshalPluginConfig(config interface{}, target interface{}) error {
594594
return fmt.Errorf("failed to marshal config: %w", err)
595595
}
596596
return json.Unmarshal(data, target)
597+
case map[interface{}]interface{}:
598+
// From YAML file with interface{} keys - convert to map[string]interface{} first
599+
converted := convertMapToStringKeys(v)
600+
data, err := json.Marshal(converted)
601+
if err != nil {
602+
return fmt.Errorf("failed to marshal config: %w", err)
603+
}
604+
return json.Unmarshal(data, target)
597605
case []byte:
598606
// From Kubernetes RawExtension - direct unmarshal
599607
return json.Unmarshal(v, target)
@@ -602,6 +610,45 @@ func unmarshalPluginConfig(config interface{}, target interface{}) error {
602610
}
603611
}
604612

613+
// convertMapToStringKeys recursively converts map[interface{}]interface{} to map[string]interface{}
614+
func convertMapToStringKeys(m map[interface{}]interface{}) map[string]interface{} {
615+
result := make(map[string]interface{})
616+
for k, v := range m {
617+
// Convert key to string
618+
key, ok := k.(string)
619+
if !ok {
620+
key = fmt.Sprintf("%v", k)
621+
}
622+
623+
// Recursively convert nested maps
624+
switch val := v.(type) {
625+
case map[interface{}]interface{}:
626+
result[key] = convertMapToStringKeys(val)
627+
case []interface{}:
628+
result[key] = convertSliceValues(val)
629+
default:
630+
result[key] = v
631+
}
632+
}
633+
return result
634+
}
635+
636+
// convertSliceValues recursively converts slice elements that are maps
637+
func convertSliceValues(s []interface{}) []interface{} {
638+
result := make([]interface{}, len(s))
639+
for i, v := range s {
640+
switch val := v.(type) {
641+
case map[interface{}]interface{}:
642+
result[i] = convertMapToStringKeys(val)
643+
case []interface{}:
644+
result[i] = convertSliceValues(val)
645+
default:
646+
result[i] = v
647+
}
648+
}
649+
return result
650+
}
651+
605652
// GetSemanticCacheConfig returns the semantic-cache plugin configuration
606653
func (d *Decision) GetSemanticCacheConfig() *SemanticCachePluginConfig {
607654
config := d.GetPluginConfig("semantic-cache")

0 commit comments

Comments
 (0)