@elizaos/plugin-action-bench 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -4
- package/dist/index.cjs +798 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +798 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
@@ -866,15 +866,811 @@ var multiverseMathActions = [
|
|
866
866
|
transferAction
|
867
867
|
];
|
868
868
|
|
869
|
+
// src/actions/relationalData.ts
|
870
|
+
function getRelationalState(state) {
|
871
|
+
return {
|
872
|
+
entities: state?.values?.entities || {},
|
873
|
+
relationships: state?.values?.relationships || {},
|
874
|
+
currentEntity: state?.values?.currentEntity || null,
|
875
|
+
queryResults: state?.values?.queryResults || []
|
876
|
+
};
|
877
|
+
}
|
878
|
+
function generateId(prefix) {
|
879
|
+
const timestamp = Date.now();
|
880
|
+
const random = Math.floor(Math.random() * 1e3);
|
881
|
+
return `${prefix}_${timestamp}_${random}`;
|
882
|
+
}
|
883
|
+
var createEntityAction = {
|
884
|
+
name: "CREATE_ENTITY",
|
885
|
+
similes: ["NEW_ENTITY", "ADD_ENTITY", "MAKE_ENTITY"],
|
886
|
+
description: "Create a new entity with a type and name. Entities are the nodes in our relational graph.",
|
887
|
+
validate: async () => true,
|
888
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
889
|
+
const relState = getRelationalState(state);
|
890
|
+
const content = message.content.text?.toLowerCase() || "";
|
891
|
+
let entityType = "generic";
|
892
|
+
let entityName = "unnamed";
|
893
|
+
if (content.includes("person")) entityType = "person";
|
894
|
+
else if (content.includes("company")) entityType = "company";
|
895
|
+
else if (content.includes("product")) entityType = "product";
|
896
|
+
else if (content.includes("location")) entityType = "location";
|
897
|
+
else if (content.includes("project")) entityType = "project";
|
898
|
+
else if (content.includes("department")) entityType = "department";
|
899
|
+
else if (content.includes("task")) entityType = "task";
|
900
|
+
else if (content.includes("document")) entityType = "document";
|
901
|
+
const nameMatch = content.match(/named?\s+["']?([^"']+)["']?/i) || content.match(/called\s+["']?([^"']+)["']?/i) || content.match(/:\s*["']?([^"']+)["']?/i);
|
902
|
+
if (nameMatch) {
|
903
|
+
entityName = nameMatch[1].trim();
|
904
|
+
}
|
905
|
+
const entityId = generateId("entity");
|
906
|
+
const entity = {
|
907
|
+
id: entityId,
|
908
|
+
type: entityType,
|
909
|
+
name: entityName,
|
910
|
+
attributes: {},
|
911
|
+
created: (/* @__PURE__ */ new Date()).toISOString()
|
912
|
+
};
|
913
|
+
relState.entities[entityId] = entity;
|
914
|
+
relState.currentEntity = entityId;
|
915
|
+
const text = `Created entity: ${entityName} (${entityType}) with ID: ${entityId}`;
|
916
|
+
if (callback) {
|
917
|
+
await callback({ text, source: message.content.source });
|
918
|
+
}
|
919
|
+
return {
|
920
|
+
success: true,
|
921
|
+
text,
|
922
|
+
values: {
|
923
|
+
...state?.values,
|
924
|
+
entities: relState.entities,
|
925
|
+
currentEntity: entityId,
|
926
|
+
lastOperation: "create_entity"
|
927
|
+
},
|
928
|
+
data: {
|
929
|
+
operation: "create_entity",
|
930
|
+
entity,
|
931
|
+
totalEntities: Object.keys(relState.entities).length
|
932
|
+
}
|
933
|
+
};
|
934
|
+
},
|
935
|
+
examples: [
|
936
|
+
[
|
937
|
+
{
|
938
|
+
name: "{{user}}",
|
939
|
+
content: { text: "create person entity named John" }
|
940
|
+
},
|
941
|
+
{
|
942
|
+
name: "{{agent}}",
|
943
|
+
content: {
|
944
|
+
text: "Created entity: John (person) with ID: entity_...",
|
945
|
+
actions: ["CREATE_ENTITY"]
|
946
|
+
}
|
947
|
+
}
|
948
|
+
]
|
949
|
+
]
|
950
|
+
};
|
951
|
+
var createRelationshipAction = {
|
952
|
+
name: "CREATE_RELATIONSHIP",
|
953
|
+
similes: ["LINK", "CONNECT", "RELATE"],
|
954
|
+
description: "Create a relationship between two entities. Relationships are the edges in our relational graph.",
|
955
|
+
validate: async (_runtime, _message, state) => {
|
956
|
+
const relState = getRelationalState(state);
|
957
|
+
return Object.keys(relState.entities).length >= 2;
|
958
|
+
},
|
959
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
960
|
+
const relState = getRelationalState(state);
|
961
|
+
const entities = Object.values(relState.entities);
|
962
|
+
if (entities.length < 2) {
|
963
|
+
return {
|
964
|
+
success: false,
|
965
|
+
text: "Error: Need at least 2 entities to create a relationship",
|
966
|
+
values: state?.values || {}
|
967
|
+
};
|
968
|
+
}
|
969
|
+
const content = message.content.text?.toLowerCase() || "";
|
970
|
+
let relationType = "related_to";
|
971
|
+
if (content.includes("parent") || content.includes("child")) relationType = "parent_child";
|
972
|
+
else if (content.includes("sibling")) relationType = "sibling";
|
973
|
+
else if (content.includes("friend")) relationType = "friend";
|
974
|
+
else if (content.includes("employee") || content.includes("works")) relationType = "employment";
|
975
|
+
else if (content.includes("owns") || content.includes("owner")) relationType = "ownership";
|
976
|
+
else if (content.includes("manages") || content.includes("reports")) relationType = "management";
|
977
|
+
else if (content.includes("partner")) relationType = "partnership";
|
978
|
+
else if (content.includes("member")) relationType = "membership";
|
979
|
+
else if (content.includes("located")) relationType = "location";
|
980
|
+
else if (content.includes("assigned")) relationType = "assignment";
|
981
|
+
let fromEntity;
|
982
|
+
let toEntity;
|
983
|
+
if (relState.currentEntity && relState.entities[relState.currentEntity]) {
|
984
|
+
fromEntity = relState.entities[relState.currentEntity];
|
985
|
+
toEntity = entities.filter((e) => e.id !== relState.currentEntity)[entities.length - 2] || entities[0];
|
986
|
+
} else {
|
987
|
+
fromEntity = entities[entities.length - 1];
|
988
|
+
toEntity = entities[entities.length - 2];
|
989
|
+
}
|
990
|
+
const relationshipId = generateId("rel");
|
991
|
+
const relationship = {
|
992
|
+
id: relationshipId,
|
993
|
+
type: relationType,
|
994
|
+
fromEntity: fromEntity.id,
|
995
|
+
toEntity: toEntity.id,
|
996
|
+
properties: {},
|
997
|
+
created: (/* @__PURE__ */ new Date()).toISOString()
|
998
|
+
};
|
999
|
+
relState.relationships[relationshipId] = relationship;
|
1000
|
+
const text = `Created ${relationType} relationship: ${fromEntity.name} \u2192 ${toEntity.name}`;
|
1001
|
+
if (callback) {
|
1002
|
+
await callback({ text, source: message.content.source });
|
1003
|
+
}
|
1004
|
+
return {
|
1005
|
+
success: true,
|
1006
|
+
text,
|
1007
|
+
values: {
|
1008
|
+
...state?.values,
|
1009
|
+
relationships: relState.relationships,
|
1010
|
+
lastOperation: "create_relationship"
|
1011
|
+
},
|
1012
|
+
data: {
|
1013
|
+
operation: "create_relationship",
|
1014
|
+
relationship,
|
1015
|
+
fromEntity: fromEntity.name,
|
1016
|
+
toEntity: toEntity.name,
|
1017
|
+
totalRelationships: Object.keys(relState.relationships).length
|
1018
|
+
}
|
1019
|
+
};
|
1020
|
+
},
|
1021
|
+
examples: [
|
1022
|
+
[
|
1023
|
+
{
|
1024
|
+
name: "{{user}}",
|
1025
|
+
content: { text: "create parent relationship" }
|
1026
|
+
},
|
1027
|
+
{
|
1028
|
+
name: "{{agent}}",
|
1029
|
+
content: {
|
1030
|
+
text: "Created parent_child relationship: Entity1 \u2192 Entity2",
|
1031
|
+
actions: ["CREATE_RELATIONSHIP"]
|
1032
|
+
}
|
1033
|
+
}
|
1034
|
+
]
|
1035
|
+
]
|
1036
|
+
};
|
1037
|
+
var setAttributeAction = {
|
1038
|
+
name: "SET_ATTRIBUTE",
|
1039
|
+
similes: ["ADD_ATTRIBUTE", "SET_PROPERTY", "UPDATE_ATTRIBUTE"],
|
1040
|
+
description: "Set an attribute on the current entity. Attributes store additional data on entities.",
|
1041
|
+
validate: async (_runtime, _message, state) => {
|
1042
|
+
const relState = getRelationalState(state);
|
1043
|
+
return relState.currentEntity !== null && relState.entities[relState.currentEntity] !== void 0;
|
1044
|
+
},
|
1045
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1046
|
+
const relState = getRelationalState(state);
|
1047
|
+
if (!relState.currentEntity || !relState.entities[relState.currentEntity]) {
|
1048
|
+
return {
|
1049
|
+
success: false,
|
1050
|
+
text: "Error: No current entity selected",
|
1051
|
+
values: state?.values || {}
|
1052
|
+
};
|
1053
|
+
}
|
1054
|
+
const entity = relState.entities[relState.currentEntity];
|
1055
|
+
const content = message.content.text || "";
|
1056
|
+
let key = "property";
|
1057
|
+
let value = "value";
|
1058
|
+
const ageMatch = content.match(/age[:\s]+(\d+)/i);
|
1059
|
+
const emailMatch = content.match(/email[:\s]+([^\s]+)/i);
|
1060
|
+
const phoneMatch = content.match(/phone[:\s]+([^\s]+)/i);
|
1061
|
+
const statusMatch = content.match(/status[:\s]+([^\s]+)/i);
|
1062
|
+
const roleMatch = content.match(/role[:\s]+([^\s]+)/i);
|
1063
|
+
const departmentMatch = content.match(/department[:\s]+([^\s]+)/i);
|
1064
|
+
const salaryMatch = content.match(/salary[:\s]+(\d+)/i);
|
1065
|
+
const locationMatch = content.match(/location[:\s]+([^\s]+)/i);
|
1066
|
+
if (ageMatch) {
|
1067
|
+
key = "age";
|
1068
|
+
value = parseInt(ageMatch[1]);
|
1069
|
+
} else if (emailMatch) {
|
1070
|
+
key = "email";
|
1071
|
+
value = emailMatch[1];
|
1072
|
+
} else if (phoneMatch) {
|
1073
|
+
key = "phone";
|
1074
|
+
value = phoneMatch[1];
|
1075
|
+
} else if (statusMatch) {
|
1076
|
+
key = "status";
|
1077
|
+
value = statusMatch[1];
|
1078
|
+
} else if (roleMatch) {
|
1079
|
+
key = "role";
|
1080
|
+
value = roleMatch[1];
|
1081
|
+
} else if (departmentMatch) {
|
1082
|
+
key = "department";
|
1083
|
+
value = departmentMatch[1];
|
1084
|
+
} else if (salaryMatch) {
|
1085
|
+
key = "salary";
|
1086
|
+
value = parseInt(salaryMatch[1]);
|
1087
|
+
} else if (locationMatch) {
|
1088
|
+
key = "location";
|
1089
|
+
value = locationMatch[1];
|
1090
|
+
} else {
|
1091
|
+
const genericMatch = content.match(/(\w+)[:\s=]+([^\s]+)/i);
|
1092
|
+
if (genericMatch) {
|
1093
|
+
key = genericMatch[1];
|
1094
|
+
value = genericMatch[2];
|
1095
|
+
const numValue = parseFloat(value);
|
1096
|
+
if (!isNaN(numValue)) value = numValue;
|
1097
|
+
}
|
1098
|
+
}
|
1099
|
+
entity.attributes[key] = value;
|
1100
|
+
const text = `Set attribute on ${entity.name}: ${key} = ${value}`;
|
1101
|
+
if (callback) {
|
1102
|
+
await callback({ text, source: message.content.source });
|
1103
|
+
}
|
1104
|
+
return {
|
1105
|
+
success: true,
|
1106
|
+
text,
|
1107
|
+
values: {
|
1108
|
+
...state?.values,
|
1109
|
+
entities: relState.entities,
|
1110
|
+
lastOperation: "set_attribute"
|
1111
|
+
},
|
1112
|
+
data: {
|
1113
|
+
operation: "set_attribute",
|
1114
|
+
entityId: entity.id,
|
1115
|
+
entityName: entity.name,
|
1116
|
+
attribute: { key, value },
|
1117
|
+
totalAttributes: Object.keys(entity.attributes).length
|
1118
|
+
}
|
1119
|
+
};
|
1120
|
+
},
|
1121
|
+
examples: [
|
1122
|
+
[
|
1123
|
+
{
|
1124
|
+
name: "{{user}}",
|
1125
|
+
content: { text: "set age 25" }
|
1126
|
+
},
|
1127
|
+
{
|
1128
|
+
name: "{{agent}}",
|
1129
|
+
content: {
|
1130
|
+
text: "Set attribute on Entity: age = 25",
|
1131
|
+
actions: ["SET_ATTRIBUTE"]
|
1132
|
+
}
|
1133
|
+
}
|
1134
|
+
]
|
1135
|
+
]
|
1136
|
+
};
|
1137
|
+
var queryRelationshipsAction = {
|
1138
|
+
name: "QUERY_RELATIONSHIPS",
|
1139
|
+
similes: ["FIND_RELATIONSHIPS", "GET_CONNECTIONS", "SHOW_LINKS"],
|
1140
|
+
description: "Query relationships of a specific type or for a specific entity.",
|
1141
|
+
validate: async () => true,
|
1142
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1143
|
+
const relState = getRelationalState(state);
|
1144
|
+
const content = message.content.text?.toLowerCase() || "";
|
1145
|
+
let results = [];
|
1146
|
+
let queryDescription = "";
|
1147
|
+
if (content.includes("parent")) {
|
1148
|
+
results = Object.values(relState.relationships).filter((r) => r.type === "parent_child").map((r) => ({
|
1149
|
+
type: r.type,
|
1150
|
+
from: relState.entities[r.fromEntity]?.name || r.fromEntity,
|
1151
|
+
to: relState.entities[r.toEntity]?.name || r.toEntity
|
1152
|
+
}));
|
1153
|
+
queryDescription = "parent-child relationships";
|
1154
|
+
} else if (content.includes("sibling")) {
|
1155
|
+
results = Object.values(relState.relationships).filter((r) => r.type === "sibling").map((r) => ({
|
1156
|
+
type: r.type,
|
1157
|
+
from: relState.entities[r.fromEntity]?.name || r.fromEntity,
|
1158
|
+
to: relState.entities[r.toEntity]?.name || r.toEntity
|
1159
|
+
}));
|
1160
|
+
queryDescription = "sibling relationships";
|
1161
|
+
} else if (content.includes("all")) {
|
1162
|
+
results = Object.values(relState.relationships).map((r) => ({
|
1163
|
+
type: r.type,
|
1164
|
+
from: relState.entities[r.fromEntity]?.name || r.fromEntity,
|
1165
|
+
to: relState.entities[r.toEntity]?.name || r.toEntity
|
1166
|
+
}));
|
1167
|
+
queryDescription = "all relationships";
|
1168
|
+
} else if (relState.currentEntity) {
|
1169
|
+
results = Object.values(relState.relationships).filter((r) => r.fromEntity === relState.currentEntity || r.toEntity === relState.currentEntity).map((r) => ({
|
1170
|
+
type: r.type,
|
1171
|
+
from: relState.entities[r.fromEntity]?.name || r.fromEntity,
|
1172
|
+
to: relState.entities[r.toEntity]?.name || r.toEntity,
|
1173
|
+
direction: r.fromEntity === relState.currentEntity ? "outgoing" : "incoming"
|
1174
|
+
}));
|
1175
|
+
queryDescription = `relationships for ${relState.entities[relState.currentEntity]?.name}`;
|
1176
|
+
}
|
1177
|
+
const text = `Found ${results.length} ${queryDescription}`;
|
1178
|
+
if (callback) {
|
1179
|
+
await callback({ text, source: message.content.source });
|
1180
|
+
}
|
1181
|
+
return {
|
1182
|
+
success: true,
|
1183
|
+
text,
|
1184
|
+
values: {
|
1185
|
+
...state?.values,
|
1186
|
+
queryResults: results,
|
1187
|
+
lastOperation: "query_relationships"
|
1188
|
+
},
|
1189
|
+
data: {
|
1190
|
+
operation: "query_relationships",
|
1191
|
+
query: queryDescription,
|
1192
|
+
results,
|
1193
|
+
count: results.length
|
1194
|
+
}
|
1195
|
+
};
|
1196
|
+
},
|
1197
|
+
examples: [
|
1198
|
+
[
|
1199
|
+
{
|
1200
|
+
name: "{{user}}",
|
1201
|
+
content: { text: "query parent relationships" }
|
1202
|
+
},
|
1203
|
+
{
|
1204
|
+
name: "{{agent}}",
|
1205
|
+
content: {
|
1206
|
+
text: "Found 0 parent-child relationships",
|
1207
|
+
actions: ["QUERY_RELATIONSHIPS"]
|
1208
|
+
}
|
1209
|
+
}
|
1210
|
+
]
|
1211
|
+
]
|
1212
|
+
};
|
1213
|
+
var queryEntitiesAction = {
|
1214
|
+
name: "QUERY_ENTITIES",
|
1215
|
+
similes: ["FIND_ENTITIES", "SEARCH_ENTITIES", "LIST_ENTITIES"],
|
1216
|
+
description: "Query entities by type or attribute values.",
|
1217
|
+
validate: async () => true,
|
1218
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1219
|
+
const relState = getRelationalState(state);
|
1220
|
+
const content = message.content.text?.toLowerCase() || "";
|
1221
|
+
let results = [];
|
1222
|
+
let queryDescription = "";
|
1223
|
+
if (content.includes("person")) {
|
1224
|
+
results = Object.values(relState.entities).filter((e) => e.type === "person");
|
1225
|
+
queryDescription = "person entities";
|
1226
|
+
} else if (content.includes("company")) {
|
1227
|
+
results = Object.values(relState.entities).filter((e) => e.type === "company");
|
1228
|
+
queryDescription = "company entities";
|
1229
|
+
} else if (content.includes("product")) {
|
1230
|
+
results = Object.values(relState.entities).filter((e) => e.type === "product");
|
1231
|
+
queryDescription = "product entities";
|
1232
|
+
} else if (content.includes("all")) {
|
1233
|
+
results = Object.values(relState.entities);
|
1234
|
+
queryDescription = "all entities";
|
1235
|
+
} else {
|
1236
|
+
const ageMatch = content.match(/age\s*[><=]+\s*(\d+)/);
|
1237
|
+
if (ageMatch) {
|
1238
|
+
const age = parseInt(ageMatch[1]);
|
1239
|
+
results = Object.values(relState.entities).filter((e) => {
|
1240
|
+
const entityAge = e.attributes.age;
|
1241
|
+
if (typeof entityAge !== "number") return false;
|
1242
|
+
if (content.includes(">")) return entityAge > age;
|
1243
|
+
if (content.includes("<")) return entityAge < age;
|
1244
|
+
return entityAge === age;
|
1245
|
+
});
|
1246
|
+
queryDescription = `entities with age ${ageMatch[0]}`;
|
1247
|
+
} else {
|
1248
|
+
results = Object.values(relState.entities);
|
1249
|
+
queryDescription = "all entities";
|
1250
|
+
}
|
1251
|
+
}
|
1252
|
+
const resultSummary = results.map((e) => ({
|
1253
|
+
id: e.id,
|
1254
|
+
name: e.name,
|
1255
|
+
type: e.type,
|
1256
|
+
attributes: e.attributes
|
1257
|
+
}));
|
1258
|
+
const text = `Found ${results.length} ${queryDescription}`;
|
1259
|
+
if (callback) {
|
1260
|
+
await callback({ text, source: message.content.source });
|
1261
|
+
}
|
1262
|
+
return {
|
1263
|
+
success: true,
|
1264
|
+
text,
|
1265
|
+
values: {
|
1266
|
+
...state?.values,
|
1267
|
+
queryResults: resultSummary,
|
1268
|
+
lastOperation: "query_entities"
|
1269
|
+
},
|
1270
|
+
data: {
|
1271
|
+
operation: "query_entities",
|
1272
|
+
query: queryDescription,
|
1273
|
+
results: resultSummary,
|
1274
|
+
count: results.length
|
1275
|
+
}
|
1276
|
+
};
|
1277
|
+
},
|
1278
|
+
examples: [
|
1279
|
+
[
|
1280
|
+
{
|
1281
|
+
name: "{{user}}",
|
1282
|
+
content: { text: "query person entities" }
|
1283
|
+
},
|
1284
|
+
{
|
1285
|
+
name: "{{agent}}",
|
1286
|
+
content: {
|
1287
|
+
text: "Found 0 person entities",
|
1288
|
+
actions: ["QUERY_ENTITIES"]
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
]
|
1292
|
+
]
|
1293
|
+
};
|
1294
|
+
var selectEntityAction = {
|
1295
|
+
name: "SELECT_ENTITY",
|
1296
|
+
similes: ["CHOOSE_ENTITY", "FOCUS_ENTITY", "SET_CURRENT_ENTITY"],
|
1297
|
+
description: "Select an entity as the current entity for operations.",
|
1298
|
+
validate: async (_runtime, _message, state) => {
|
1299
|
+
const relState = getRelationalState(state);
|
1300
|
+
return Object.keys(relState.entities).length > 0;
|
1301
|
+
},
|
1302
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1303
|
+
const relState = getRelationalState(state);
|
1304
|
+
const content = message.content.text || "";
|
1305
|
+
if (Object.keys(relState.entities).length === 0) {
|
1306
|
+
return {
|
1307
|
+
success: false,
|
1308
|
+
text: "Error: No entities exist to select",
|
1309
|
+
values: state?.values || {}
|
1310
|
+
};
|
1311
|
+
}
|
1312
|
+
let selectedEntity;
|
1313
|
+
for (const entity of Object.values(relState.entities)) {
|
1314
|
+
if (content.toLowerCase().includes(entity.name.toLowerCase())) {
|
1315
|
+
selectedEntity = entity;
|
1316
|
+
break;
|
1317
|
+
}
|
1318
|
+
}
|
1319
|
+
if (!selectedEntity) {
|
1320
|
+
const entities = Object.values(relState.entities);
|
1321
|
+
selectedEntity = entities[entities.length - 1];
|
1322
|
+
}
|
1323
|
+
relState.currentEntity = selectedEntity.id;
|
1324
|
+
const text = `Selected entity: ${selectedEntity.name} (${selectedEntity.type})`;
|
1325
|
+
if (callback) {
|
1326
|
+
await callback({ text, source: message.content.source });
|
1327
|
+
}
|
1328
|
+
return {
|
1329
|
+
success: true,
|
1330
|
+
text,
|
1331
|
+
values: {
|
1332
|
+
...state?.values,
|
1333
|
+
currentEntity: selectedEntity.id,
|
1334
|
+
lastOperation: "select_entity"
|
1335
|
+
},
|
1336
|
+
data: {
|
1337
|
+
operation: "select_entity",
|
1338
|
+
entity: selectedEntity
|
1339
|
+
}
|
1340
|
+
};
|
1341
|
+
},
|
1342
|
+
examples: [
|
1343
|
+
[
|
1344
|
+
{
|
1345
|
+
name: "{{user}}",
|
1346
|
+
content: { text: "select entity John" }
|
1347
|
+
},
|
1348
|
+
{
|
1349
|
+
name: "{{agent}}",
|
1350
|
+
content: {
|
1351
|
+
text: "Selected entity: John (person)",
|
1352
|
+
actions: ["SELECT_ENTITY"]
|
1353
|
+
}
|
1354
|
+
}
|
1355
|
+
]
|
1356
|
+
]
|
1357
|
+
};
|
1358
|
+
var deleteEntityAction = {
|
1359
|
+
name: "DELETE_ENTITY",
|
1360
|
+
similes: ["REMOVE_ENTITY", "DESTROY_ENTITY"],
|
1361
|
+
description: "Delete the current entity and all its relationships.",
|
1362
|
+
validate: async (_runtime, _message, state) => {
|
1363
|
+
const relState = getRelationalState(state);
|
1364
|
+
return relState.currentEntity !== null && relState.entities[relState.currentEntity] !== void 0;
|
1365
|
+
},
|
1366
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1367
|
+
const relState = getRelationalState(state);
|
1368
|
+
if (!relState.currentEntity || !relState.entities[relState.currentEntity]) {
|
1369
|
+
return {
|
1370
|
+
success: false,
|
1371
|
+
text: "Error: No current entity selected",
|
1372
|
+
values: state?.values || {}
|
1373
|
+
};
|
1374
|
+
}
|
1375
|
+
const entity = relState.entities[relState.currentEntity];
|
1376
|
+
const entityName = entity.name;
|
1377
|
+
delete relState.entities[relState.currentEntity];
|
1378
|
+
const relationshipsToDelete = [];
|
1379
|
+
for (const [relId, rel] of Object.entries(relState.relationships)) {
|
1380
|
+
if (rel.fromEntity === relState.currentEntity || rel.toEntity === relState.currentEntity) {
|
1381
|
+
relationshipsToDelete.push(relId);
|
1382
|
+
}
|
1383
|
+
}
|
1384
|
+
for (const relId of relationshipsToDelete) {
|
1385
|
+
delete relState.relationships[relId];
|
1386
|
+
}
|
1387
|
+
relState.currentEntity = null;
|
1388
|
+
const text = `Deleted entity: ${entityName} and ${relationshipsToDelete.length} relationships`;
|
1389
|
+
if (callback) {
|
1390
|
+
await callback({ text, source: message.content.source });
|
1391
|
+
}
|
1392
|
+
return {
|
1393
|
+
success: true,
|
1394
|
+
text,
|
1395
|
+
values: {
|
1396
|
+
...state?.values,
|
1397
|
+
entities: relState.entities,
|
1398
|
+
relationships: relState.relationships,
|
1399
|
+
currentEntity: null,
|
1400
|
+
lastOperation: "delete_entity"
|
1401
|
+
},
|
1402
|
+
data: {
|
1403
|
+
operation: "delete_entity",
|
1404
|
+
deletedEntity: entityName,
|
1405
|
+
deletedRelationships: relationshipsToDelete.length,
|
1406
|
+
remainingEntities: Object.keys(relState.entities).length
|
1407
|
+
}
|
1408
|
+
};
|
1409
|
+
},
|
1410
|
+
examples: [
|
1411
|
+
[
|
1412
|
+
{
|
1413
|
+
name: "{{user}}",
|
1414
|
+
content: { text: "delete current entity" }
|
1415
|
+
},
|
1416
|
+
{
|
1417
|
+
name: "{{agent}}",
|
1418
|
+
content: {
|
1419
|
+
text: "Deleted entity: EntityName and 0 relationships",
|
1420
|
+
actions: ["DELETE_ENTITY"]
|
1421
|
+
}
|
1422
|
+
}
|
1423
|
+
]
|
1424
|
+
]
|
1425
|
+
};
|
1426
|
+
var countStatisticsAction = {
|
1427
|
+
name: "COUNT_STATISTICS",
|
1428
|
+
similes: ["STATS", "STATISTICS", "COUNT"],
|
1429
|
+
description: "Get statistics about the current relational data graph.",
|
1430
|
+
validate: async () => true,
|
1431
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1432
|
+
const relState = getRelationalState(state);
|
1433
|
+
const totalEntities = Object.keys(relState.entities).length;
|
1434
|
+
const totalRelationships = Object.keys(relState.relationships).length;
|
1435
|
+
const entityTypes = {};
|
1436
|
+
for (const entity of Object.values(relState.entities)) {
|
1437
|
+
entityTypes[entity.type] = (entityTypes[entity.type] || 0) + 1;
|
1438
|
+
}
|
1439
|
+
const relationshipTypes = {};
|
1440
|
+
for (const rel of Object.values(relState.relationships)) {
|
1441
|
+
relationshipTypes[rel.type] = (relationshipTypes[rel.type] || 0) + 1;
|
1442
|
+
}
|
1443
|
+
let totalAttributes = 0;
|
1444
|
+
for (const entity of Object.values(relState.entities)) {
|
1445
|
+
totalAttributes += Object.keys(entity.attributes).length;
|
1446
|
+
}
|
1447
|
+
const stats = {
|
1448
|
+
totalEntities,
|
1449
|
+
totalRelationships,
|
1450
|
+
totalAttributes,
|
1451
|
+
entityTypes,
|
1452
|
+
relationshipTypes,
|
1453
|
+
currentEntity: relState.currentEntity ? relState.entities[relState.currentEntity]?.name : "none"
|
1454
|
+
};
|
1455
|
+
const text = `Graph statistics: ${totalEntities} entities, ${totalRelationships} relationships, ${totalAttributes} attributes`;
|
1456
|
+
if (callback) {
|
1457
|
+
await callback({ text, source: message.content.source });
|
1458
|
+
}
|
1459
|
+
return {
|
1460
|
+
success: true,
|
1461
|
+
text,
|
1462
|
+
values: {
|
1463
|
+
...state?.values,
|
1464
|
+
queryResults: [stats],
|
1465
|
+
lastOperation: "count_statistics"
|
1466
|
+
},
|
1467
|
+
data: {
|
1468
|
+
operation: "count_statistics",
|
1469
|
+
statistics: stats
|
1470
|
+
}
|
1471
|
+
};
|
1472
|
+
},
|
1473
|
+
examples: [
|
1474
|
+
[
|
1475
|
+
{
|
1476
|
+
name: "{{user}}",
|
1477
|
+
content: { text: "show statistics" }
|
1478
|
+
},
|
1479
|
+
{
|
1480
|
+
name: "{{agent}}",
|
1481
|
+
content: {
|
1482
|
+
text: "Graph statistics: 0 entities, 0 relationships, 0 attributes",
|
1483
|
+
actions: ["COUNT_STATISTICS"]
|
1484
|
+
}
|
1485
|
+
}
|
1486
|
+
]
|
1487
|
+
]
|
1488
|
+
};
|
1489
|
+
var clearGraphAction = {
|
1490
|
+
name: "CLEAR_GRAPH",
|
1491
|
+
similes: ["RESET_GRAPH", "CLEAR_ALL", "DELETE_ALL"],
|
1492
|
+
description: "Clear all entities and relationships from the graph.",
|
1493
|
+
validate: async () => true,
|
1494
|
+
handler: async (_runtime, message, _state, _options, callback) => {
|
1495
|
+
const text = "Cleared all entities and relationships";
|
1496
|
+
if (callback) {
|
1497
|
+
await callback({ text, source: message.content.source });
|
1498
|
+
}
|
1499
|
+
return {
|
1500
|
+
success: true,
|
1501
|
+
text,
|
1502
|
+
values: {
|
1503
|
+
entities: {},
|
1504
|
+
relationships: {},
|
1505
|
+
currentEntity: null,
|
1506
|
+
queryResults: [],
|
1507
|
+
lastOperation: "clear_graph"
|
1508
|
+
},
|
1509
|
+
data: {
|
1510
|
+
operation: "clear_graph"
|
1511
|
+
}
|
1512
|
+
};
|
1513
|
+
},
|
1514
|
+
examples: [
|
1515
|
+
[
|
1516
|
+
{
|
1517
|
+
name: "{{user}}",
|
1518
|
+
content: { text: "clear graph" }
|
1519
|
+
},
|
1520
|
+
{
|
1521
|
+
name: "{{agent}}",
|
1522
|
+
content: {
|
1523
|
+
text: "Cleared all entities and relationships",
|
1524
|
+
actions: ["CLEAR_GRAPH"]
|
1525
|
+
}
|
1526
|
+
}
|
1527
|
+
]
|
1528
|
+
]
|
1529
|
+
};
|
1530
|
+
var findPathAction = {
|
1531
|
+
name: "FIND_PATH",
|
1532
|
+
similes: ["PATH", "ROUTE", "CONNECTION_PATH"],
|
1533
|
+
description: "Find the shortest path between two entities in the relationship graph.",
|
1534
|
+
validate: async (_runtime, _message, state) => {
|
1535
|
+
const relState = getRelationalState(state);
|
1536
|
+
return Object.keys(relState.entities).length >= 2;
|
1537
|
+
},
|
1538
|
+
handler: async (_runtime, message, state, _options, callback) => {
|
1539
|
+
const relState = getRelationalState(state);
|
1540
|
+
if (Object.keys(relState.entities).length < 2) {
|
1541
|
+
return {
|
1542
|
+
success: false,
|
1543
|
+
text: "Error: Need at least 2 entities to find a path",
|
1544
|
+
values: state?.values || {}
|
1545
|
+
};
|
1546
|
+
}
|
1547
|
+
const entities = Object.values(relState.entities);
|
1548
|
+
const start = entities[0];
|
1549
|
+
const end = entities[entities.length - 1];
|
1550
|
+
const adjacency = {};
|
1551
|
+
for (const entity of entities) {
|
1552
|
+
adjacency[entity.id] = /* @__PURE__ */ new Set();
|
1553
|
+
}
|
1554
|
+
for (const rel of Object.values(relState.relationships)) {
|
1555
|
+
adjacency[rel.fromEntity]?.add(rel.toEntity);
|
1556
|
+
adjacency[rel.toEntity]?.add(rel.fromEntity);
|
1557
|
+
}
|
1558
|
+
const queue = [{ node: start.id, path: [start.id] }];
|
1559
|
+
const visited = /* @__PURE__ */ new Set();
|
1560
|
+
let foundPath = [];
|
1561
|
+
while (queue.length > 0) {
|
1562
|
+
const current = queue.shift();
|
1563
|
+
if (current.node === end.id) {
|
1564
|
+
foundPath = current.path;
|
1565
|
+
break;
|
1566
|
+
}
|
1567
|
+
if (visited.has(current.node)) continue;
|
1568
|
+
visited.add(current.node);
|
1569
|
+
for (const neighbor of adjacency[current.node] || []) {
|
1570
|
+
if (!visited.has(neighbor)) {
|
1571
|
+
queue.push({
|
1572
|
+
node: neighbor,
|
1573
|
+
path: [...current.path, neighbor]
|
1574
|
+
});
|
1575
|
+
}
|
1576
|
+
}
|
1577
|
+
}
|
1578
|
+
const pathNames = foundPath.map((id) => relState.entities[id]?.name || id);
|
1579
|
+
const text = foundPath.length > 0 ? `Found path: ${pathNames.join(" \u2192 ")}` : `No path found between ${start.name} and ${end.name}`;
|
1580
|
+
if (callback) {
|
1581
|
+
await callback({ text, source: message.content.source });
|
1582
|
+
}
|
1583
|
+
return {
|
1584
|
+
success: true,
|
1585
|
+
text,
|
1586
|
+
values: {
|
1587
|
+
...state?.values,
|
1588
|
+
queryResults: [{ path: pathNames, length: foundPath.length }],
|
1589
|
+
lastOperation: "find_path"
|
1590
|
+
},
|
1591
|
+
data: {
|
1592
|
+
operation: "find_path",
|
1593
|
+
from: start.name,
|
1594
|
+
to: end.name,
|
1595
|
+
path: pathNames,
|
1596
|
+
pathLength: foundPath.length
|
1597
|
+
}
|
1598
|
+
};
|
1599
|
+
},
|
1600
|
+
examples: [
|
1601
|
+
[
|
1602
|
+
{
|
1603
|
+
name: "{{user}}",
|
1604
|
+
content: { text: "find path between entities" }
|
1605
|
+
},
|
1606
|
+
{
|
1607
|
+
name: "{{agent}}",
|
1608
|
+
content: {
|
1609
|
+
text: "Found path: Entity1 \u2192 Entity2",
|
1610
|
+
actions: ["FIND_PATH"]
|
1611
|
+
}
|
1612
|
+
}
|
1613
|
+
]
|
1614
|
+
]
|
1615
|
+
};
|
1616
|
+
var relationalDataActions = [
|
1617
|
+
createEntityAction,
|
1618
|
+
createRelationshipAction,
|
1619
|
+
setAttributeAction,
|
1620
|
+
queryRelationshipsAction,
|
1621
|
+
queryEntitiesAction,
|
1622
|
+
selectEntityAction,
|
1623
|
+
deleteEntityAction,
|
1624
|
+
countStatisticsAction,
|
1625
|
+
clearGraphAction,
|
1626
|
+
findPathAction
|
1627
|
+
];
|
1628
|
+
|
869
1629
|
// src/index.ts
|
1630
|
+
var TYPEWRITER_ENABLED = process.env.TYPEWRITER_ENABLED?.toLowerCase() !== "false";
|
1631
|
+
var MULTIVERSE_MATH_ENABLED = process.env.MULTIVERSE_MATH_ENABLED?.toLowerCase() !== "false";
|
1632
|
+
var RELATIONAL_DATA_ENABLED = process.env.RELATIONAL_DATA_ENABLED?.toLowerCase() !== "false";
|
1633
|
+
function buildActions() {
|
1634
|
+
const actions = [];
|
1635
|
+
if (TYPEWRITER_ENABLED) {
|
1636
|
+
console.log("[plugin-action-bench] Typewriter actions enabled");
|
1637
|
+
actions.push(...typewriterActions);
|
1638
|
+
} else {
|
1639
|
+
console.log("[plugin-action-bench] Typewriter actions disabled via TYPEWRITER_ENABLED=false");
|
1640
|
+
}
|
1641
|
+
if (MULTIVERSE_MATH_ENABLED) {
|
1642
|
+
console.log("[plugin-action-bench] Multiverse math actions enabled");
|
1643
|
+
actions.push(...multiverseMathActions);
|
1644
|
+
} else {
|
1645
|
+
console.log("[plugin-action-bench] Multiverse math actions disabled via MULTIVERSE_MATH_ENABLED=false");
|
1646
|
+
}
|
1647
|
+
if (RELATIONAL_DATA_ENABLED) {
|
1648
|
+
console.log("[plugin-action-bench] Relational data actions enabled");
|
1649
|
+
actions.push(...relationalDataActions);
|
1650
|
+
} else {
|
1651
|
+
console.log("[plugin-action-bench] Relational data actions disabled via RELATIONAL_DATA_ENABLED=false");
|
1652
|
+
}
|
1653
|
+
if (actions.length === 0) {
|
1654
|
+
console.warn("[plugin-action-bench] WARNING: No benchmark actions are enabled. Set TYPEWRITER_ENABLED=true, MULTIVERSE_MATH_ENABLED=true, or RELATIONAL_DATA_ENABLED=true to enable benchmarks.");
|
1655
|
+
}
|
1656
|
+
console.log(`[plugin-action-bench] Total actions loaded: ${actions.length}`);
|
1657
|
+
return actions;
|
1658
|
+
}
|
870
1659
|
var actionBenchPlugin = {
|
871
1660
|
name: "plugin-action-bench",
|
872
|
-
description: "Action benchmark plugin providing typewriter (A\u2013Z)
|
873
|
-
actions:
|
1661
|
+
description: "Action benchmark plugin providing typewriter (A\u2013Z), multiverse math operations with dimensional constants, and relational data management, testing AI agents' ability to handle action chaining, context-dependent operations, and complex data relationships.",
|
1662
|
+
actions: buildActions()
|
1663
|
+
};
|
1664
|
+
var benchmarkConfig = {
|
1665
|
+
typewriterEnabled: TYPEWRITER_ENABLED,
|
1666
|
+
multiverseMathEnabled: MULTIVERSE_MATH_ENABLED,
|
1667
|
+
relationalDataEnabled: RELATIONAL_DATA_ENABLED,
|
1668
|
+
totalActionsLoaded: actionBenchPlugin.actions?.length ?? 0
|
874
1669
|
};
|
875
1670
|
var index_default = actionBenchPlugin;
|
876
1671
|
|
877
1672
|
exports.actionBenchPlugin = actionBenchPlugin;
|
1673
|
+
exports.benchmarkConfig = benchmarkConfig;
|
878
1674
|
exports.default = index_default;
|
879
1675
|
//# sourceMappingURL=index.cjs.map
|
880
1676
|
//# sourceMappingURL=index.cjs.map
|