Lines 13-53javascript
13 - S\u1ea3n ph\u1ea9m, V\u1eadt t\u01b0, H\u00e0ng h\u00f3a -> ${$ten_tham_so$$}: "dmvt"
14 - Nh\u00f3m S\u1ea3n ph\u1ea9m, V\u1eadt t\u01b0, H\u00e0ng h\u00f3a -> ${$ten_tham_so$$}: "dmnvt"
15 - Ng\u00e0nh h\u00e0ng -> ${$ten_tham_so$$}: "ecomproductlines"
16 - T\u00e0i s\u1ea3n c\u1ed1 \u0111\u1ecbnh, c\u00f4ng c\u1ee5 d\u1ee5ng c\u1ee5 -> ${$ten_tham_so$$}: "qts"
17 - Phi\u1ebfu \u0111\u1eb7t h\u00e0ng -> ${$ten_tham_so$$}: "dh2"
18 - Phi\u1ebfu b\u00e1n h\u00e0ng -> ${$ten_tham_so$$}: "hd2"
19 - H\u00f3a \u0111\u01a1n \u0111\u1ea7u v\u00e0o -> ${$ten_tham_so$$}: "vatvao"
20 - H\u00f3a \u0111\u01a1n \u0111\u1ea7u ra -> ${$ten_tham_so$$}: "vatra"
21 `,bangTuDienBaoCao=($ten_tham_so$$="exact_code")=>`
22 - C\u00e2n \u0111\u1ed1i ph\u00e1t sinh t\u00e0i kho\u1ea3n-> ${$ten_tham_so$$}: "cdpstk"
23 - T\u1ed5ng h\u1ee3p nh\u1eadp, xu\u1ea5t t\u1ed3n kho -> ${$ten_tham_so$$}: "thnxt"
24 `,getApiContext=$id_app$$=>({apis:{asyncGetData:async($token$$,$model$$,$condition$$={})=>{$condition$$.id_app=$id_app$$;return global.getModel($model$$).findOne($condition$$).lean()}},userInfo:{email:"admin",token:""}}),searchActiveListInfo=async({keywords:$keywords_words$$=[],include_fields_schema:$include_fields_schema_matchedKeyword$$=!1,limit:$finalResult_limit_processedDocs$$=15})=>{const $cacheKey$$=`listinfo_${$keywords_words$$.join("_").toLowerCase()}_${$include_fields_schema_matchedKeyword$$}_${$finalResult_limit_processedDocs$$}`;
25if(global.__aiListInfoCache.has($cacheKey$$)){var $ListInfoModel_cachedData$$=global.__aiListInfoCache.get($cacheKey$$);if(Date.now()-$ListInfoModel_cachedData$$.timestamp<CACHE_TTL)return $ListInfoModel_cachedData$$.result;global.__aiListInfoCache.delete($cacheKey$$)}$ListInfoModel_cachedData$$=global.getModel("listinfo");if(!$ListInfoModel_cachedData$$)throw Error("Model 'listinfo' kh\u00f4ng t\u1ed3n t\u1ea1i.");var $endpoints_matchQuery$$=Object.keys(global.controllers||{}).map($k$$=>$k$$.toLowerCase());
26$endpoints_matchQuery$$={status:!0,$and:[{code:{$not:{$regex:"(_bk|_bk1|_bk2|_dev|_tmp|_bk3|_agent)$",$options:"i"}}},{$or:[{code:{$in:$endpoints_matchQuery$$}},{api_code:{$in:$endpoints_matchQuery$$}}]}]};const $selectFields$$={code:1,title:1,search_form:1,api_code:1};$include_fields_schema_matchedKeyword$$&&($selectFields$$.fields=1);let $listDocs$$=[];$include_fields_schema_matchedKeyword$$="";if($keywords_words$$&&$keywords_words$$.length>0)for(let $kw$$ of $keywords_words$$){if($kw$$=$kw$$.trim())if($listDocs$$=
27await $ListInfoModel_cachedData$$.find({...$endpoints_matchQuery$$,$or:[{code:{$regex:$kw$$,$options:"i"}},{api_code:{$regex:$kw$$,$options:"i"}},{title:{$regex:$kw$$,$options:"i"}}]}).select($selectFields$$).limit($finalResult_limit_processedDocs$$).lean(),$listDocs$$.length===0&&$kw$$.includes(" ")&&($keywords_words$$=$kw$$.split(" ").filter($w$$=>$w$$.length>1),$keywords_words$$.length>=2&&($listDocs$$=await $ListInfoModel_cachedData$$.find({...$endpoints_matchQuery$$,$and:$keywords_words$$.slice(0,
282).map($word$$=>({title:{$regex:$word$$,$options:"i"}}))}).select($selectFields$$).limit($finalResult_limit_processedDocs$$).lean()),$listDocs$$.length===0&&$keywords_words$$.length>0&&($listDocs$$=await $ListInfoModel_cachedData$$.find({...$endpoints_matchQuery$$,title:{$regex:$keywords_words$$[0],$options:"i"}}).select($selectFields$$).limit($finalResult_limit_processedDocs$$).lean()),$listDocs$$.length===0&&($listDocs$$=await $ListInfoModel_cachedData$$.find({...$endpoints_matchQuery$$,$or:$keywords_words$$.map($word$$=>
29({title:{$regex:$word$$,$options:"i"}}))}).select($selectFields$$).limit($finalResult_limit_processedDocs$$).lean())),$listDocs$$.length>0){$include_fields_schema_matchedKeyword$$=$kw$$;break}}else $listDocs$$=await $ListInfoModel_cachedData$$.find($endpoints_matchQuery$$).select($selectFields$$).limit($finalResult_limit_processedDocs$$).lean();$finalResult_limit_processedDocs$$=$listDocs$$.map($d$$=>({...$d$$,finalCode:$d$$.api_code||$d$$.code}));$finalResult_limit_processedDocs$$={docs:JSON.parse(JSON.stringify($finalResult_limit_processedDocs$$)),
30matchedKeyword:$include_fields_schema_matchedKeyword$$||"all"};global.__aiListInfoCache.set($cacheKey$$,{timestamp:Date.now(),result:$finalResult_limit_processedDocs$$});return $finalResult_limit_processedDocs$$};
31async function translateDocToText($doc$$,$listInfoCode_text$$,$cache$$={},$depth$$=0,$visited$$=new Set){if($visited$$.has($listInfoCode_text$$))return"";$visited$$.add($listInfoCode_text$$);if(!$cache$$[$listInfoCode_text$$]){var $indent_info$$=await global.getModel("listinfo").findOne({code:$listInfoCode_text$$});if(!$indent_info$$)return"";$cache$$[$listInfoCode_text$$]=$indent_info$$}const $listInfo$$=$cache$$[$listInfoCode_text$$];$listInfoCode_text$$=$depth$$===0?`Th\u00f4ng tin ${$listInfo$$.title}:\n`:
32"";$indent_info$$=" ".repeat($depth$$);await Promise.all(($listInfo$$.fields||[]).filter($f$$=>$f$$.header.indexOf("return ")>=0).map($field$$=>(async()=>{let $body_func$$=$field$$.header;$body_func$$=`return (async ()=>{
34 })()`;try{const $func$$=new Function("master","Moment","Numeral","API","utils","context","field","listInfo",$body_func$$),$context$$=getApiContext($doc$$.id_app);let $header$$=await $func$$({},moment,numeral,$context$$.apis,{},$context$$,$field$$,$listInfo$$);$field$$.header=$header$$}catch($e$$){console.error($e$$.message,$field$$.header,$body_func$$),$field$$.header=$field$$.name}})()));for(const $field$$ of $listInfo$$.fields){const {header:$header$$,name:$name$$,type:$type$$,form:$form$$}=
35$field$$,$rawValue$$=$doc$$[$name$$];if($rawValue$$!==void 0&&$rawValue$$!==null&&$rawValue$$!=="")if($type$$.toLowerCase()==="array"&&$form$$){if(Array.isArray($rawValue$$)&&$rawValue$$.length!==0){$listInfoCode_text$$+=`${$indent_info$$}- ${$header$$}:\n`;for(var $displayValue_i$$=0;$displayValue_i$$<$rawValue$$.length;$displayValue_i$$++){var $subDoc_subText$$=$rawValue$$[$displayValue_i$$];$listInfoCode_text$$+=`${$indent_info$$} * [D\u00f2ng ${$displayValue_i$$+1}]:\n`;$subDoc_subText$$=await translateDocToText($subDoc_subText$$,
LowEval
Package source references a known benign dynamic code generation pattern.
server/agents/tools/utils.jsView on unpkg · L33 36$form$$,$cache$$,$depth$$+2,new Set($visited$$));$listInfoCode_text$$+=$subDoc_subText$$}}}else{$displayValue_i$$=$rawValue$$;switch($type$$.toLowerCase()){case "datetime":case "date":$displayValue_i$$=(new Date($rawValue$$)).toLocaleDateString("vi-VN");break;case "array":$displayValue_i$$=Array.isArray($rawValue$$)?$rawValue$$.join("; "):$rawValue$$;break;case "boolean":$displayValue_i$$=$rawValue$$?"C\u00f3":"Kh\u00f4ng";break;case "currency":case "number":$displayValue_i$$=Number($rawValue$$).toLocaleString("en-US");
37break;default:$displayValue_i$$=String($rawValue$$).trim()}$listInfoCode_text$$+=`${$indent_info$$}- ${$header$$}: ${$displayValue_i$$}.\n`}}return $listInfoCode_text$$}
38const extractFeatureKeywords=$rawQuery$$=>{var $q_withContext$$=$rawQuery$$.trim();$q_withContext$$=$q_withContext$$.replace(/^(t\u00f4i|anh|ch\u1ecb|em|m\u00ecnh|s\u1ebfp|boss)?\s*(mu\u1ed1n|c\u1ea7n|h\u00e3y|cho\s+(?:t\u00f4i|anh|em|m\u00ecnh)|gi\u00fap\s+(?:t\u00f4i|anh|em|m\u00ecnh))?\s*/i,"");$q_withContext$$=$q_withContext$$.replace(/^(t
39$q_withContext$$=$q_withContext$$.replace(/\s*(th\u00ec)?\s*(v\u00e0o \u0111\u00e2u|\u1edf \u0111\u00e2u|link n\u00e0o|link \u0111\u1ebfn|\u0111\u01b0\u1eddng d\u1eabn|\u0111\u01b0\u1eddng link|m\u00e0n h\u00ecnh n\u00e0o|ch\u1ee9c n\u0103
40"").trim(),$keywords$$=[];$withoutContext$$&&$withoutContext$$.toLowerCase()!==$rawQuery$$.toLowerCase()&&$keywords$$.push($withoutContext$$);$q_withContext$$&&$q_withContext$$.toLowerCase()!==$withoutContext$$.toLowerCase()&&$q_withContext$$.toLowerCase()!==$rawQuery$$.toLowerCase()&&$keywords$$.push($q_withContext$$);$keywords$$.push($rawQuery$$);return[...(new Set($keywords$$))].filter($k$$=>$k$$.length>1)};
41async function findRefDocsByKeyword($RefModel$$,$stringFields$$,$keyword$$,$id_app$$){const $tryFind$$=async $orConditions_query$$=>{$orConditions_query$$={$or:$orConditions_query$$};$RefModel$$.schema.paths.id_app&&($orConditions_query$$.id_app=$id_app$$);$RefModel$$.schema.paths.id_apps&&$RefModel$$.schema.paths.id_apps.instance==="Array"&&($orConditions_query$$.$and||($orConditions_query$$.$and=[]),$orConditions_query$$.$and.push({$or:[{id_apps:$id_app$$},{id_apps:null},{"id_apps.0":{$exists:!1}}]}));
42return await $RefModel$$.find($orConditions_query$$).lean()};var $docs_words$$=await $tryFind$$($stringFields$$.map($f$$=>({[$f$$]:{$regex:`^${escapeRegex($keyword$$)}$`,$options:"i"}})));if($docs_words$$.length>0)return{docs:$docs_words$$,matchedBy:"exact"};$docs_words$$=await $tryFind$$($stringFields$$.map($f$$=>({[$f$$]:{$regex:escapeRegex($keyword$$),$options:"i"}})));if($docs_words$$.length>0)return{docs:$docs_words$$,matchedBy:"contains_phrase"};$docs_words$$=String($keyword$$).split(/\s+/).filter($w$$=>
43$w$$.length>1);return $docs_words$$.length>1&&($docs_words$$=await $tryFind$$($docs_words$$.flatMap($w$$=>$stringFields$$.map($f$$=>({[$f$$]:{$regex:escapeRegex($w$$),$options:"i"}})))),$docs_words$$.length>0)?{docs:$docs_words$$,matchedBy:"fuzzy_words"}:{docs:[],matchedBy:"none"}}
44async function resolveRefMetaByKeyword($refMeta_values$$,$keyword$$,$docs$jscomp$1_id_app$$){var $stringFields$$=($refMeta_values$$.listinfo_code||$refMeta_values$$.ref_model).toUpperCase();const $RefModel$$=global.controllers[$stringFields$$]?.model||global.getModel($refMeta_values$$.ref_model);if(!$RefModel$$)return{error:`Kh\u00f4ng t\u00ecm th\u1ea5y model danh m\u1ee5c li\u00ean k\u1ebft '${$refMeta_values$$.ref_model}'.`};$stringFields$$=Object.keys($RefModel$$.schema.paths).filter($p$$=>$RefModel$$.schema.paths[$p$$].instance===
45"String"&&!["id_app","user_created"].includes($p$$));({docs:$docs$jscomp$1_id_app$$}=await findRefDocsByKeyword($RefModel$$,$stringFields$$,$keyword$$,$docs$jscomp$1_id_app$$));if($docs$jscomp$1_id_app$$.length===0)return{error:`Kh\u00f4ng t\u00ecm th\u1ea5y '${$keyword$$}' trong danh m\u1ee5c li\u00ean k\u1ebft '${$refMeta_values$$.ref_model}'.`};const $valueField$$=$refMeta_values$$.value_field||"_id";$refMeta_values$$=$docs$jscomp$1_id_app$$.map($d$$=>$valueField$$==="_id"?$d$$._id?$d$$._id.toString():
46$d$$.id:$d$$[$valueField$$]);return{values:$refMeta_values$$,count:$refMeta_values$$.length,refModel:$RefModel$$}}
47async function resolveDirectRefFilter($matched_pathDef$$,$keyword$$,$id_app$$){if(!$matched_pathDef$$)return{error:"Field kh\u00f4ng t\u1ed3n t\u1ea1i trong schema."};if($matched_pathDef$$.ref&&$matched_pathDef$$.ref.ref_model)return await resolveRefMetaByKeyword($matched_pathDef$$.ref,$keyword$$,$id_app$$);if($matched_pathDef$$.options&&Array.isArray($matched_pathDef$$.options.options)){const $labelField$$=$matched_pathDef$$.options.label_field||"name",$valueField$$=$matched_pathDef$$.options.value_field||
48"code";$matched_pathDef$$=$matched_pathDef$$.options.options.filter($o$$=>$o$$[$labelField$$]&&$o$$[$labelField$$].toLowerCase().includes($keyword$$.toLowerCase())||$o$$[$valueField$$]&&$o$$[$valueField$$].toLowerCase()===$keyword$$.toLowerCase());return $matched_pathDef$$.length===0?{error:`Gi\u00e1 tr\u1ecb '${$keyword$$}' kh\u00f4ng h\u1ee3p l\u1ec7.`}:{values:$matched_pathDef$$.map($o$$=>$o$$[$valueField$$]),count:$matched_pathDef$$.length}}return{error:"Field kh\u00f4ng h\u1ed7 tr\u1ee3 l\u1ecdc theo t\u1eeb kh\u00f3a (kh\u00f4ng c\u00f3 ref/options)."}}
49async function resolveHopChain($hops$$,$keyword$$,$id_app$$){var $currentValues_query$$=null;for(let $i$$=0;$i$$<$hops$$.length;$i$$++){const $hop$$=$hops$$[$i$$],$stepLabel$$=`b\u01b0\u1edbc ${$i$$+1}/${$hops$$.length} ('${$hop$$.controller}.${$hop$$.field}')`,$HopCtrl$$=global.controllers[$hop$$.controller.toUpperCase()];if(!$HopCtrl$$)return{error:`Kh\u00f4ng t\u00ecm th\u1ea5y controller trung gian '${$hop$$.controller}' (${$stepLabel$$}).`};var $HopModel_hopDocs$$=$HopCtrl$$.model||global.getModel($hop$$.controller.toLowerCase());
50if(!$HopModel_hopDocs$$)return{error:`Kh\u00f4ng t\u00ecm th\u1ea5y model c\u1ee7a controller trung gian '${$hop$$.controller}' (${$stepLabel$$}).`};if($HopModel_hopDocs$$.schema?.paths&&!$HopModel_hopDocs$$.schema.paths[$hop$$.field])return{error:`Tr\u01b0\u1eddng b\u1eafc c\u1ea7u '${$hop$$.field}' KH\u00d4NG T\u1ed2N T\u1ea0I trong controller '${$hop$$.controller}' \u2014 c\u00f3 th\u1ec3 t\u00ean field \u0111\u00e3 b\u1ecb \u0111o\u00e1n sai. H\u00e3y g\u1ecdi exploreSystemSchemaTool \u0111\u1ec3 x\u00e1c nh\u1eadn \u0111\u00fang t\u00ean field tr\u01b0\u1edbc khi b\u1eafc c\u1ea7u (${$ste ...
51let $matchCondition$$=null;if($currentValues_query$$===null){if(typeof $HopCtrl$$.getJsonSchema==="function")try{const $hopPathDef$$=(await $HopCtrl$$.getJsonSchema($id_app$$))?.[$hop$$.field];if($hopPathDef$$?.ref?.ref_model){const $resolved$$=await resolveRefMetaByKeyword($hopPathDef$$.ref,$keyword$$,$id_app$$);if
52$e$$.message)}$matchCondition$$||={[$hop$$.field]:{$regex:escapeRegex($keyword$$),$options:"i"}}}else $matchCondition$$={[$hop$$.field]:{$in:$currentValues_query$$}};$currentValues_query$$={...$matchCondition$$};$HopModel_hopDocs$$.schema.paths.id_app&&($currentValues_query$$.id_app=$id_app$$);$HopModel_hopDocs$$.schema.paths.id_apps&&$HopModel_hopDocs$$.schema.paths.id_apps.instance==="Array"&&($currentValues_query$$.$and||($currentValues_query$$.$and=[]),$currentValues_query$$.$and.push({$or:[{id_apps:$id_app$$},
53{id_apps:null},{"id_apps.0":{$exists:!1}}]}));$HopModel_hopDocs$$=await $HopModel_hopDocs$$.find($currentValues_query$$).lean();if($HopModel_hopDocs$$.length===0)return{error:`Kh\u00f4ng t\u00ecm th\u1ea5y d\u1eef li\u1ec7u n\u00e0o kh\u1edb
Long lines were clipped for display.