normalizeTools converts the tool list into lightweight descriptors. Function tool schemas are preserved so the debug panel can render parameter details without re-fetching provider metadata.
(tools []fantasy.Tool)
| 1042 | // Function tool schemas are preserved so the debug panel can render |
| 1043 | // parameter details without re-fetching provider metadata. |
| 1044 | func normalizeTools(tools []fantasy.Tool) []normalizedTool { |
| 1045 | if len(tools) == 0 { |
| 1046 | return nil |
| 1047 | } |
| 1048 | result := make([]normalizedTool, 0, len(tools)) |
| 1049 | for _, t := range tools { |
| 1050 | if isNilInterfaceValue(t) { |
| 1051 | continue |
| 1052 | } |
| 1053 | nt := normalizedTool{ |
| 1054 | Type: string(t.GetType()), |
| 1055 | Name: t.GetName(), |
| 1056 | } |
| 1057 | switch v := t.(type) { |
| 1058 | case fantasy.FunctionTool: |
| 1059 | nt.Description = v.Description |
| 1060 | nt.HasInputSchema = len(v.InputSchema) > 0 |
| 1061 | if nt.HasInputSchema { |
| 1062 | nt.InputSchema = safeMarshalJSON( |
| 1063 | fmt.Sprintf("tool %q input schema", v.Name), |
| 1064 | v.InputSchema, |
| 1065 | ) |
| 1066 | } |
| 1067 | case *fantasy.FunctionTool: |
| 1068 | nt.Description = v.Description |
| 1069 | nt.HasInputSchema = len(v.InputSchema) > 0 |
| 1070 | if nt.HasInputSchema { |
| 1071 | nt.InputSchema = safeMarshalJSON( |
| 1072 | fmt.Sprintf("tool %q input schema", v.Name), |
| 1073 | v.InputSchema, |
| 1074 | ) |
| 1075 | } |
| 1076 | case fantasy.ProviderDefinedTool: |
| 1077 | nt.ID = v.ID |
| 1078 | case *fantasy.ProviderDefinedTool: |
| 1079 | nt.ID = v.ID |
| 1080 | case fantasy.ExecutableProviderTool: |
| 1081 | nt.ID = v.Definition().ID |
| 1082 | case *fantasy.ExecutableProviderTool: |
| 1083 | nt.ID = v.Definition().ID |
| 1084 | } |
| 1085 | result = append(result, nt) |
| 1086 | } |
| 1087 | return result |
| 1088 | } |
| 1089 | |
| 1090 | // normalizeContentParts converts the response content into a slice |
| 1091 | // of normalizedContentPart values. Text payloads are bounded to |