1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_EXTRACT_INSIGHT_INTENT_PROFILE_H 17 #define OHOS_ABILITY_RUNTIME_EXTRACT_INSIGHT_INTENT_PROFILE_H 18 19 #include <string> 20 #include <vector> 21 22 #include "insight_intent_execute_param.h" 23 24 namespace OHOS { 25 namespace AbilityRuntime { 26 using ExecuteMode = AppExecFwk::ExecuteMode; 27 28 const std::string INSIGHT_INTENTS_DECORATOR_TYPE_LINK = "@InsightIntentLink"; 29 const std::string INSIGHT_INTENTS_DECORATOR_TYPE_PAGE = "@InsightIntentPage"; 30 const std::string INSIGHT_INTENTS_DECORATOR_TYPE_ENTRY = "@InsightIntentEntry"; 31 const std::string INSIGHT_INTENTS_DECORATOR_TYPE_FUNCTION = "@InsightIntentFunctionMethod"; 32 const std::string INSIGHT_INTENTS_DECORATOR_TYPE_FORM = "@InsightIntentForm"; 33 34 struct InsightIntentParam { 35 std::string paramName; 36 bool isRequired = false; 37 std::string paramSchema; 38 39 InsightIntentParam() = default; 40 }; 41 42 struct LinkIntentParamMapping { 43 std::string paramName; 44 std::string paramMappingName; 45 std::string paramCategory; 46 47 LinkIntentParamMapping() = default; 48 }; 49 50 struct InsightIntentLinkInfo { 51 std::string uri; 52 std::vector<LinkIntentParamMapping> paramMapping {}; 53 std::string parameters; 54 55 InsightIntentLinkInfo() = default; 56 }; 57 58 struct InsightIntentPageInfo { 59 std::string uiAbility; 60 std::string pagePath; 61 std::string navigationId; 62 std::string navDestinationName; 63 std::string parameters; 64 65 InsightIntentPageInfo() = default; 66 }; 67 68 struct InsightIntentEntryInfo { 69 std::string abilityName; 70 std::vector<ExecuteMode> executeMode {}; 71 std::string parameters; 72 73 InsightIntentEntryInfo() = default; 74 }; 75 76 struct InsightIntentFunctionInfo { 77 std::string functionName; 78 std::vector<std::string> functionParams; 79 std::string parameters; 80 81 InsightIntentFunctionInfo() = default; 82 }; 83 84 struct InsightIntentFormInfo { 85 std::string abilityName; 86 std::string formName; 87 std::string parameters; 88 89 InsightIntentFormInfo() = default; 90 }; 91 92 enum class InfoType: uint8_t { 93 Link, 94 Page, 95 Entry, 96 Function, 97 Form, 98 None 99 }; 100 101 struct ExtractInsightIntentGenericInfo { 102 std::string bundleName; 103 std::string moduleName; 104 std::string intentName; 105 std::string displayName; 106 std::string decoratorType; 107 108 std::variant< 109 InsightIntentLinkInfo, 110 InsightIntentPageInfo, 111 InsightIntentEntryInfo, 112 InsightIntentFunctionInfo, 113 InsightIntentFormInfo, 114 std::monostate 115 > data; 116 117 InfoType currentType = InfoType::None; 118 ExtractInsightIntentGenericInfoExtractInsightIntentGenericInfo119 ExtractInsightIntentGenericInfo() : data(std::monostate{}) {} 120 121 template<typename T> setExtractInsightIntentGenericInfo122 void set() 123 { 124 data = T{}; 125 currentType = TypeInfo<T>(); 126 } 127 128 template<typename T> getExtractInsightIntentGenericInfo129 T& get() 130 { 131 if (!std::holds_alternative<T>(data)) { 132 data = T{}; 133 currentType = TypeInfo<T>(); 134 } 135 return std::get<T>(data); 136 } 137 138 private: 139 template<typename T> TypeInfoExtractInsightIntentGenericInfo140 static InfoType TypeInfo() 141 { 142 if constexpr (std::is_same_v<T, InsightIntentLinkInfo>) return InfoType::Link; 143 if constexpr (std::is_same_v<T, InsightIntentPageInfo>) return InfoType::Page; 144 if constexpr (std::is_same_v<T, InsightIntentEntryInfo>) return InfoType::Entry; 145 if constexpr (std::is_same_v<T, InsightIntentFunctionInfo>) return InfoType::Function; 146 if constexpr (std::is_same_v<T, InsightIntentFormInfo>) return InfoType::Form; 147 return InfoType::None; 148 } 149 }; 150 151 struct InsightIntentEntityInfo { 152 std::string decoratorFile; 153 std::string className; 154 std::string decoratorType; 155 std::string entityId; 156 std::string entityCategory; 157 std::string parameters; 158 std::string parentClassName; 159 160 InsightIntentEntityInfo() = default; 161 }; 162 163 // 全量信息 164 struct ExtractInsightIntentInfo { 165 std::string decoratorFile; 166 std::string decoratorClass; 167 std::string displayDescription; 168 std::string domain; 169 std::string intentVersion; 170 std::string schema; 171 std::string icon; 172 std::string llmDescription; 173 std::string result; 174 std::string example; 175 std::vector<std::string> keywords; 176 std::vector<InsightIntentEntityInfo> entities {}; 177 ExtractInsightIntentGenericInfo genericInfo; 178 179 ExtractInsightIntentInfo() = default; 180 }; 181 182 struct LinkIntentParamProfileMapping { 183 std::string paramName; 184 std::string paramMappingName; 185 std::string paramCategory; 186 }; 187 188 struct ExtractInsightIntentProfileInfo { 189 std::string decoratorFile; 190 std::string decoratorClass; 191 std::string decoratorType; 192 std::string bundleName; 193 std::string moduleName; 194 std::string intentName; 195 std::string domain; 196 std::string intentVersion; 197 std::string displayName; 198 std::string displayDescription; 199 std::string schema; 200 std::string icon; 201 std::string llmDescription; 202 std::vector<std::string> keywords; 203 std::string parameters; 204 std::string result; 205 std::string example; 206 std::string uri; 207 std::vector<LinkIntentParamProfileMapping> paramMapping {}; 208 std::string uiAbility; 209 std::string pagePath; 210 std::string navigationId; 211 std::string navDestinationName; 212 std::string abilityName; 213 std::vector<std::string> executeMode {}; 214 std::string functionName; 215 std::vector<std::string> functionParams; 216 std::string formName; 217 std::vector<InsightIntentEntityInfo> entities {}; 218 }; 219 220 struct ExtractInsightIntentProfileInfoVec { 221 std::vector<ExtractInsightIntentProfileInfo> insightIntents {}; 222 }; 223 224 class ExtractInsightIntentProfile { 225 public: 226 static bool TransformTo(const std::string &profileStr, ExtractInsightIntentProfileInfoVec &infos); 227 static bool ToJson(const ExtractInsightIntentProfileInfo &info, nlohmann::json &jsonObject); 228 static bool ProfileInfoFormat(const ExtractInsightIntentProfileInfo &insightIntent, ExtractInsightIntentInfo &info); 229 }; 230 } // namespace AbilityRuntime 231 } // namespace OHOS 232 #endif // OHOS_ABILITY_RUNTIME_EXTRACT_INSIGHT_INTENT_PROFILE_H 233