toRPCContent converts an SDK content value to an RPC elicitation response value.
(v any)
| 1025 | |
| 1026 | // toRPCContent converts an SDK content value to an RPC elicitation response value. |
| 1027 | func toRPCContent(v any) (rpc.UIElicitationFieldValue, error) { |
| 1028 | if v == nil { |
| 1029 | return nil, nil |
| 1030 | } |
| 1031 | switch val := v.(type) { |
| 1032 | case bool: |
| 1033 | return rpc.UIElicitationBooleanValue(val), nil |
| 1034 | case float64: |
| 1035 | return rpc.UIElicitationNumberValue(val), nil |
| 1036 | case float32: |
| 1037 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1038 | case int: |
| 1039 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1040 | case int8: |
| 1041 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1042 | case int16: |
| 1043 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1044 | case int32: |
| 1045 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1046 | case int64: |
| 1047 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1048 | case uint: |
| 1049 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1050 | case uint8: |
| 1051 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1052 | case uint16: |
| 1053 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1054 | case uint32: |
| 1055 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1056 | case uint64: |
| 1057 | return rpc.UIElicitationNumberValue(float64(val)), nil |
| 1058 | case json.Number: |
| 1059 | f, err := val.Float64() |
| 1060 | if err != nil { |
| 1061 | return nil, err |
| 1062 | } |
| 1063 | return rpc.UIElicitationNumberValue(f), nil |
| 1064 | case string: |
| 1065 | return rpc.UIElicitationStringValue(val), nil |
| 1066 | case []string: |
| 1067 | return rpc.UIElicitationStringArrayValue(val), nil |
| 1068 | case []any: |
| 1069 | strs := make([]string, len(val)) |
| 1070 | for i, item := range val { |
| 1071 | s, ok := item.(string) |
| 1072 | if !ok { |
| 1073 | return nil, fmt.Errorf("unsupported elicitation string array item type %T", item) |
| 1074 | } |
| 1075 | strs[i] = s |
| 1076 | } |
| 1077 | return rpc.UIElicitationStringArrayValue(strs), nil |
| 1078 | default: |
| 1079 | return nil, fmt.Errorf("unsupported elicitation content value type %T", v) |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | // Capabilities returns the session capabilities reported by the server. |
| 1084 | func (s *Session) Capabilities() SessionCapabilities { |
no outgoing calls
searching dependent graphs…