Warn about confusing agent tool catalogs
This commit is contained in:
@@ -195,6 +195,35 @@ document.addEventListener('alpine:init', function() {
|
||||
return this.tKey(this.isCommunityBuild ? 'agents.drawer.operations_sub_community' : 'agents.drawer.operations_sub');
|
||||
},
|
||||
|
||||
get selectedOperations() {
|
||||
var selected = this.form.selectedOps;
|
||||
return this.operations.filter(function(operation) {
|
||||
return selected.includes(operation.id);
|
||||
});
|
||||
},
|
||||
|
||||
get agentToolFindings() {
|
||||
var findings = [];
|
||||
var selected = this.selectedOperations;
|
||||
if (selected.length > 8) {
|
||||
findings.push(this.tKey('agents.drawer.finding.too_many_tools'));
|
||||
}
|
||||
|
||||
for (var leftIndex = 0; leftIndex < selected.length; leftIndex += 1) {
|
||||
for (var rightIndex = leftIndex + 1; rightIndex < selected.length; rightIndex += 1) {
|
||||
if (this.operationsLookSimilar(selected[leftIndex], selected[rightIndex])) {
|
||||
findings.push(this.tfKey('agents.drawer.finding.similar_tools', {
|
||||
left: selected[leftIndex].display_name || selected[leftIndex].name,
|
||||
right: selected[rightIndex].display_name || selected[rightIndex].name,
|
||||
}));
|
||||
return findings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return findings;
|
||||
},
|
||||
|
||||
get filteredOps() {
|
||||
var query = this.opSearch.toLowerCase().trim();
|
||||
if (!query) return this.operations;
|
||||
@@ -267,6 +296,28 @@ document.addEventListener('alpine:init', function() {
|
||||
return this.form.selectedOps.includes(operationId);
|
||||
},
|
||||
|
||||
operationsLookSimilar(left, right) {
|
||||
var leftTokens = this.operationTokens(left);
|
||||
var rightTokens = this.operationTokens(right);
|
||||
if (!leftTokens.length || !rightTokens.length) return false;
|
||||
var shared = leftTokens.filter(function(token) { return rightTokens.includes(token); }).length;
|
||||
var smaller = Math.min(leftTokens.length, rightTokens.length);
|
||||
return shared >= 2 && (shared / smaller) >= 0.6;
|
||||
},
|
||||
|
||||
operationTokens(operation) {
|
||||
var text = [
|
||||
operation.name || '',
|
||||
operation.display_name || '',
|
||||
].join(' ').toLowerCase();
|
||||
var tokens = [];
|
||||
text.split(/[^a-z0-9а-яё]+/i).forEach(function(token) {
|
||||
if (token.length < 3 || tokens.includes(token)) return;
|
||||
tokens.push(token);
|
||||
});
|
||||
return tokens;
|
||||
},
|
||||
|
||||
async saveAgent() {
|
||||
var self = this;
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user