@elizaos/core 1.0.0-alpha.62 → 1.0.0-alpha.64
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/dist/actions/choice.d.ts +1 -1
- package/dist/actions/followRoom.d.ts +1 -1
- package/dist/actions/ignore.d.ts +1 -1
- package/dist/actions/muteRoom.d.ts +1 -1
- package/dist/actions/none.d.ts +1 -1
- package/dist/actions/reply.d.ts +1 -1
- package/dist/actions/roles.d.ts +1 -1
- package/dist/actions/sendMessage.d.ts +1 -1
- package/dist/actions/settings.d.ts +1 -1
- package/dist/actions/unfollowRoom.d.ts +1 -1
- package/dist/actions/unmuteRoom.d.ts +1 -1
- package/dist/actions/updateEntity.d.ts +1 -1
- package/dist/actions.d.ts +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/database.d.ts +18 -5
- package/dist/entities.d.ts +1 -1
- package/dist/evaluators/reflection.d.ts +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.js +844 -1071
- package/dist/prompts.d.ts +1 -1
- package/dist/providers/actions.d.ts +1 -1
- package/dist/providers/anxiety.d.ts +1 -1
- package/dist/providers/attachments.d.ts +1 -1
- package/dist/providers/capabilities.d.ts +1 -1
- package/dist/providers/character.d.ts +1 -1
- package/dist/providers/choice.d.ts +1 -1
- package/dist/providers/entities.d.ts +1 -1
- package/dist/providers/evaluators.d.ts +1 -1
- package/dist/providers/facts.d.ts +1 -1
- package/dist/providers/knowledge.d.ts +1 -1
- package/dist/providers/providers.d.ts +1 -1
- package/dist/providers/recentMessages.d.ts +1 -1
- package/dist/providers/relationships.d.ts +1 -1
- package/dist/providers/roles.d.ts +1 -1
- package/dist/providers/settings.d.ts +1 -1
- package/dist/providers/shouldRespond.d.ts +1 -1
- package/dist/providers/time.d.ts +1 -1
- package/dist/roles.d.ts +1 -1
- package/dist/runtime.d.ts +36 -13
- package/dist/services/index.d.ts +1 -0
- package/dist/services/scenario.d.ts +1 -1
- package/dist/services/task.d.ts +1 -1
- package/dist/services/websocket.d.ts +73 -0
- package/dist/settings.d.ts +1 -1
- package/dist/test_resources/constants.d.ts +1 -1
- package/dist/types.d.ts +50 -41
- package/dist/uuid.d.ts +2 -2
- package/package.json +74 -70
- package/dist/environment.d.ts +0 -403
package/dist/index.js
CHANGED
|
@@ -4,7 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
8
14
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
15
|
};
|
|
10
16
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -121,23 +127,29 @@ var MemoryType = /* @__PURE__ */ ((MemoryType2) => {
|
|
|
121
127
|
})(MemoryType || {});
|
|
122
128
|
var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
|
|
123
129
|
ChannelType2["SELF"] = "SELF";
|
|
124
|
-
ChannelType2["DM"] = "
|
|
125
|
-
ChannelType2["GROUP"] = "
|
|
130
|
+
ChannelType2["DM"] = "dm";
|
|
131
|
+
ChannelType2["GROUP"] = "group";
|
|
126
132
|
ChannelType2["VOICE_DM"] = "VOICE_DM";
|
|
127
133
|
ChannelType2["VOICE_GROUP"] = "VOICE_GROUP";
|
|
128
134
|
ChannelType2["FEED"] = "FEED";
|
|
129
135
|
ChannelType2["THREAD"] = "THREAD";
|
|
130
136
|
ChannelType2["WORLD"] = "WORLD";
|
|
131
|
-
ChannelType2["API"] = "API";
|
|
132
137
|
ChannelType2["FORUM"] = "FORUM";
|
|
138
|
+
ChannelType2["API"] = "API";
|
|
133
139
|
return ChannelType2;
|
|
134
140
|
})(ChannelType || {});
|
|
135
141
|
var Service = class {
|
|
142
|
+
/** Runtime instance */
|
|
143
|
+
runtime;
|
|
136
144
|
constructor(runtime) {
|
|
137
145
|
if (runtime) {
|
|
138
146
|
this.runtime = runtime;
|
|
139
147
|
}
|
|
140
148
|
}
|
|
149
|
+
/** Service type */
|
|
150
|
+
static serviceType;
|
|
151
|
+
/** Service configuration */
|
|
152
|
+
config;
|
|
141
153
|
/** Start service connection */
|
|
142
154
|
static async start(_runtime) {
|
|
143
155
|
throw new Error("Not implemented");
|
|
@@ -162,6 +174,7 @@ var CacheKeyPrefix = /* @__PURE__ */ ((CacheKeyPrefix2) => {
|
|
|
162
174
|
return CacheKeyPrefix2;
|
|
163
175
|
})(CacheKeyPrefix || {});
|
|
164
176
|
var TeeLogDAO = class {
|
|
177
|
+
db;
|
|
165
178
|
};
|
|
166
179
|
var TEEMode = /* @__PURE__ */ ((TEEMode2) => {
|
|
167
180
|
TEEMode2["OFF"] = "OFF";
|
|
@@ -181,31 +194,31 @@ var Role = /* @__PURE__ */ ((Role2) => {
|
|
|
181
194
|
Role2["NONE"] = "NONE";
|
|
182
195
|
return Role2;
|
|
183
196
|
})(Role || {});
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return
|
|
208
|
-
})(
|
|
197
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
198
|
+
EventType2["WORLD_JOINED"] = "WORLD_JOINED";
|
|
199
|
+
EventType2["WORLD_CONNECTED"] = "WORLD_CONNECTED";
|
|
200
|
+
EventType2["WORLD_LEFT"] = "WORLD_LEFT";
|
|
201
|
+
EventType2["ENTITY_JOINED"] = "ENTITY_JOINED";
|
|
202
|
+
EventType2["ENTITY_LEFT"] = "ENTITY_LEFT";
|
|
203
|
+
EventType2["ENTITY_UPDATED"] = "ENTITY_UPDATED";
|
|
204
|
+
EventType2["ROOM_JOINED"] = "ROOM_JOINED";
|
|
205
|
+
EventType2["ROOM_LEFT"] = "ROOM_LEFT";
|
|
206
|
+
EventType2["MESSAGE_RECEIVED"] = "MESSAGE_RECEIVED";
|
|
207
|
+
EventType2["MESSAGE_SENT"] = "MESSAGE_SENT";
|
|
208
|
+
EventType2["VOICE_MESSAGE_RECEIVED"] = "VOICE_MESSAGE_RECEIVED";
|
|
209
|
+
EventType2["VOICE_MESSAGE_SENT"] = "VOICE_MESSAGE_SENT";
|
|
210
|
+
EventType2["REACTION_RECEIVED"] = "REACTION_RECEIVED";
|
|
211
|
+
EventType2["POST_GENERATED"] = "POST_GENERATED";
|
|
212
|
+
EventType2["INTERACTION_RECEIVED"] = "INTERACTION_RECEIVED";
|
|
213
|
+
EventType2["RUN_STARTED"] = "RUN_STARTED";
|
|
214
|
+
EventType2["RUN_ENDED"] = "RUN_ENDED";
|
|
215
|
+
EventType2["RUN_TIMEOUT"] = "RUN_TIMEOUT";
|
|
216
|
+
EventType2["ACTION_STARTED"] = "ACTION_STARTED";
|
|
217
|
+
EventType2["ACTION_COMPLETED"] = "ACTION_COMPLETED";
|
|
218
|
+
EventType2["EVALUATOR_STARTED"] = "EVALUATOR_STARTED";
|
|
219
|
+
EventType2["EVALUATOR_COMPLETED"] = "EVALUATOR_COMPLETED";
|
|
220
|
+
return EventType2;
|
|
221
|
+
})(EventType || {});
|
|
209
222
|
var PlatformPrefix = /* @__PURE__ */ ((PlatformPrefix2) => {
|
|
210
223
|
PlatformPrefix2["DISCORD"] = "DISCORD";
|
|
211
224
|
PlatformPrefix2["TELEGRAM"] = "TELEGRAM";
|
|
@@ -215,6 +228,9 @@ var PlatformPrefix = /* @__PURE__ */ ((PlatformPrefix2) => {
|
|
|
215
228
|
var SOCKET_MESSAGE_TYPE = /* @__PURE__ */ ((SOCKET_MESSAGE_TYPE2) => {
|
|
216
229
|
SOCKET_MESSAGE_TYPE2[SOCKET_MESSAGE_TYPE2["ROOM_JOINING"] = 1] = "ROOM_JOINING";
|
|
217
230
|
SOCKET_MESSAGE_TYPE2[SOCKET_MESSAGE_TYPE2["SEND_MESSAGE"] = 2] = "SEND_MESSAGE";
|
|
231
|
+
SOCKET_MESSAGE_TYPE2[SOCKET_MESSAGE_TYPE2["MESSAGE"] = 3] = "MESSAGE";
|
|
232
|
+
SOCKET_MESSAGE_TYPE2[SOCKET_MESSAGE_TYPE2["ACK"] = 4] = "ACK";
|
|
233
|
+
SOCKET_MESSAGE_TYPE2[SOCKET_MESSAGE_TYPE2["THINKING"] = 5] = "THINKING";
|
|
218
234
|
return SOCKET_MESSAGE_TYPE2;
|
|
219
235
|
})(SOCKET_MESSAGE_TYPE || {});
|
|
220
236
|
function createMessageMemory(params) {
|
|
@@ -284,9 +300,7 @@ function createServiceError(error, code = "UNKNOWN_ERROR") {
|
|
|
284
300
|
// src/actions.ts
|
|
285
301
|
import { names, uniqueNamesGenerator } from "unique-names-generator";
|
|
286
302
|
var composeActionExamples = (actionsData, count) => {
|
|
287
|
-
const data = actionsData.map((action) => [
|
|
288
|
-
...action.examples
|
|
289
|
-
]);
|
|
303
|
+
const data = actionsData.map((action) => [...action.examples]);
|
|
290
304
|
const actionExamples = [];
|
|
291
305
|
let length = data.length;
|
|
292
306
|
for (let i = 0; i < count && length; i++) {
|
|
@@ -312,10 +326,7 @@ var composeActionExamples = (actionsData, count) => {
|
|
|
312
326
|
${example.map((message) => {
|
|
313
327
|
let messageString = `${message.name}: ${message.content.text}${message.content.action ? ` (action: ${message.content.action})` : ""}${message.content.actions ? ` (actions: ${message.content.actions.join(", ")})` : ""}`;
|
|
314
328
|
for (let i = 0; i < exampleNames.length; i++) {
|
|
315
|
-
messageString = messageString.replaceAll(
|
|
316
|
-
`{{name${i + 1}}}`,
|
|
317
|
-
exampleNames[i]
|
|
318
|
-
);
|
|
329
|
+
messageString = messageString.replaceAll(`{{name${i + 1}}}`, exampleNames[i]);
|
|
319
330
|
}
|
|
320
331
|
return messageString;
|
|
321
332
|
}).join("\n")}`;
|
|
@@ -331,6 +342,10 @@ function formatActions(actions) {
|
|
|
331
342
|
|
|
332
343
|
// src/database.ts
|
|
333
344
|
var DatabaseAdapter = class {
|
|
345
|
+
/**
|
|
346
|
+
* The database instance.
|
|
347
|
+
*/
|
|
348
|
+
db;
|
|
334
349
|
};
|
|
335
350
|
|
|
336
351
|
// src/prompts.ts
|
|
@@ -354,13 +369,15 @@ function parseBooleanFromText(value) {
|
|
|
354
369
|
return false;
|
|
355
370
|
}
|
|
356
371
|
var InMemoryDestination = class {
|
|
372
|
+
logs = [];
|
|
373
|
+
maxLogs = 1e3;
|
|
374
|
+
// Keep last 1000 logs
|
|
375
|
+
stream;
|
|
357
376
|
/**
|
|
358
377
|
* Constructor for creating a new instance of the class.
|
|
359
378
|
* @param {DestinationStream|null} stream - The stream to assign to the instance. Can be null.
|
|
360
379
|
*/
|
|
361
380
|
constructor(stream) {
|
|
362
|
-
this.logs = [];
|
|
363
|
-
this.maxLogs = 1e3;
|
|
364
381
|
this.stream = stream;
|
|
365
382
|
}
|
|
366
383
|
/**
|
|
@@ -370,16 +387,46 @@ var InMemoryDestination = class {
|
|
|
370
387
|
* @returns {void}
|
|
371
388
|
*/
|
|
372
389
|
write(data) {
|
|
373
|
-
|
|
390
|
+
let logEntry;
|
|
391
|
+
let stringData;
|
|
392
|
+
if (typeof data === "string") {
|
|
393
|
+
stringData = data;
|
|
394
|
+
try {
|
|
395
|
+
logEntry = JSON.parse(data);
|
|
396
|
+
} catch (e) {
|
|
397
|
+
if (this.stream) {
|
|
398
|
+
this.stream.write(data);
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
} else {
|
|
403
|
+
logEntry = data;
|
|
404
|
+
stringData = JSON.stringify(data);
|
|
405
|
+
}
|
|
374
406
|
if (!logEntry.time) {
|
|
375
407
|
logEntry.time = Date.now();
|
|
376
408
|
}
|
|
409
|
+
const isDebugMode2 = (process?.env?.LOG_LEVEL || "").toLowerCase() === "debug";
|
|
410
|
+
const isLoggingDiagnostic = Boolean(process?.env?.LOG_DIAGNOSTIC);
|
|
411
|
+
if (isLoggingDiagnostic) {
|
|
412
|
+
logEntry.diagnostic = true;
|
|
413
|
+
}
|
|
414
|
+
if (!isDebugMode2) {
|
|
415
|
+
if (logEntry.agentName && logEntry.agentId) {
|
|
416
|
+
const msg = logEntry.msg || "";
|
|
417
|
+
if (typeof msg === "string" && (msg.includes("registered successfully") || msg.includes("Registering") || msg.includes("Success:") || msg.includes("linked to") || msg.includes("Started"))) {
|
|
418
|
+
if (isLoggingDiagnostic) {
|
|
419
|
+
console.error("Filtered log:", stringData);
|
|
420
|
+
}
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
377
425
|
this.logs.push(logEntry);
|
|
378
426
|
if (this.logs.length > this.maxLogs) {
|
|
379
427
|
this.logs.shift();
|
|
380
428
|
}
|
|
381
429
|
if (this.stream) {
|
|
382
|
-
const stringData = typeof data === "string" ? data : JSON.stringify(data);
|
|
383
430
|
this.stream.write(stringData);
|
|
384
431
|
}
|
|
385
432
|
}
|
|
@@ -404,6 +451,8 @@ var customLevels = {
|
|
|
404
451
|
trace: 10
|
|
405
452
|
};
|
|
406
453
|
var raw = parseBooleanFromText(process?.env?.LOG_JSON_FORMAT) || false;
|
|
454
|
+
var isDebugMode = (process?.env?.LOG_LEVEL || "").toLowerCase() === "debug";
|
|
455
|
+
var effectiveLogLevel = isDebugMode ? "debug" : process?.env?.DEFAULT_LOG_LEVEL || "info";
|
|
407
456
|
var createStream = async () => {
|
|
408
457
|
if (raw) {
|
|
409
458
|
return void 0;
|
|
@@ -413,11 +462,12 @@ var createStream = async () => {
|
|
|
413
462
|
colorize: true,
|
|
414
463
|
translateTime: "yyyy-mm-dd HH:MM:ss",
|
|
415
464
|
ignore: "pid,hostname"
|
|
465
|
+
// Don't use minimumLevel since we're filtering in the destination
|
|
416
466
|
});
|
|
417
467
|
};
|
|
418
|
-
var defaultLevel = process?.env?.DEFAULT_LOG_LEVEL || process?.env?.LOG_LEVEL || "info";
|
|
419
468
|
var options = {
|
|
420
|
-
level:
|
|
469
|
+
level: effectiveLogLevel,
|
|
470
|
+
// Use more restrictive level unless in debug mode
|
|
421
471
|
customLevels,
|
|
422
472
|
hooks: {
|
|
423
473
|
logMethod(inputArgs, method) {
|
|
@@ -430,13 +480,9 @@ var options = {
|
|
|
430
480
|
method.apply(this, [arg1, message]);
|
|
431
481
|
} else {
|
|
432
482
|
const context = {};
|
|
433
|
-
const messageParts = [arg1, ...rest].map(
|
|
434
|
-
(arg) => typeof arg === "string" ? arg : arg
|
|
435
|
-
);
|
|
483
|
+
const messageParts = [arg1, ...rest].map((arg) => typeof arg === "string" ? arg : arg);
|
|
436
484
|
const message = messageParts.filter((part) => typeof part === "string").join(" ");
|
|
437
|
-
const jsonParts = messageParts.filter(
|
|
438
|
-
(part) => typeof part === "object"
|
|
439
|
-
);
|
|
485
|
+
const jsonParts = messageParts.filter((part) => typeof part === "object");
|
|
440
486
|
Object.assign(context, ...jsonParts);
|
|
441
487
|
method.apply(this, [context, message]);
|
|
442
488
|
}
|
|
@@ -445,11 +491,54 @@ var options = {
|
|
|
445
491
|
};
|
|
446
492
|
var logger = pino(options);
|
|
447
493
|
if (typeof process !== "undefined") {
|
|
448
|
-
|
|
494
|
+
let stream = null;
|
|
495
|
+
if (!raw) {
|
|
496
|
+
try {
|
|
497
|
+
const pretty = __require("pino-pretty");
|
|
498
|
+
stream = pretty.default ? pretty.default({
|
|
499
|
+
colorize: true,
|
|
500
|
+
translateTime: "yyyy-mm-dd HH:MM:ss",
|
|
501
|
+
ignore: "pid,hostname",
|
|
502
|
+
customLevels: {
|
|
503
|
+
names: {
|
|
504
|
+
fatal: 60,
|
|
505
|
+
error: 50,
|
|
506
|
+
warn: 40,
|
|
507
|
+
info: 30,
|
|
508
|
+
log: 29,
|
|
509
|
+
progress: 28,
|
|
510
|
+
success: 27,
|
|
511
|
+
debug: 20,
|
|
512
|
+
trace: 10
|
|
513
|
+
},
|
|
514
|
+
// Map custom level values to their display text
|
|
515
|
+
// This ensures consistent level names in pretty-printed output
|
|
516
|
+
customLevelNames: {
|
|
517
|
+
10: "TRACE",
|
|
518
|
+
20: "DEBUG",
|
|
519
|
+
27: "SUCCESS",
|
|
520
|
+
28: "PROGRESS",
|
|
521
|
+
29: "LOG",
|
|
522
|
+
30: "INFO",
|
|
523
|
+
40: "WARN",
|
|
524
|
+
50: "ERROR",
|
|
525
|
+
60: "FATAL"
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}) : null;
|
|
529
|
+
} catch (e) {
|
|
530
|
+
createStream().then((prettyStream) => {
|
|
531
|
+
const destination = new InMemoryDestination(prettyStream);
|
|
532
|
+
logger = pino(options, destination);
|
|
533
|
+
logger[Symbol.for("pino-destination")] = destination;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (stream !== null || raw) {
|
|
449
538
|
const destination = new InMemoryDestination(stream);
|
|
450
539
|
logger = pino(options, destination);
|
|
451
540
|
logger[Symbol.for("pino-destination")] = destination;
|
|
452
|
-
}
|
|
541
|
+
}
|
|
453
542
|
}
|
|
454
543
|
var elizaLogger = logger;
|
|
455
544
|
var logger_default = logger;
|
|
@@ -471,17 +560,12 @@ var composePromptFromState = ({
|
|
|
471
560
|
const templateStr = typeof template === "function" ? template({ state }) : template;
|
|
472
561
|
const templateFunction = handlebars.compile(templateStr);
|
|
473
562
|
const stateKeys = Object.keys(state);
|
|
474
|
-
const filteredKeys = stateKeys.filter(
|
|
475
|
-
(key) => !["text", "values", "data"].includes(key)
|
|
476
|
-
);
|
|
563
|
+
const filteredKeys = stateKeys.filter((key) => !["text", "values", "data"].includes(key));
|
|
477
564
|
const filteredState = filteredKeys.reduce((acc, key) => {
|
|
478
565
|
acc[key] = state[key];
|
|
479
566
|
return acc;
|
|
480
567
|
}, {});
|
|
481
|
-
const output = composeRandomUser(
|
|
482
|
-
templateFunction({ ...filteredState, ...state.values }),
|
|
483
|
-
10
|
|
484
|
-
);
|
|
568
|
+
const output = composeRandomUser(templateFunction({ ...filteredState, ...state.values }), 10);
|
|
485
569
|
return output;
|
|
486
570
|
};
|
|
487
571
|
var addHeader = (header, body) => {
|
|
@@ -522,9 +606,7 @@ var formatPosts = ({
|
|
|
522
606
|
);
|
|
523
607
|
const formattedPosts = sortedRooms.map(([roomId, roomMessages]) => {
|
|
524
608
|
const messageStrings = roomMessages.filter((message) => message.entityId).map((message) => {
|
|
525
|
-
const entity = entities.find(
|
|
526
|
-
(entity2) => entity2.id === message.entityId
|
|
527
|
-
);
|
|
609
|
+
const entity = entities.find((entity2) => entity2.id === message.entityId);
|
|
528
610
|
const userName = entity?.names[0] || "Unknown User";
|
|
529
611
|
const displayName = entity?.names[0] || "unknown";
|
|
530
612
|
return `Name: ${userName} (@${displayName})
|
|
@@ -565,13 +647,7 @@ var formatMessages = ({
|
|
|
565
647
|
const textString = messageText ? `${timestampString} ${formattedName}: ${messageText}` : null;
|
|
566
648
|
const actionString = messageActions && messageActions.length > 0 ? `${textString ? "" : timestampString} (${formattedName}'s actions: ${messageActions.join(", ")})` : null;
|
|
567
649
|
const planString = newestMessageWithContentPlan?.id === message.id ? `(${formattedName}'s plan: ${newestMessageWithContentPlan?.content?.plan})` : null;
|
|
568
|
-
const messageString = [
|
|
569
|
-
textString,
|
|
570
|
-
thoughtString,
|
|
571
|
-
planString,
|
|
572
|
-
actionString,
|
|
573
|
-
attachmentString
|
|
574
|
-
].filter(Boolean).join("\n");
|
|
650
|
+
const messageString = [textString, thoughtString, planString, actionString, attachmentString].filter(Boolean).join("\n");
|
|
575
651
|
return messageString;
|
|
576
652
|
}).join("\n");
|
|
577
653
|
return messageStrings;
|
|
@@ -695,10 +771,7 @@ function parseJsonArrayFromText(text) {
|
|
|
695
771
|
const jsonBlockMatch = text?.match(jsonBlockPattern);
|
|
696
772
|
if (jsonBlockMatch) {
|
|
697
773
|
try {
|
|
698
|
-
const normalizedJson = jsonBlockMatch[1].replace(
|
|
699
|
-
/(?<!\\)'([^']*)'(?=\s*[,}\]])/g,
|
|
700
|
-
'"$1"'
|
|
701
|
-
);
|
|
774
|
+
const normalizedJson = jsonBlockMatch[1].replace(/(?<!\\)'([^']*)'(?=\s*[,}\]])/g, '"$1"');
|
|
702
775
|
jsonData = JSON.parse(normalizeJsonString(normalizedJson));
|
|
703
776
|
} catch (_e) {
|
|
704
777
|
logger_default.warn("Could not parse text as JSON, will try pattern matching");
|
|
@@ -709,10 +782,7 @@ function parseJsonArrayFromText(text) {
|
|
|
709
782
|
const arrayMatch = text.match(arrayPattern);
|
|
710
783
|
if (arrayMatch) {
|
|
711
784
|
try {
|
|
712
|
-
const normalizedJson = arrayMatch[0].replace(
|
|
713
|
-
/(?<!\\)'([^']*)'(?=\s*[,}\]])/g,
|
|
714
|
-
'"$1"'
|
|
715
|
-
);
|
|
785
|
+
const normalizedJson = arrayMatch[0].replace(/(?<!\\)'([^']*)'(?=\s*[,}\]])/g, '"$1"');
|
|
716
786
|
jsonData = JSON.parse(normalizeJsonString(normalizedJson));
|
|
717
787
|
} catch (_e) {
|
|
718
788
|
logger_default.warn("Could not parse text as JSON, returning null");
|
|
@@ -752,9 +822,7 @@ function extractAttributes(response, attributesToExtract) {
|
|
|
752
822
|
}
|
|
753
823
|
} else {
|
|
754
824
|
for (const attribute of attributesToExtract) {
|
|
755
|
-
const match = response.match(
|
|
756
|
-
new RegExp(`"${attribute}"\\s*:\\s*"([^"]*)"`, "i")
|
|
757
|
-
);
|
|
825
|
+
const match = response.match(new RegExp(`"${attribute}"\\s*:\\s*"([^"]*)"`, "i"));
|
|
758
826
|
if (match) {
|
|
759
827
|
attributes[attribute] = match[1];
|
|
760
828
|
}
|
|
@@ -764,14 +832,8 @@ function extractAttributes(response, attributesToExtract) {
|
|
|
764
832
|
}
|
|
765
833
|
var normalizeJsonString = (str) => {
|
|
766
834
|
str = str.replace(/\{\s+/, "{").replace(/\s+\}/, "}").trim();
|
|
767
|
-
str = str.replace(
|
|
768
|
-
|
|
769
|
-
'$1: "$2"'
|
|
770
|
-
);
|
|
771
|
-
str = str.replace(
|
|
772
|
-
/"([^"]+)"\s*:\s*'([^']*)'/g,
|
|
773
|
-
(_, key, value) => `"${key}": "${value}"`
|
|
774
|
-
);
|
|
835
|
+
str = str.replace(/("[\w\d_-]+")\s*: \s*(?!"|\[)([\s\S]+?)(?=(,\s*"|\}$))/g, '$1: "$2"');
|
|
836
|
+
str = str.replace(/"([^"]+)"\s*:\s*'([^']*)'/g, (_, key, value) => `"${key}": "${value}"`);
|
|
775
837
|
str = str.replace(/("[\w\d_-]+")\s*:\s*([A-Za-z_]+)(?!["\w])/g, '$1: "$2"');
|
|
776
838
|
str = str.replace(/(?:"')|(?:'")/g, '"');
|
|
777
839
|
return str;
|
|
@@ -1014,17 +1076,14 @@ async function findEntityByName(runtime, message, state) {
|
|
|
1014
1076
|
if (resolution.matches?.[0]?.name) {
|
|
1015
1077
|
const matchName = resolution.matches[0].name.toLowerCase();
|
|
1016
1078
|
const matchingEntity = allEntities.find((entity) => {
|
|
1017
|
-
if (entity.names.some((n) => n.toLowerCase() === matchName))
|
|
1018
|
-
return true;
|
|
1079
|
+
if (entity.names.some((n) => n.toLowerCase() === matchName)) return true;
|
|
1019
1080
|
return entity.components?.some(
|
|
1020
1081
|
(c) => c.data.username?.toLowerCase() === matchName || c.data.handle?.toLowerCase() === matchName
|
|
1021
1082
|
);
|
|
1022
1083
|
});
|
|
1023
1084
|
if (matchingEntity) {
|
|
1024
1085
|
if (resolution.type === "RELATIONSHIP_MATCH") {
|
|
1025
|
-
const interactionInfo = interactionData.find(
|
|
1026
|
-
(d) => d.entity.id === matchingEntity.id
|
|
1027
|
-
);
|
|
1086
|
+
const interactionInfo = interactionData.find((d) => d.entity.id === matchingEntity.id);
|
|
1028
1087
|
if (interactionInfo && interactionInfo.count > 0) {
|
|
1029
1088
|
return matchingEntity;
|
|
1030
1089
|
}
|
|
@@ -1093,175 +1152,6 @@ Data: ${JSON.stringify(entity.metadata)}
|
|
|
1093
1152
|
return entityStrings.join("\n");
|
|
1094
1153
|
}
|
|
1095
1154
|
|
|
1096
|
-
// src/environment.ts
|
|
1097
|
-
import fs from "node:fs";
|
|
1098
|
-
import path from "node:path";
|
|
1099
|
-
import { config } from "dotenv";
|
|
1100
|
-
import { z } from "zod";
|
|
1101
|
-
var environmentSettings = {};
|
|
1102
|
-
var isBrowser = () => {
|
|
1103
|
-
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
1104
|
-
};
|
|
1105
|
-
function findNearestEnvFile(startDir = process.cwd()) {
|
|
1106
|
-
if (isBrowser()) return null;
|
|
1107
|
-
let currentDir = startDir;
|
|
1108
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
1109
|
-
const envPath = path.join(currentDir, ".env");
|
|
1110
|
-
if (fs.existsSync(envPath)) {
|
|
1111
|
-
return envPath;
|
|
1112
|
-
}
|
|
1113
|
-
currentDir = path.dirname(currentDir);
|
|
1114
|
-
}
|
|
1115
|
-
const rootEnvPath = path.join(path.parse(currentDir).root, ".env");
|
|
1116
|
-
return fs.existsSync(rootEnvPath) ? rootEnvPath : null;
|
|
1117
|
-
}
|
|
1118
|
-
function configureSettings(settings2) {
|
|
1119
|
-
environmentSettings = { ...settings2 };
|
|
1120
|
-
}
|
|
1121
|
-
function loadEnvConfig() {
|
|
1122
|
-
if (isBrowser()) {
|
|
1123
|
-
return environmentSettings;
|
|
1124
|
-
}
|
|
1125
|
-
const envPath = findNearestEnvFile();
|
|
1126
|
-
const result = config(envPath ? { path: envPath } : {});
|
|
1127
|
-
if (!result.error) {
|
|
1128
|
-
logger_default.log(`Loaded .env file from: ${envPath}`);
|
|
1129
|
-
}
|
|
1130
|
-
const env = typeof process !== "undefined" ? process.env : import.meta.env;
|
|
1131
|
-
const namespacedSettings = parseNamespacedSettings(env);
|
|
1132
|
-
if (typeof process !== "undefined") {
|
|
1133
|
-
Object.entries(namespacedSettings).forEach(([namespace, settings2]) => {
|
|
1134
|
-
process.env[`__namespaced_${namespace}`] = JSON.stringify(settings2);
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
return env;
|
|
1138
|
-
}
|
|
1139
|
-
function getEnvVariable(key, defaultValue) {
|
|
1140
|
-
if (isBrowser()) {
|
|
1141
|
-
return environmentSettings[key] || defaultValue;
|
|
1142
|
-
}
|
|
1143
|
-
const env = typeof process !== "undefined" ? process.env : import.meta.env;
|
|
1144
|
-
return env[key] || defaultValue;
|
|
1145
|
-
}
|
|
1146
|
-
function hasEnvVariable(key) {
|
|
1147
|
-
if (isBrowser()) {
|
|
1148
|
-
return key in environmentSettings;
|
|
1149
|
-
}
|
|
1150
|
-
const env = typeof process !== "undefined" ? process.env : import.meta.env;
|
|
1151
|
-
return key in env;
|
|
1152
|
-
}
|
|
1153
|
-
function parseNamespacedSettings(env) {
|
|
1154
|
-
const namespaced = {};
|
|
1155
|
-
for (const [key, value] of Object.entries(env)) {
|
|
1156
|
-
if (!value) continue;
|
|
1157
|
-
const [namespace, ...rest] = key.split(".");
|
|
1158
|
-
if (!namespace || rest.length === 0) continue;
|
|
1159
|
-
const settingKey = rest.join(".");
|
|
1160
|
-
namespaced[namespace] = namespaced[namespace] || {};
|
|
1161
|
-
namespaced[namespace][settingKey] = value;
|
|
1162
|
-
}
|
|
1163
|
-
return namespaced;
|
|
1164
|
-
}
|
|
1165
|
-
var settings = isBrowser() ? environmentSettings : loadEnvConfig();
|
|
1166
|
-
var MessageExampleSchema = z.object({
|
|
1167
|
-
name: z.string(),
|
|
1168
|
-
content: z.object({
|
|
1169
|
-
text: z.string(),
|
|
1170
|
-
action: z.string().optional(),
|
|
1171
|
-
source: z.string().optional(),
|
|
1172
|
-
url: z.string().optional(),
|
|
1173
|
-
inReplyTo: z.string().uuid().optional(),
|
|
1174
|
-
attachments: z.array(z.any()).optional()
|
|
1175
|
-
}).and(z.record(z.string(), z.unknown()))
|
|
1176
|
-
// For additional properties
|
|
1177
|
-
});
|
|
1178
|
-
var PluginSchema = z.object({
|
|
1179
|
-
name: z.string(),
|
|
1180
|
-
description: z.string(),
|
|
1181
|
-
actions: z.array(z.any()).optional(),
|
|
1182
|
-
providers: z.array(z.any()).optional(),
|
|
1183
|
-
evaluators: z.array(z.any()).optional(),
|
|
1184
|
-
services: z.array(z.any()).optional(),
|
|
1185
|
-
clients: z.array(z.any()).optional()
|
|
1186
|
-
});
|
|
1187
|
-
var CharacterSchema = z.object({
|
|
1188
|
-
id: z.string().uuid().optional(),
|
|
1189
|
-
name: z.string(),
|
|
1190
|
-
system: z.string().optional(),
|
|
1191
|
-
templates: z.record(z.string()).optional(),
|
|
1192
|
-
bio: z.union([z.string(), z.array(z.string())]),
|
|
1193
|
-
messageExamples: z.array(z.array(MessageExampleSchema)),
|
|
1194
|
-
postExamples: z.array(z.string()),
|
|
1195
|
-
topics: z.array(z.string()),
|
|
1196
|
-
adjectives: z.array(z.string()),
|
|
1197
|
-
knowledge: z.array(
|
|
1198
|
-
z.union([
|
|
1199
|
-
z.string(),
|
|
1200
|
-
// Direct knowledge strings
|
|
1201
|
-
z.object({
|
|
1202
|
-
// Individual file config
|
|
1203
|
-
path: z.string(),
|
|
1204
|
-
shared: z.boolean().optional()
|
|
1205
|
-
}),
|
|
1206
|
-
z.object({
|
|
1207
|
-
// Directory config
|
|
1208
|
-
directory: z.string(),
|
|
1209
|
-
shared: z.boolean().optional()
|
|
1210
|
-
})
|
|
1211
|
-
])
|
|
1212
|
-
).optional(),
|
|
1213
|
-
plugins: z.union([z.array(z.string()), z.array(PluginSchema)]),
|
|
1214
|
-
settings: z.object({
|
|
1215
|
-
secrets: z.record(z.string()).optional(),
|
|
1216
|
-
voice: z.object({
|
|
1217
|
-
model: z.string().optional(),
|
|
1218
|
-
url: z.string().optional()
|
|
1219
|
-
}).optional(),
|
|
1220
|
-
model: z.string().optional(),
|
|
1221
|
-
modelConfig: z.object({
|
|
1222
|
-
maxInputTokens: z.number().optional(),
|
|
1223
|
-
maxOutputTokens: z.number().optional(),
|
|
1224
|
-
temperature: z.number().optional(),
|
|
1225
|
-
frequency_penalty: z.number().optional(),
|
|
1226
|
-
presence_penalty: z.number().optional()
|
|
1227
|
-
}).optional(),
|
|
1228
|
-
embeddingModel: z.string().optional()
|
|
1229
|
-
}).optional(),
|
|
1230
|
-
style: z.object({
|
|
1231
|
-
all: z.array(z.string()),
|
|
1232
|
-
chat: z.array(z.string()),
|
|
1233
|
-
post: z.array(z.string())
|
|
1234
|
-
})
|
|
1235
|
-
});
|
|
1236
|
-
function validateCharacterConfig(json) {
|
|
1237
|
-
try {
|
|
1238
|
-
return CharacterSchema.parse(json);
|
|
1239
|
-
} catch (error) {
|
|
1240
|
-
if (error instanceof z.ZodError) {
|
|
1241
|
-
const groupedErrors = error.errors.reduce(
|
|
1242
|
-
(acc, err) => {
|
|
1243
|
-
const path3 = err.path.join(".");
|
|
1244
|
-
if (!acc[path3]) {
|
|
1245
|
-
acc[path3] = [];
|
|
1246
|
-
}
|
|
1247
|
-
acc[path3].push(err.message);
|
|
1248
|
-
return acc;
|
|
1249
|
-
},
|
|
1250
|
-
{}
|
|
1251
|
-
);
|
|
1252
|
-
for (const field in groupedErrors) {
|
|
1253
|
-
logger_default.error(
|
|
1254
|
-
`Validation errors in ${field}: ${groupedErrors[field].join(" - ")}`
|
|
1255
|
-
);
|
|
1256
|
-
}
|
|
1257
|
-
throw new Error(
|
|
1258
|
-
"Character configuration validation failed. Check logs for details."
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
throw error;
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
1155
|
// src/import.ts
|
|
1266
1156
|
var registrations = /* @__PURE__ */ new Map();
|
|
1267
1157
|
var dynamicImport = async (specifier) => {
|
|
@@ -1276,7 +1166,6 @@ var registerDynamicImport = (specifier, module) => {
|
|
|
1276
1166
|
};
|
|
1277
1167
|
async function handlePluginImporting(plugins) {
|
|
1278
1168
|
if (plugins.length > 0) {
|
|
1279
|
-
logger_default.debug("Imported are: ", plugins);
|
|
1280
1169
|
const importedPlugins = await Promise.all(
|
|
1281
1170
|
plugins.map(async (plugin) => {
|
|
1282
1171
|
try {
|
|
@@ -1342,8 +1231,8 @@ async function findWorldForOwner(runtime, entityId) {
|
|
|
1342
1231
|
import { v4 as uuidv43 } from "uuid";
|
|
1343
1232
|
|
|
1344
1233
|
// src/bootstrap.ts
|
|
1345
|
-
import
|
|
1346
|
-
import
|
|
1234
|
+
import fs from "node:fs";
|
|
1235
|
+
import path from "node:path";
|
|
1347
1236
|
import { v4 } from "uuid";
|
|
1348
1237
|
|
|
1349
1238
|
// src/actions/choice.ts
|
|
@@ -1388,11 +1277,7 @@ var choiceAction = {
|
|
|
1388
1277
|
tags: ["AWAITING_CHOICE"]
|
|
1389
1278
|
});
|
|
1390
1279
|
const room = state.data.room ?? await runtime.getRoom(message.roomId);
|
|
1391
|
-
const userRole = await getUserServerRole(
|
|
1392
|
-
runtime,
|
|
1393
|
-
message.entityId,
|
|
1394
|
-
room.serverId
|
|
1395
|
-
);
|
|
1280
|
+
const userRole = await getUserServerRole(runtime, message.entityId, room.serverId);
|
|
1396
1281
|
if (userRole !== "OWNER" && userRole !== "ADMIN") {
|
|
1397
1282
|
return false;
|
|
1398
1283
|
}
|
|
@@ -1407,9 +1292,7 @@ var choiceAction = {
|
|
|
1407
1292
|
if (!pendingTasks?.length) {
|
|
1408
1293
|
throw new Error("No pending tasks with options found");
|
|
1409
1294
|
}
|
|
1410
|
-
const tasksWithOptions = pendingTasks.filter(
|
|
1411
|
-
(task) => task.metadata?.options
|
|
1412
|
-
);
|
|
1295
|
+
const tasksWithOptions = pendingTasks.filter((task) => task.metadata?.options);
|
|
1413
1296
|
if (!tasksWithOptions.length) {
|
|
1414
1297
|
throw new Error("No tasks currently have options to select from.");
|
|
1415
1298
|
}
|
|
@@ -1444,9 +1327,7 @@ ${task.options.map((opt) => `- ${opt.name}: ${opt.description}`).join("\n")}`;
|
|
|
1444
1327
|
const parsed = parseJSONObjectFromText(result);
|
|
1445
1328
|
const { taskId, selectedOption } = parsed;
|
|
1446
1329
|
if (taskId && selectedOption) {
|
|
1447
|
-
const taskMap = new Map(
|
|
1448
|
-
formattedTasks.map((task) => [task.taskId, task])
|
|
1449
|
-
);
|
|
1330
|
+
const taskMap = new Map(formattedTasks.map((task) => [task.taskId, task]));
|
|
1450
1331
|
const taskInfo = taskMap.get(taskId);
|
|
1451
1332
|
if (!taskInfo) {
|
|
1452
1333
|
await callback({
|
|
@@ -1456,9 +1337,7 @@ ${task.options.map((opt) => `- ${opt.name}: ${opt.description}`).join("\n")}`;
|
|
|
1456
1337
|
});
|
|
1457
1338
|
return;
|
|
1458
1339
|
}
|
|
1459
|
-
const selectedTask = tasksWithOptions.find(
|
|
1460
|
-
(task) => task.id === taskInfo.fullId
|
|
1461
|
-
);
|
|
1340
|
+
const selectedTask = tasksWithOptions.find((task) => task.id === taskInfo.fullId);
|
|
1462
1341
|
if (!selectedTask) {
|
|
1463
1342
|
await callback({
|
|
1464
1343
|
text: "Error locating the selected task. Please try again.",
|
|
@@ -1478,11 +1357,7 @@ ${task.options.map((opt) => `- ${opt.name}: ${opt.description}`).join("\n")}`;
|
|
|
1478
1357
|
}
|
|
1479
1358
|
try {
|
|
1480
1359
|
const taskWorker = runtime.getTaskWorker(selectedTask.name);
|
|
1481
|
-
await taskWorker.execute(
|
|
1482
|
-
runtime,
|
|
1483
|
-
{ option: selectedOption },
|
|
1484
|
-
selectedTask
|
|
1485
|
-
);
|
|
1360
|
+
await taskWorker.execute(runtime, { option: selectedOption }, selectedTask);
|
|
1486
1361
|
await callback({
|
|
1487
1362
|
text: `Selected option: ${selectedOption} for task: ${selectedTask.name}`,
|
|
1488
1363
|
actions: ["CHOOSE_OPTION"],
|
|
@@ -1574,25 +1449,11 @@ Otherwise, respond with NO.
|
|
|
1574
1449
|
${booleanFooter}`;
|
|
1575
1450
|
var followRoomAction = {
|
|
1576
1451
|
name: "FOLLOW_ROOM",
|
|
1577
|
-
similes: [
|
|
1578
|
-
"FOLLOW_CHAT",
|
|
1579
|
-
"FOLLOW_CHANNEL",
|
|
1580
|
-
"FOLLOW_CONVERSATION",
|
|
1581
|
-
"FOLLOW_THREAD"
|
|
1582
|
-
],
|
|
1452
|
+
similes: ["FOLLOW_CHAT", "FOLLOW_CHANNEL", "FOLLOW_CONVERSATION", "FOLLOW_THREAD"],
|
|
1583
1453
|
description: "Start following this channel with great interest, chiming in without needing to be explicitly mentioned. Only do this if explicitly asked to.",
|
|
1584
1454
|
validate: async (runtime, message) => {
|
|
1585
|
-
const keywords = [
|
|
1586
|
-
|
|
1587
|
-
"participate",
|
|
1588
|
-
"engage",
|
|
1589
|
-
"listen",
|
|
1590
|
-
"take interest",
|
|
1591
|
-
"join"
|
|
1592
|
-
];
|
|
1593
|
-
if (!keywords.some(
|
|
1594
|
-
(keyword) => message.content.text?.toLowerCase().includes(keyword)
|
|
1595
|
-
)) {
|
|
1455
|
+
const keywords = ["follow", "participate", "engage", "listen", "take interest", "join"];
|
|
1456
|
+
if (!keywords.some((keyword) => message.content.text?.toLowerCase().includes(keyword))) {
|
|
1596
1457
|
return false;
|
|
1597
1458
|
}
|
|
1598
1459
|
const roomId = message.roomId;
|
|
@@ -1613,35 +1474,41 @@ var followRoomAction = {
|
|
|
1613
1474
|
});
|
|
1614
1475
|
const cleanedResponse = response.trim().toLowerCase();
|
|
1615
1476
|
if (cleanedResponse === "true" || cleanedResponse === "yes" || cleanedResponse === "y" || cleanedResponse.includes("true") || cleanedResponse.includes("yes")) {
|
|
1616
|
-
await runtime.createMemory(
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1477
|
+
await runtime.createMemory(
|
|
1478
|
+
{
|
|
1479
|
+
entityId: message.entityId,
|
|
1480
|
+
agentId: message.agentId,
|
|
1481
|
+
roomId: message.roomId,
|
|
1482
|
+
content: {
|
|
1483
|
+
source: message.content.source,
|
|
1484
|
+
thought: "I will now follow this room and chime in",
|
|
1485
|
+
actions: ["FOLLOW_ROOM_STARTED"]
|
|
1486
|
+
},
|
|
1487
|
+
metadata: {
|
|
1488
|
+
type: "FOLLOW_ROOM"
|
|
1489
|
+
}
|
|
1624
1490
|
},
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
}
|
|
1628
|
-
}, "messages");
|
|
1491
|
+
"messages"
|
|
1492
|
+
);
|
|
1629
1493
|
return true;
|
|
1630
1494
|
}
|
|
1631
1495
|
if (cleanedResponse === "false" || cleanedResponse === "no" || cleanedResponse === "n" || cleanedResponse.includes("false") || cleanedResponse.includes("no")) {
|
|
1632
|
-
await runtime.createMemory(
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1496
|
+
await runtime.createMemory(
|
|
1497
|
+
{
|
|
1498
|
+
entityId: message.entityId,
|
|
1499
|
+
agentId: message.agentId,
|
|
1500
|
+
roomId: message.roomId,
|
|
1501
|
+
content: {
|
|
1502
|
+
source: message.content.source,
|
|
1503
|
+
thought: "I decided to not follow this room",
|
|
1504
|
+
actions: ["FOLLOW_ROOM_FAILED"]
|
|
1505
|
+
},
|
|
1506
|
+
metadata: {
|
|
1507
|
+
type: "FOLLOW_ROOM"
|
|
1508
|
+
}
|
|
1640
1509
|
},
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
}, "messages");
|
|
1510
|
+
"messages"
|
|
1511
|
+
);
|
|
1645
1512
|
return false;
|
|
1646
1513
|
}
|
|
1647
1514
|
logger_default.warn(`Unclear boolean response: ${response}, defaulting to false`);
|
|
@@ -1651,15 +1518,18 @@ var followRoomAction = {
|
|
|
1651
1518
|
await runtime.setParticipantUserState(message.roomId, runtime.agentId, "FOLLOWED");
|
|
1652
1519
|
}
|
|
1653
1520
|
const room = state.data.room ?? await runtime.getRoom(message.roomId);
|
|
1654
|
-
await runtime.createMemory(
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1521
|
+
await runtime.createMemory(
|
|
1522
|
+
{
|
|
1523
|
+
entityId: message.entityId,
|
|
1524
|
+
agentId: message.agentId,
|
|
1525
|
+
roomId: message.roomId,
|
|
1526
|
+
content: {
|
|
1527
|
+
thought: `I followed the room ${room.name}`,
|
|
1528
|
+
actions: ["FOLLOW_ROOM_START"]
|
|
1529
|
+
}
|
|
1530
|
+
},
|
|
1531
|
+
"messages"
|
|
1532
|
+
);
|
|
1663
1533
|
},
|
|
1664
1534
|
examples: [
|
|
1665
1535
|
[
|
|
@@ -2170,13 +2040,7 @@ Otherwise, respond with NO.
|
|
|
2170
2040
|
${booleanFooter}`;
|
|
2171
2041
|
var muteRoomAction = {
|
|
2172
2042
|
name: "MUTE_ROOM",
|
|
2173
|
-
similes: [
|
|
2174
|
-
"MUTE_CHAT",
|
|
2175
|
-
"MUTE_CONVERSATION",
|
|
2176
|
-
"MUTE_ROOM",
|
|
2177
|
-
"MUTE_THREAD",
|
|
2178
|
-
"MUTE_CHANNEL"
|
|
2179
|
-
],
|
|
2043
|
+
similes: ["MUTE_CHAT", "MUTE_CONVERSATION", "MUTE_ROOM", "MUTE_THREAD", "MUTE_CHANNEL"],
|
|
2180
2044
|
description: "Mutes a room, ignoring all messages unless explicitly mentioned. Only do this if explicitly asked to, or if you're annoying people.",
|
|
2181
2045
|
validate: async (runtime, message) => {
|
|
2182
2046
|
const roomId = message.roomId;
|
|
@@ -2197,35 +2061,41 @@ var muteRoomAction = {
|
|
|
2197
2061
|
});
|
|
2198
2062
|
const cleanedResponse = response.trim().toLowerCase();
|
|
2199
2063
|
if (cleanedResponse === "true" || cleanedResponse === "yes" || cleanedResponse === "y" || cleanedResponse.includes("true") || cleanedResponse.includes("yes")) {
|
|
2200
|
-
await runtime.createMemory(
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2064
|
+
await runtime.createMemory(
|
|
2065
|
+
{
|
|
2066
|
+
entityId: message.entityId,
|
|
2067
|
+
agentId: message.agentId,
|
|
2068
|
+
roomId: message.roomId,
|
|
2069
|
+
content: {
|
|
2070
|
+
source: message.content.source,
|
|
2071
|
+
thought: "I will now mute this room",
|
|
2072
|
+
actions: ["MUTE_ROOM_STARTED"]
|
|
2073
|
+
},
|
|
2074
|
+
metadata: {
|
|
2075
|
+
type: "MUTE_ROOM"
|
|
2076
|
+
}
|
|
2208
2077
|
},
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
}
|
|
2212
|
-
}, "messages");
|
|
2078
|
+
"messages"
|
|
2079
|
+
);
|
|
2213
2080
|
return true;
|
|
2214
2081
|
}
|
|
2215
2082
|
if (cleanedResponse === "false" || cleanedResponse === "no" || cleanedResponse === "n" || cleanedResponse.includes("false") || cleanedResponse.includes("no")) {
|
|
2216
|
-
await runtime.createMemory(
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2083
|
+
await runtime.createMemory(
|
|
2084
|
+
{
|
|
2085
|
+
entityId: message.entityId,
|
|
2086
|
+
agentId: message.agentId,
|
|
2087
|
+
roomId: message.roomId,
|
|
2088
|
+
content: {
|
|
2089
|
+
source: message.content.source,
|
|
2090
|
+
thought: "I decided to not mute this room",
|
|
2091
|
+
actions: ["MUTE_ROOM_FAILED"]
|
|
2092
|
+
},
|
|
2093
|
+
metadata: {
|
|
2094
|
+
type: "MUTE_ROOM"
|
|
2095
|
+
}
|
|
2224
2096
|
},
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
}
|
|
2228
|
-
}, "messages");
|
|
2097
|
+
"messages"
|
|
2098
|
+
);
|
|
2229
2099
|
}
|
|
2230
2100
|
logger_default.warn(`Unclear boolean response: ${response}, defaulting to false`);
|
|
2231
2101
|
return false;
|
|
@@ -2234,15 +2104,18 @@ var muteRoomAction = {
|
|
|
2234
2104
|
await runtime.setParticipantUserState(message.roomId, runtime.agentId, "MUTED");
|
|
2235
2105
|
}
|
|
2236
2106
|
const room = state.data.room ?? await runtime.getRoom(message.roomId);
|
|
2237
|
-
await runtime.createMemory(
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2107
|
+
await runtime.createMemory(
|
|
2108
|
+
{
|
|
2109
|
+
entityId: message.entityId,
|
|
2110
|
+
agentId: message.agentId,
|
|
2111
|
+
roomId: message.roomId,
|
|
2112
|
+
content: {
|
|
2113
|
+
thought: `I muted the room ${room.name}`,
|
|
2114
|
+
actions: ["MUTE_ROOM_START"]
|
|
2115
|
+
}
|
|
2116
|
+
},
|
|
2117
|
+
"messages"
|
|
2118
|
+
);
|
|
2246
2119
|
},
|
|
2247
2120
|
examples: [
|
|
2248
2121
|
[
|
|
@@ -2507,7 +2380,7 @@ Response format should be formatted in a valid JSON block like this:
|
|
|
2507
2380
|
Your response should include the valid JSON block and nothing else.`;
|
|
2508
2381
|
var replyAction = {
|
|
2509
2382
|
name: "REPLY",
|
|
2510
|
-
similes: ["GREET", "REPLY_TO_MESSAGE", "SEND_REPLY", "RESPOND"],
|
|
2383
|
+
similes: ["GREET", "REPLY_TO_MESSAGE", "SEND_REPLY", "RESPOND", "RESPONSE"],
|
|
2511
2384
|
description: "Replies to the current conversation with the text from the generated message. Default if the agent is responding with a message and no other action. Use REPLY at the beginning of a chain of actions as an acknowledgement, and at the end of a chain of actions as a final response.",
|
|
2512
2385
|
validate: async (_runtime) => {
|
|
2513
2386
|
return true;
|
|
@@ -2622,7 +2495,7 @@ var updateRoleAction = {
|
|
|
2622
2495
|
const serverId = message.content.serverId;
|
|
2623
2496
|
return (
|
|
2624
2497
|
// First, check if this is a supported channel type
|
|
2625
|
-
(channelType === "
|
|
2498
|
+
(channelType === "group" /* GROUP */ || channelType === "WORLD" /* WORLD */) && // Then, check if we have a server ID
|
|
2626
2499
|
!!serverId
|
|
2627
2500
|
);
|
|
2628
2501
|
},
|
|
@@ -2685,24 +2558,27 @@ var updateRoleAction = {
|
|
|
2685
2558
|
\`\`\`
|
|
2686
2559
|
`
|
|
2687
2560
|
});
|
|
2688
|
-
const result = await runtime.useModel(
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
type: "
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
type: "string",
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2561
|
+
const result = await runtime.useModel(
|
|
2562
|
+
ModelType.OBJECT_LARGE,
|
|
2563
|
+
{
|
|
2564
|
+
prompt: extractionPrompt,
|
|
2565
|
+
schema: {
|
|
2566
|
+
type: "array",
|
|
2567
|
+
items: {
|
|
2568
|
+
type: "object",
|
|
2569
|
+
properties: {
|
|
2570
|
+
entityId: { type: "string" },
|
|
2571
|
+
newRole: {
|
|
2572
|
+
type: "string",
|
|
2573
|
+
enum: Object.values(Role)
|
|
2574
|
+
}
|
|
2575
|
+
},
|
|
2576
|
+
required: ["entityId", "newRole"]
|
|
2577
|
+
}
|
|
2578
|
+
},
|
|
2579
|
+
output: "array"
|
|
2580
|
+
}
|
|
2581
|
+
);
|
|
2706
2582
|
if (!result?.length) {
|
|
2707
2583
|
await callback({
|
|
2708
2584
|
text: "No valid role assignments found in the request.",
|
|
@@ -2715,11 +2591,7 @@ var updateRoleAction = {
|
|
|
2715
2591
|
for (const assignment of result) {
|
|
2716
2592
|
let targetEntity = entities.find((e) => e.id === assignment.entityId);
|
|
2717
2593
|
if (!targetEntity) {
|
|
2718
|
-
|
|
2719
|
-
console.log("Trying to write to generated tenant ID");
|
|
2720
|
-
}
|
|
2721
|
-
if (!targetEntity) {
|
|
2722
|
-
console.log("Could not find an ID ot assign to");
|
|
2594
|
+
logger.error("Could not find an ID ot assign to");
|
|
2723
2595
|
}
|
|
2724
2596
|
const currentRole = world.metadata.roles[assignment.entityId];
|
|
2725
2597
|
if (!canModifyRole(requesterRole, currentRole, assignment.newRole)) {
|
|
@@ -2890,7 +2762,12 @@ var sendMessageAction = {
|
|
|
2890
2762
|
});
|
|
2891
2763
|
return;
|
|
2892
2764
|
}
|
|
2893
|
-
const userComponent = await runtime.getComponent(
|
|
2765
|
+
const userComponent = await runtime.getComponent(
|
|
2766
|
+
targetEntity.id,
|
|
2767
|
+
source,
|
|
2768
|
+
worldId,
|
|
2769
|
+
sourceEntityId
|
|
2770
|
+
);
|
|
2894
2771
|
if (!userComponent) {
|
|
2895
2772
|
await callback({
|
|
2896
2773
|
text: `I couldn't find ${source} information for that user. Could you please provide their ${source} details?`,
|
|
@@ -2909,13 +2786,7 @@ var sendMessageAction = {
|
|
|
2909
2786
|
return;
|
|
2910
2787
|
}
|
|
2911
2788
|
try {
|
|
2912
|
-
await sendDirectMessage(
|
|
2913
|
-
runtime,
|
|
2914
|
-
targetEntity.id,
|
|
2915
|
-
source,
|
|
2916
|
-
message.content.text,
|
|
2917
|
-
worldId
|
|
2918
|
-
);
|
|
2789
|
+
await sendDirectMessage(runtime, targetEntity.id, source, message.content.text, worldId);
|
|
2919
2790
|
await callback({
|
|
2920
2791
|
text: `Message sent to ${targetEntity.names[0]} on ${source}.`,
|
|
2921
2792
|
actions: ["SEND_MESSAGE"],
|
|
@@ -2952,13 +2823,7 @@ var sendMessageAction = {
|
|
|
2952
2823
|
return;
|
|
2953
2824
|
}
|
|
2954
2825
|
try {
|
|
2955
|
-
await sendRoomMessage(
|
|
2956
|
-
runtime,
|
|
2957
|
-
targetRoom.id,
|
|
2958
|
-
source,
|
|
2959
|
-
message.content.text,
|
|
2960
|
-
worldId
|
|
2961
|
-
);
|
|
2826
|
+
await sendRoomMessage(runtime, targetRoom.id, source, message.content.text, worldId);
|
|
2962
2827
|
await callback({
|
|
2963
2828
|
text: `Message sent to ${targetRoom.name} on ${source}.`,
|
|
2964
2829
|
actions: ["SEND_MESSAGE"],
|
|
@@ -3158,12 +3023,12 @@ async function updateWorldSettings(runtime, serverId, worldSettings) {
|
|
|
3158
3023
|
}
|
|
3159
3024
|
}
|
|
3160
3025
|
function formatSettingsList(worldSettings) {
|
|
3161
|
-
const
|
|
3026
|
+
const settings = Object.entries(worldSettings).filter(([key]) => !key.startsWith("_")).map(([key, setting]) => {
|
|
3162
3027
|
const status = setting.value !== null ? "Configured" : "Not configured";
|
|
3163
3028
|
const required = setting.required ? "Required" : "Optional";
|
|
3164
3029
|
return `- ${setting.name} (${key}): ${status}, ${required}`;
|
|
3165
3030
|
}).join("\n");
|
|
3166
|
-
return
|
|
3031
|
+
return settings || "No settings available";
|
|
3167
3032
|
}
|
|
3168
3033
|
function categorizeSettings(worldSettings) {
|
|
3169
3034
|
const configured = [];
|
|
@@ -3201,21 +3066,24 @@ async function extractSettingValues(runtime, _message, state, worldSettings) {
|
|
|
3201
3066
|
If a setting is mentioned but no clear value is provided, do not include it.
|
|
3202
3067
|
`;
|
|
3203
3068
|
try {
|
|
3204
|
-
const result = await runtime.useModel(
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
type: "
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3069
|
+
const result = await runtime.useModel(
|
|
3070
|
+
ModelType.OBJECT_LARGE,
|
|
3071
|
+
{
|
|
3072
|
+
prompt: basePrompt,
|
|
3073
|
+
output: "array",
|
|
3074
|
+
schema: {
|
|
3075
|
+
type: "array",
|
|
3076
|
+
items: {
|
|
3077
|
+
type: "object",
|
|
3078
|
+
properties: {
|
|
3079
|
+
key: { type: "string" },
|
|
3080
|
+
value: { type: "string" }
|
|
3081
|
+
},
|
|
3082
|
+
required: ["key", "value"]
|
|
3083
|
+
}
|
|
3216
3084
|
}
|
|
3217
3085
|
}
|
|
3218
|
-
|
|
3086
|
+
);
|
|
3219
3087
|
if (!result || !Array.isArray(result)) {
|
|
3220
3088
|
return [];
|
|
3221
3089
|
}
|
|
@@ -3239,9 +3107,7 @@ async function processSettingUpdates(runtime, serverId, worldSettings, updates)
|
|
|
3239
3107
|
const setting = updatedState[update.key];
|
|
3240
3108
|
if (!setting) continue;
|
|
3241
3109
|
if (setting.dependsOn?.length) {
|
|
3242
|
-
const dependenciesMet = setting.dependsOn.every(
|
|
3243
|
-
(dep) => updatedState[dep]?.value !== null
|
|
3244
|
-
);
|
|
3110
|
+
const dependenciesMet = setting.dependsOn.every((dep) => updatedState[dep]?.value !== null);
|
|
3245
3111
|
if (!dependenciesMet) {
|
|
3246
3112
|
messages.push(`Cannot update ${setting.name} - dependencies not met`);
|
|
3247
3113
|
continue;
|
|
@@ -3402,10 +3268,8 @@ var updateSettingsAction = {
|
|
|
3402
3268
|
description: "Saves a configuration setting during the onboarding process, or update an existing setting. Use this when you are onboarding with a world owner or admin.",
|
|
3403
3269
|
validate: async (runtime, message, _state) => {
|
|
3404
3270
|
try {
|
|
3405
|
-
if (message.content.channelType !== "
|
|
3406
|
-
logger.info(
|
|
3407
|
-
`Skipping settings in non-DM channel (type: ${message.content.channelType})`
|
|
3408
|
-
);
|
|
3271
|
+
if (message.content.channelType !== "dm" /* DM */) {
|
|
3272
|
+
logger.info(`Skipping settings in non-DM channel (type: ${message.content.channelType})`);
|
|
3409
3273
|
return false;
|
|
3410
3274
|
}
|
|
3411
3275
|
logger.info(`Looking for server where user ${message.entityId} is owner`);
|
|
@@ -3429,10 +3293,7 @@ var updateSettingsAction = {
|
|
|
3429
3293
|
handler: async (runtime, message, state, _options, callback) => {
|
|
3430
3294
|
try {
|
|
3431
3295
|
logger.info(`Handler looking for server for user ${message.entityId}`);
|
|
3432
|
-
const serverOwnership = await findWorldForOwner(
|
|
3433
|
-
runtime,
|
|
3434
|
-
message.entityId
|
|
3435
|
-
);
|
|
3296
|
+
const serverOwnership = await findWorldForOwner(runtime, message.entityId);
|
|
3436
3297
|
if (!serverOwnership) {
|
|
3437
3298
|
logger.error(`No server found for user ${message.entityId} in handler`);
|
|
3438
3299
|
await generateErrorResponse(runtime, state, callback);
|
|
@@ -3442,9 +3303,7 @@ var updateSettingsAction = {
|
|
|
3442
3303
|
logger.info(`Using server ID: ${serverId}`);
|
|
3443
3304
|
const worldSettings = await getWorldSettings(runtime, serverId);
|
|
3444
3305
|
if (!worldSettings) {
|
|
3445
|
-
logger.error(
|
|
3446
|
-
`No settings state found for server ${serverId} in handler`
|
|
3447
|
-
);
|
|
3306
|
+
logger.error(`No settings state found for server ${serverId} in handler`);
|
|
3448
3307
|
await generateErrorResponse(runtime, state, callback);
|
|
3449
3308
|
return;
|
|
3450
3309
|
}
|
|
@@ -3455,12 +3314,7 @@ var updateSettingsAction = {
|
|
|
3455
3314
|
return;
|
|
3456
3315
|
}
|
|
3457
3316
|
logger.info(`Extracting settings from message: ${message.content.text}`);
|
|
3458
|
-
const extractedSettings = await extractSettingValues(
|
|
3459
|
-
runtime,
|
|
3460
|
-
message,
|
|
3461
|
-
state,
|
|
3462
|
-
worldSettings
|
|
3463
|
-
);
|
|
3317
|
+
const extractedSettings = await extractSettingValues(runtime, message, state, worldSettings);
|
|
3464
3318
|
logger.info(`Extracted ${extractedSettings.length} settings`);
|
|
3465
3319
|
const updateResults = await processSettingUpdates(
|
|
3466
3320
|
runtime,
|
|
@@ -3469,9 +3323,7 @@ var updateSettingsAction = {
|
|
|
3469
3323
|
extractedSettings
|
|
3470
3324
|
);
|
|
3471
3325
|
if (updateResults.updatedAny) {
|
|
3472
|
-
logger.info(
|
|
3473
|
-
`Successfully updated settings: ${updateResults.messages.join(", ")}`
|
|
3474
|
-
);
|
|
3326
|
+
logger.info(`Successfully updated settings: ${updateResults.messages.join(", ")}`);
|
|
3475
3327
|
const updatedWorldSettings = await getWorldSettings(runtime, serverId);
|
|
3476
3328
|
if (!updatedWorldSettings) {
|
|
3477
3329
|
logger.error("Failed to retrieve updated settings state");
|
|
@@ -3684,12 +3536,7 @@ Otherwise, respond with NO.
|
|
|
3684
3536
|
${booleanFooter}`;
|
|
3685
3537
|
var unfollowRoomAction = {
|
|
3686
3538
|
name: "UNFOLLOW_ROOM",
|
|
3687
|
-
similes: [
|
|
3688
|
-
"UNFOLLOW_CHAT",
|
|
3689
|
-
"UNFOLLOW_CONVERSATION",
|
|
3690
|
-
"UNFOLLOW_ROOM",
|
|
3691
|
-
"UNFOLLOW_THREAD"
|
|
3692
|
-
],
|
|
3539
|
+
similes: ["UNFOLLOW_CHAT", "UNFOLLOW_CONVERSATION", "UNFOLLOW_ROOM", "UNFOLLOW_THREAD"],
|
|
3693
3540
|
description: "Stop following this channel. You can still respond if explicitly mentioned, but you won't automatically chime in anymore. Unfollow if you're annoying people or have been asked to.",
|
|
3694
3541
|
validate: async (runtime, message) => {
|
|
3695
3542
|
const roomId = message.roomId;
|
|
@@ -3712,29 +3559,35 @@ var unfollowRoomAction = {
|
|
|
3712
3559
|
if (await _shouldUnfollow(state)) {
|
|
3713
3560
|
await runtime.setParticipantUserState(message.roomId, runtime.agentId, null);
|
|
3714
3561
|
const room = state.data.room ?? await runtime.getRoom(message.roomId);
|
|
3715
|
-
await runtime.createMemory(
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3562
|
+
await runtime.createMemory(
|
|
3563
|
+
{
|
|
3564
|
+
entityId: message.entityId,
|
|
3565
|
+
agentId: message.agentId,
|
|
3566
|
+
roomId: message.roomId,
|
|
3567
|
+
content: {
|
|
3568
|
+
thought: `I unfollowed the room ${room.name}`,
|
|
3569
|
+
actions: ["UNFOLLOW_ROOM_START"]
|
|
3570
|
+
}
|
|
3571
|
+
},
|
|
3572
|
+
"messages"
|
|
3573
|
+
);
|
|
3724
3574
|
} else {
|
|
3725
|
-
await runtime.createMemory(
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3575
|
+
await runtime.createMemory(
|
|
3576
|
+
{
|
|
3577
|
+
entityId: message.entityId,
|
|
3578
|
+
agentId: message.agentId,
|
|
3579
|
+
roomId: message.roomId,
|
|
3580
|
+
content: {
|
|
3581
|
+
source: message.content.source,
|
|
3582
|
+
thought: "I tried to unfollow a room but I'm not in a room",
|
|
3583
|
+
actions: ["UNFOLLOW_ROOM_FAILED"]
|
|
3584
|
+
},
|
|
3585
|
+
metadata: {
|
|
3586
|
+
type: "UNFOLLOW_ROOM"
|
|
3587
|
+
}
|
|
3733
3588
|
},
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
}
|
|
3737
|
-
}, "messages");
|
|
3589
|
+
"messages"
|
|
3590
|
+
);
|
|
3738
3591
|
}
|
|
3739
3592
|
},
|
|
3740
3593
|
examples: [
|
|
@@ -3999,12 +3852,7 @@ Otherwise, respond with NO.
|
|
|
3999
3852
|
${booleanFooter}`;
|
|
4000
3853
|
var unmuteRoomAction = {
|
|
4001
3854
|
name: "UNMUTE_ROOM",
|
|
4002
|
-
similes: [
|
|
4003
|
-
"UNMUTE_CHAT",
|
|
4004
|
-
"UNMUTE_CONVERSATION",
|
|
4005
|
-
"UNMUTE_ROOM",
|
|
4006
|
-
"UNMUTE_THREAD"
|
|
4007
|
-
],
|
|
3855
|
+
similes: ["UNMUTE_CHAT", "UNMUTE_CONVERSATION", "UNMUTE_ROOM", "UNMUTE_THREAD"],
|
|
4008
3856
|
description: "Unmutes a room, allowing the agent to consider responding to messages again.",
|
|
4009
3857
|
validate: async (runtime, message) => {
|
|
4010
3858
|
const roomId = message.roomId;
|
|
@@ -4025,35 +3873,41 @@ var unmuteRoomAction = {
|
|
|
4025
3873
|
});
|
|
4026
3874
|
const cleanedResponse = response.trim().toLowerCase();
|
|
4027
3875
|
if (cleanedResponse === "true" || cleanedResponse === "yes" || cleanedResponse === "y" || cleanedResponse.includes("true") || cleanedResponse.includes("yes")) {
|
|
4028
|
-
await runtime.createMemory(
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
3876
|
+
await runtime.createMemory(
|
|
3877
|
+
{
|
|
3878
|
+
entityId: message.entityId,
|
|
3879
|
+
agentId: message.agentId,
|
|
3880
|
+
roomId: message.roomId,
|
|
3881
|
+
content: {
|
|
3882
|
+
source: message.content.source,
|
|
3883
|
+
thought: "I will now unmute this room and start considering it for responses again",
|
|
3884
|
+
actions: ["UNMUTE_ROOM_STARTED"]
|
|
3885
|
+
},
|
|
3886
|
+
metadata: {
|
|
3887
|
+
type: "UNMUTE_ROOM"
|
|
3888
|
+
}
|
|
3889
|
+
},
|
|
3890
|
+
"messages"
|
|
3891
|
+
);
|
|
4041
3892
|
return true;
|
|
4042
3893
|
}
|
|
4043
3894
|
if (cleanedResponse === "false" || cleanedResponse === "no" || cleanedResponse === "n" || cleanedResponse.includes("false") || cleanedResponse.includes("no")) {
|
|
4044
|
-
await runtime.createMemory(
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
3895
|
+
await runtime.createMemory(
|
|
3896
|
+
{
|
|
3897
|
+
entityId: message.entityId,
|
|
3898
|
+
agentId: message.agentId,
|
|
3899
|
+
roomId: message.roomId,
|
|
3900
|
+
content: {
|
|
3901
|
+
source: message.content.source,
|
|
3902
|
+
thought: "I tried to unmute a room but I decided not to",
|
|
3903
|
+
actions: ["UNMUTE_ROOM_FAILED"]
|
|
3904
|
+
},
|
|
3905
|
+
metadata: {
|
|
3906
|
+
type: "UNMUTE_ROOM"
|
|
3907
|
+
}
|
|
4052
3908
|
},
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
}
|
|
4056
|
-
}, "messages");
|
|
3909
|
+
"messages"
|
|
3910
|
+
);
|
|
4057
3911
|
return false;
|
|
4058
3912
|
}
|
|
4059
3913
|
logger_default.warn(`Unclear boolean response: ${response}, defaulting to false`);
|
|
@@ -4063,15 +3917,18 @@ var unmuteRoomAction = {
|
|
|
4063
3917
|
await runtime.setParticipantUserState(message.roomId, runtime.agentId, null);
|
|
4064
3918
|
}
|
|
4065
3919
|
const room = await runtime.getRoom(message.roomId);
|
|
4066
|
-
await runtime.createMemory(
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
3920
|
+
await runtime.createMemory(
|
|
3921
|
+
{
|
|
3922
|
+
entityId: message.entityId,
|
|
3923
|
+
agentId: message.agentId,
|
|
3924
|
+
roomId: message.roomId,
|
|
3925
|
+
content: {
|
|
3926
|
+
thought: `I unmuted the room ${room.name}`,
|
|
3927
|
+
actions: ["UNMUTE_ROOM_START"]
|
|
3928
|
+
}
|
|
3929
|
+
},
|
|
3930
|
+
"messages"
|
|
3931
|
+
);
|
|
4075
3932
|
},
|
|
4076
3933
|
examples: [
|
|
4077
3934
|
[
|
|
@@ -4277,7 +4134,12 @@ var updateEntityAction = {
|
|
|
4277
4134
|
}
|
|
4278
4135
|
const componentType = parsedResult.source.toLowerCase();
|
|
4279
4136
|
const componentData = parsedResult.data;
|
|
4280
|
-
existingComponent = await runtime.getComponent(
|
|
4137
|
+
existingComponent = await runtime.getComponent(
|
|
4138
|
+
entity.id,
|
|
4139
|
+
componentType,
|
|
4140
|
+
worldId,
|
|
4141
|
+
sourceEntityId
|
|
4142
|
+
);
|
|
4281
4143
|
if (existingComponent) {
|
|
4282
4144
|
await runtime.updateComponent({
|
|
4283
4145
|
id: existingComponent.id,
|
|
@@ -4370,26 +4232,26 @@ var updateEntityAction = {
|
|
|
4370
4232
|
};
|
|
4371
4233
|
|
|
4372
4234
|
// src/evaluators/reflection.ts
|
|
4373
|
-
import { z
|
|
4374
|
-
var relationshipSchema =
|
|
4375
|
-
sourceEntityId:
|
|
4376
|
-
targetEntityId:
|
|
4377
|
-
tags:
|
|
4378
|
-
metadata:
|
|
4379
|
-
interactions:
|
|
4235
|
+
import { z } from "zod";
|
|
4236
|
+
var relationshipSchema = z.object({
|
|
4237
|
+
sourceEntityId: z.string(),
|
|
4238
|
+
targetEntityId: z.string(),
|
|
4239
|
+
tags: z.array(z.string()),
|
|
4240
|
+
metadata: z.object({
|
|
4241
|
+
interactions: z.number()
|
|
4380
4242
|
}).optional()
|
|
4381
4243
|
});
|
|
4382
|
-
var reflectionSchema =
|
|
4244
|
+
var reflectionSchema = z.object({
|
|
4383
4245
|
// reflection: z.string(),
|
|
4384
|
-
facts:
|
|
4385
|
-
|
|
4386
|
-
claim:
|
|
4387
|
-
type:
|
|
4388
|
-
in_bio:
|
|
4389
|
-
already_known:
|
|
4246
|
+
facts: z.array(
|
|
4247
|
+
z.object({
|
|
4248
|
+
claim: z.string(),
|
|
4249
|
+
type: z.string(),
|
|
4250
|
+
in_bio: z.boolean(),
|
|
4251
|
+
already_known: z.boolean()
|
|
4390
4252
|
})
|
|
4391
4253
|
),
|
|
4392
|
-
relationships:
|
|
4254
|
+
relationships: z.array(relationshipSchema)
|
|
4393
4255
|
});
|
|
4394
4256
|
var reflectionTemplate = `# Task: Generate Agent Reflection, Extract Facts and Relationships
|
|
4395
4257
|
|
|
@@ -4444,9 +4306,7 @@ Generate a response in the following format:
|
|
|
4444
4306
|
}
|
|
4445
4307
|
\`\`\``;
|
|
4446
4308
|
function resolveEntity(entityId, entities) {
|
|
4447
|
-
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
4448
|
-
entityId
|
|
4449
|
-
)) {
|
|
4309
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(entityId)) {
|
|
4450
4310
|
return entityId;
|
|
4451
4311
|
}
|
|
4452
4312
|
let entity;
|
|
@@ -4491,93 +4351,98 @@ async function handler(runtime, message, state) {
|
|
|
4491
4351
|
},
|
|
4492
4352
|
template: runtime.character.templates?.reflectionTemplate || reflectionTemplate
|
|
4493
4353
|
});
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
if (!reflection) {
|
|
4499
|
-
logger_default.warn("Getting reflection failed", prompt);
|
|
4500
|
-
return;
|
|
4501
|
-
}
|
|
4502
|
-
const newFacts = reflection?.facts.filter(
|
|
4503
|
-
(fact) => !fact.already_known && !fact.in_bio && fact.claim && fact.claim.trim() !== ""
|
|
4504
|
-
) || [];
|
|
4505
|
-
await Promise.all(
|
|
4506
|
-
newFacts.map(async (fact) => {
|
|
4507
|
-
const factMemory = await runtime.addEmbeddingToMemory({
|
|
4508
|
-
entityId: agentId,
|
|
4509
|
-
agentId,
|
|
4510
|
-
content: { text: fact.claim },
|
|
4511
|
-
roomId,
|
|
4512
|
-
createdAt: Date.now()
|
|
4513
|
-
});
|
|
4514
|
-
return runtime.createMemory(factMemory, "facts", true);
|
|
4515
|
-
})
|
|
4516
|
-
);
|
|
4517
|
-
for (const relationship of reflection.relationships) {
|
|
4518
|
-
let sourceId;
|
|
4519
|
-
let targetId;
|
|
4520
|
-
try {
|
|
4521
|
-
sourceId = resolveEntity(relationship.sourceEntityId, entities);
|
|
4522
|
-
targetId = resolveEntity(relationship.targetEntityId, entities);
|
|
4523
|
-
} catch (error) {
|
|
4524
|
-
console.warn("Failed to resolve relationship entities:", error);
|
|
4525
|
-
console.warn("relationship:\n", relationship);
|
|
4526
|
-
continue;
|
|
4527
|
-
}
|
|
4528
|
-
const existingRelationship = existingRelationships.find((r) => {
|
|
4529
|
-
return r.sourceEntityId === sourceId && r.targetEntityId === targetId;
|
|
4354
|
+
try {
|
|
4355
|
+
const reflection = await runtime.useModel(ModelType.OBJECT_SMALL, {
|
|
4356
|
+
prompt
|
|
4357
|
+
// Remove schema validation to avoid zod issues
|
|
4530
4358
|
});
|
|
4531
|
-
if (
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4359
|
+
if (!reflection) {
|
|
4360
|
+
logger_default.warn("Getting reflection failed - empty response", prompt);
|
|
4361
|
+
return;
|
|
4362
|
+
}
|
|
4363
|
+
if (!reflection.facts || !Array.isArray(reflection.facts)) {
|
|
4364
|
+
logger_default.warn("Getting reflection failed - invalid facts structure", reflection);
|
|
4365
|
+
return;
|
|
4366
|
+
}
|
|
4367
|
+
if (!reflection.relationships || !Array.isArray(reflection.relationships)) {
|
|
4368
|
+
logger_default.warn("Getting reflection failed - invalid relationships structure", reflection);
|
|
4369
|
+
return;
|
|
4370
|
+
}
|
|
4371
|
+
const newFacts = reflection.facts.filter(
|
|
4372
|
+
(fact) => fact && typeof fact === "object" && !fact.already_known && !fact.in_bio && fact.claim && typeof fact.claim === "string" && fact.claim.trim() !== ""
|
|
4373
|
+
) || [];
|
|
4374
|
+
await Promise.all(
|
|
4375
|
+
newFacts.map(async (fact) => {
|
|
4376
|
+
const factMemory = await runtime.addEmbeddingToMemory({
|
|
4377
|
+
entityId: agentId,
|
|
4378
|
+
agentId,
|
|
4379
|
+
content: { text: fact.claim },
|
|
4380
|
+
roomId,
|
|
4381
|
+
createdAt: Date.now()
|
|
4382
|
+
});
|
|
4383
|
+
return runtime.createMemory(factMemory, "facts", true);
|
|
4384
|
+
})
|
|
4385
|
+
);
|
|
4386
|
+
for (const relationship of reflection.relationships) {
|
|
4387
|
+
let sourceId;
|
|
4388
|
+
let targetId;
|
|
4389
|
+
try {
|
|
4390
|
+
sourceId = resolveEntity(relationship.sourceEntityId, entities);
|
|
4391
|
+
targetId = resolveEntity(relationship.targetEntityId, entities);
|
|
4392
|
+
} catch (error) {
|
|
4393
|
+
console.warn("Failed to resolve relationship entities:", error);
|
|
4394
|
+
console.warn("relationship:\n", relationship);
|
|
4395
|
+
continue;
|
|
4396
|
+
}
|
|
4397
|
+
const existingRelationship = existingRelationships.find((r) => {
|
|
4398
|
+
return r.sourceEntityId === sourceId && r.targetEntityId === targetId;
|
|
4553
4399
|
});
|
|
4400
|
+
if (existingRelationship) {
|
|
4401
|
+
const updatedMetadata = {
|
|
4402
|
+
...existingRelationship.metadata,
|
|
4403
|
+
interactions: (existingRelationship.metadata?.interactions || 0) + 1
|
|
4404
|
+
};
|
|
4405
|
+
const updatedTags = Array.from(
|
|
4406
|
+
/* @__PURE__ */ new Set([...existingRelationship.tags || [], ...relationship.tags])
|
|
4407
|
+
);
|
|
4408
|
+
await runtime.updateRelationship({
|
|
4409
|
+
...existingRelationship,
|
|
4410
|
+
tags: updatedTags,
|
|
4411
|
+
metadata: updatedMetadata
|
|
4412
|
+
});
|
|
4413
|
+
} else {
|
|
4414
|
+
await runtime.createRelationship({
|
|
4415
|
+
sourceEntityId: sourceId,
|
|
4416
|
+
targetEntityId: targetId,
|
|
4417
|
+
tags: relationship.tags,
|
|
4418
|
+
metadata: {
|
|
4419
|
+
interactions: 1,
|
|
4420
|
+
...relationship.metadata
|
|
4421
|
+
}
|
|
4422
|
+
});
|
|
4423
|
+
}
|
|
4554
4424
|
}
|
|
4425
|
+
await runtime.setCache(`${message.roomId}-reflection-last-processed`, message.id);
|
|
4426
|
+
return reflection;
|
|
4427
|
+
} catch (error) {
|
|
4428
|
+
logger_default.error("Error in reflection handler:", error);
|
|
4429
|
+
return;
|
|
4555
4430
|
}
|
|
4556
|
-
await runtime.setCache(
|
|
4557
|
-
`${message.roomId}-reflection-last-processed`,
|
|
4558
|
-
message.id
|
|
4559
|
-
);
|
|
4560
|
-
return reflection;
|
|
4561
4431
|
}
|
|
4562
4432
|
var reflectionEvaluator = {
|
|
4563
4433
|
name: "REFLECTION",
|
|
4564
|
-
similes: [
|
|
4565
|
-
"REFLECT",
|
|
4566
|
-
"SELF_REFLECT",
|
|
4567
|
-
"EVALUATE_INTERACTION",
|
|
4568
|
-
"ASSESS_SITUATION"
|
|
4569
|
-
],
|
|
4434
|
+
similes: ["REFLECT", "SELF_REFLECT", "EVALUATE_INTERACTION", "ASSESS_SITUATION"],
|
|
4570
4435
|
validate: async (runtime, message) => {
|
|
4571
|
-
const lastMessageId = await runtime.getCache(
|
|
4436
|
+
const lastMessageId = await runtime.getCache(
|
|
4437
|
+
`${message.roomId}-reflection-last-processed`
|
|
4438
|
+
);
|
|
4572
4439
|
const messages = await runtime.getMemories({
|
|
4573
4440
|
tableName: "messages",
|
|
4574
4441
|
roomId: message.roomId,
|
|
4575
4442
|
count: runtime.getConversationLength()
|
|
4576
4443
|
});
|
|
4577
4444
|
if (lastMessageId) {
|
|
4578
|
-
const lastMessageIndex = messages.findIndex(
|
|
4579
|
-
(msg) => msg.id === lastMessageId
|
|
4580
|
-
);
|
|
4445
|
+
const lastMessageIndex = messages.findIndex((msg) => msg.id === lastMessageId);
|
|
4581
4446
|
if (lastMessageIndex !== -1) {
|
|
4582
4447
|
messages.splice(0, lastMessageIndex + 1);
|
|
4583
4448
|
}
|
|
@@ -4771,9 +4636,7 @@ var actionsProvider = {
|
|
|
4771
4636
|
});
|
|
4772
4637
|
const resolvedActions = await Promise.all(actionPromises);
|
|
4773
4638
|
const actionsData = resolvedActions.filter(Boolean);
|
|
4774
|
-
const actionNames = `Possible response actions: ${formatActionNames(
|
|
4775
|
-
actionsData
|
|
4776
|
-
)}`;
|
|
4639
|
+
const actionNames = `Possible response actions: ${formatActionNames(actionsData)}`;
|
|
4777
4640
|
const actions = actionsData.length > 0 ? addHeader("# Available Actions", formatActions(actionsData)) : "";
|
|
4778
4641
|
const actionExamples = actionsData.length > 0 ? addHeader("# Action Examples", composeActionExamples(actionsData, 10)) : "";
|
|
4779
4642
|
const data = {
|
|
@@ -4850,9 +4713,9 @@ var anxietyProvider = {
|
|
|
4850
4713
|
"Keep voice channel interactions brief and purposeful."
|
|
4851
4714
|
];
|
|
4852
4715
|
let anxietyExamples = [];
|
|
4853
|
-
if (channelType === "
|
|
4716
|
+
if (channelType === "group" /* GROUP */) {
|
|
4854
4717
|
anxietyExamples = groupAnxietyExamples;
|
|
4855
|
-
} else if (channelType === "
|
|
4718
|
+
} else if (channelType === "dm" /* DM */) {
|
|
4856
4719
|
anxietyExamples = dmAnxietyExamples;
|
|
4857
4720
|
} else if (channelType === "VOICE_GROUP" /* VOICE_GROUP */ || channelType === "VOICE_DM" /* VOICE_DM */) {
|
|
4858
4721
|
anxietyExamples = voiceAnxietyExamples;
|
|
@@ -5003,10 +4866,7 @@ var characterProvider = {
|
|
|
5003
4866
|
const messageString = `${post}`;
|
|
5004
4867
|
return messageString;
|
|
5005
4868
|
}).slice(0, 50).join("\n");
|
|
5006
|
-
const characterPostExamples = formattedCharacterPostExamples && formattedCharacterPostExamples.replaceAll("\n", "").length > 0 ? addHeader(
|
|
5007
|
-
`# Example Posts for ${character.name}`,
|
|
5008
|
-
formattedCharacterPostExamples
|
|
5009
|
-
) : "";
|
|
4869
|
+
const characterPostExamples = formattedCharacterPostExamples && formattedCharacterPostExamples.replaceAll("\n", "").length > 0 ? addHeader(`# Example Posts for ${character.name}`, formattedCharacterPostExamples) : "";
|
|
5010
4870
|
const formattedCharacterMessageExamples = !character.messageExamples ? "" : character.messageExamples.sort(() => 0.5 - Math.random()).slice(0, 5).map((example) => {
|
|
5011
4871
|
const exampleNames = Array.from(
|
|
5012
4872
|
{ length: 5 },
|
|
@@ -5069,16 +4929,7 @@ var characterProvider = {
|
|
|
5069
4929
|
examples,
|
|
5070
4930
|
system
|
|
5071
4931
|
};
|
|
5072
|
-
const text = [
|
|
5073
|
-
bio,
|
|
5074
|
-
adjective,
|
|
5075
|
-
topic,
|
|
5076
|
-
topics,
|
|
5077
|
-
adjective,
|
|
5078
|
-
directions,
|
|
5079
|
-
examples,
|
|
5080
|
-
system
|
|
5081
|
-
].filter(Boolean).join("\n\n");
|
|
4932
|
+
const text = [bio, adjective, topic, topics, adjective, directions, examples, system].filter(Boolean).join("\n\n");
|
|
5082
4933
|
return {
|
|
5083
4934
|
values,
|
|
5084
4935
|
data,
|
|
@@ -5107,9 +4958,7 @@ var choiceProvider = {
|
|
|
5107
4958
|
text: "No pending choices for the moment."
|
|
5108
4959
|
};
|
|
5109
4960
|
}
|
|
5110
|
-
const tasksWithOptions = pendingTasks.filter(
|
|
5111
|
-
(task) => task.metadata?.options
|
|
5112
|
-
);
|
|
4961
|
+
const tasksWithOptions = pendingTasks.filter((task) => task.metadata?.options);
|
|
5113
4962
|
if (tasksWithOptions.length === 0) {
|
|
5114
4963
|
return {
|
|
5115
4964
|
data: {
|
|
@@ -5180,9 +5029,7 @@ var entitiesProvider = {
|
|
|
5180
5029
|
const { roomId, entityId } = message;
|
|
5181
5030
|
const entitiesData = await getEntityDetails({ runtime, roomId });
|
|
5182
5031
|
const formattedEntities = formatEntities({ entities: entitiesData ?? [] });
|
|
5183
|
-
const senderName = entitiesData?.find(
|
|
5184
|
-
(entity) => entity.id === entityId
|
|
5185
|
-
)?.names[0];
|
|
5032
|
+
const senderName = entitiesData?.find((entity) => entity.id === entityId)?.names[0];
|
|
5186
5033
|
const entities = formattedEntities && formattedEntities.length > 0 ? addHeader("# People in the Room", formattedEntities) : "";
|
|
5187
5034
|
const data = {
|
|
5188
5035
|
entitiesData,
|
|
@@ -5238,32 +5085,25 @@ ${formattedOutcome}`;
|
|
|
5238
5085
|
}).join("\n\n");
|
|
5239
5086
|
}
|
|
5240
5087
|
function formatEvaluators(evaluators) {
|
|
5241
|
-
return evaluators.map(
|
|
5242
|
-
(evaluator) => `'${evaluator.name}: ${evaluator.description}'`
|
|
5243
|
-
).join(",\n");
|
|
5088
|
+
return evaluators.map((evaluator) => `'${evaluator.name}: ${evaluator.description}'`).join(",\n");
|
|
5244
5089
|
}
|
|
5245
5090
|
var evaluatorsProvider = {
|
|
5246
5091
|
name: "EVALUATORS",
|
|
5247
5092
|
description: "Evaluators that can be used to evaluate the conversation after responding",
|
|
5248
5093
|
private: true,
|
|
5249
5094
|
get: async (runtime, message, state) => {
|
|
5250
|
-
const evaluatorPromises = runtime.evaluators.map(
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
return evaluator;
|
|
5255
|
-
}
|
|
5256
|
-
return null;
|
|
5095
|
+
const evaluatorPromises = runtime.evaluators.map(async (evaluator) => {
|
|
5096
|
+
const result = await evaluator.validate(runtime, message, state);
|
|
5097
|
+
if (result) {
|
|
5098
|
+
return evaluator;
|
|
5257
5099
|
}
|
|
5258
|
-
|
|
5100
|
+
return null;
|
|
5101
|
+
});
|
|
5259
5102
|
const resolvedEvaluators = await Promise.all(evaluatorPromises);
|
|
5260
5103
|
const evaluatorsData = resolvedEvaluators.filter(Boolean);
|
|
5261
5104
|
const evaluators = evaluatorsData.length > 0 ? addHeader("# Available Evaluators", formatEvaluators(evaluatorsData)) : "";
|
|
5262
5105
|
const evaluatorNames = evaluatorsData.length > 0 ? formatEvaluatorNames(evaluatorsData) : "";
|
|
5263
|
-
const evaluatorExamples = evaluatorsData.length > 0 ? addHeader(
|
|
5264
|
-
"# Evaluator Examples",
|
|
5265
|
-
formatEvaluatorExamples(evaluatorsData)
|
|
5266
|
-
) : "";
|
|
5106
|
+
const evaluatorExamples = evaluatorsData.length > 0 ? addHeader("# Evaluator Examples", formatEvaluatorExamples(evaluatorsData)) : "";
|
|
5267
5107
|
const values = {
|
|
5268
5108
|
evaluatorsData,
|
|
5269
5109
|
evaluators,
|
|
@@ -5368,19 +5208,14 @@ var providersProvider = {
|
|
|
5368
5208
|
name: "PROVIDERS",
|
|
5369
5209
|
description: "List of all data providers the agent can use to get additional information",
|
|
5370
5210
|
get: async (runtime, _message) => {
|
|
5371
|
-
const dynamicProviders = runtime.providers.filter(
|
|
5372
|
-
(provider) => provider.dynamic === true
|
|
5373
|
-
);
|
|
5211
|
+
const dynamicProviders = runtime.providers.filter((provider) => provider.dynamic === true);
|
|
5374
5212
|
const providerDescriptions = dynamicProviders.map((provider) => {
|
|
5375
5213
|
return `- **${provider.name}**: ${provider.description || "No description available"}`;
|
|
5376
5214
|
});
|
|
5377
5215
|
const headerText = "# Providers\n\nThese providers are available for the agent to select and use:";
|
|
5378
5216
|
if (providerDescriptions.length === 0) {
|
|
5379
5217
|
return {
|
|
5380
|
-
text: addHeader(
|
|
5381
|
-
headerText,
|
|
5382
|
-
"No dynamic providers are currently available."
|
|
5383
|
-
)
|
|
5218
|
+
text: addHeader(headerText, "No dynamic providers are currently available.")
|
|
5384
5219
|
};
|
|
5385
5220
|
}
|
|
5386
5221
|
const providersText = providerDescriptions.join("\n");
|
|
@@ -5424,12 +5259,7 @@ var recentMessagesProvider = {
|
|
|
5424
5259
|
count: conversationLength,
|
|
5425
5260
|
unique: false
|
|
5426
5261
|
}),
|
|
5427
|
-
message.entityId !== runtime.agentId ? getRecentInteractions2(
|
|
5428
|
-
runtime,
|
|
5429
|
-
message.entityId,
|
|
5430
|
-
runtime.agentId,
|
|
5431
|
-
roomId
|
|
5432
|
-
) : Promise.resolve([])
|
|
5262
|
+
message.entityId !== runtime.agentId ? getRecentInteractions2(runtime, message.entityId, runtime.agentId, roomId) : Promise.resolve([])
|
|
5433
5263
|
]);
|
|
5434
5264
|
const isPostFormat = room?.type === "FEED" /* FEED */ || room?.type === "THREAD" /* THREAD */;
|
|
5435
5265
|
const [formattedRecentMessages, formattedRecentPosts] = await Promise.all([
|
|
@@ -5460,14 +5290,10 @@ var recentMessagesProvider = {
|
|
|
5460
5290
|
entitiesDataIdSet.add(entity.id);
|
|
5461
5291
|
}
|
|
5462
5292
|
});
|
|
5463
|
-
const remainingEntityIds = uniqueEntityIds.filter(
|
|
5464
|
-
(id) => !entitiesDataIdSet.has(id)
|
|
5465
|
-
);
|
|
5293
|
+
const remainingEntityIds = uniqueEntityIds.filter((id) => !entitiesDataIdSet.has(id));
|
|
5466
5294
|
if (remainingEntityIds.length > 0) {
|
|
5467
5295
|
const entities = await Promise.all(
|
|
5468
|
-
remainingEntityIds.map(
|
|
5469
|
-
(entityId) => runtime.getEntityById(entityId)
|
|
5470
|
-
)
|
|
5296
|
+
remainingEntityIds.map((entityId) => runtime.getEntityById(entityId))
|
|
5471
5297
|
);
|
|
5472
5298
|
entities.forEach((entity, index) => {
|
|
5473
5299
|
if (entity) {
|
|
@@ -5530,18 +5356,14 @@ var recentMessagesProvider = {
|
|
|
5530
5356
|
|
|
5531
5357
|
// src/providers/relationships.ts
|
|
5532
5358
|
async function formatRelationships(runtime, relationships) {
|
|
5533
|
-
const sortedRelationships = relationships.filter((rel) => rel.metadata?.interactions).sort(
|
|
5534
|
-
(a, b) => (b.metadata?.interactions || 0) - (a.metadata?.interactions || 0)
|
|
5535
|
-
).slice(0, 30);
|
|
5359
|
+
const sortedRelationships = relationships.filter((rel) => rel.metadata?.interactions).sort((a, b) => (b.metadata?.interactions || 0) - (a.metadata?.interactions || 0)).slice(0, 30);
|
|
5536
5360
|
if (sortedRelationships.length === 0) {
|
|
5537
5361
|
return "";
|
|
5538
5362
|
}
|
|
5539
5363
|
const uniqueEntityIds = Array.from(
|
|
5540
5364
|
new Set(sortedRelationships.map((rel) => rel.targetEntityId))
|
|
5541
5365
|
);
|
|
5542
|
-
const entities = await Promise.all(
|
|
5543
|
-
uniqueEntityIds.map((id) => runtime.getEntityById(id))
|
|
5544
|
-
);
|
|
5366
|
+
const entities = await Promise.all(uniqueEntityIds.map((id) => runtime.getEntityById(id)));
|
|
5545
5367
|
const entityMap = /* @__PURE__ */ new Map();
|
|
5546
5368
|
entities.forEach((entity, index) => {
|
|
5547
5369
|
if (entity) {
|
|
@@ -5588,10 +5410,7 @@ var relationshipsProvider = {
|
|
|
5588
5410
|
text: "No relationships found."
|
|
5589
5411
|
};
|
|
5590
5412
|
}
|
|
5591
|
-
const formattedRelationships = await formatRelationships(
|
|
5592
|
-
runtime,
|
|
5593
|
-
relationships
|
|
5594
|
-
);
|
|
5413
|
+
const formattedRelationships = await formatRelationships(runtime, relationships);
|
|
5595
5414
|
if (!formattedRelationships) {
|
|
5596
5415
|
return {
|
|
5597
5416
|
data: {
|
|
@@ -5625,7 +5444,7 @@ var roleProvider = {
|
|
|
5625
5444
|
if (!room) {
|
|
5626
5445
|
throw new Error("No room found");
|
|
5627
5446
|
}
|
|
5628
|
-
if (room.type !== "
|
|
5447
|
+
if (room.type !== "group" /* GROUP */) {
|
|
5629
5448
|
return {
|
|
5630
5449
|
data: {
|
|
5631
5450
|
roles: []
|
|
@@ -5767,9 +5586,7 @@ function getSalt(runtime) {
|
|
|
5767
5586
|
logger.warn("AgentId is missing when generating encryption salt");
|
|
5768
5587
|
}
|
|
5769
5588
|
const salt = secretSalt + (agentId || "");
|
|
5770
|
-
logger.debug(
|
|
5771
|
-
`Generated salt with length: ${salt.length} (truncated for security)`
|
|
5772
|
-
);
|
|
5589
|
+
logger.debug(`Generated salt with length: ${salt.length} (truncated for security)`);
|
|
5773
5590
|
return salt;
|
|
5774
5591
|
}
|
|
5775
5592
|
function saltSettingValue(setting, salt) {
|
|
@@ -5781,9 +5598,7 @@ function saltSettingValue(setting, salt) {
|
|
|
5781
5598
|
try {
|
|
5782
5599
|
const possibleIv = Buffer.from(parts[0], "hex");
|
|
5783
5600
|
if (possibleIv.length === 16) {
|
|
5784
|
-
logger.debug(
|
|
5785
|
-
"Value appears to be already encrypted, skipping re-encryption"
|
|
5786
|
-
);
|
|
5601
|
+
logger.debug("Value appears to be already encrypted, skipping re-encryption");
|
|
5787
5602
|
return settingCopy;
|
|
5788
5603
|
}
|
|
5789
5604
|
} catch (e) {
|
|
@@ -5808,9 +5623,7 @@ function unsaltSettingValue(setting, salt) {
|
|
|
5808
5623
|
try {
|
|
5809
5624
|
const parts = setting.value.split(":");
|
|
5810
5625
|
if (parts.length !== 2) {
|
|
5811
|
-
logger.warn(
|
|
5812
|
-
`Invalid encrypted value format for setting - expected 'iv:encrypted'`
|
|
5813
|
-
);
|
|
5626
|
+
logger.warn(`Invalid encrypted value format for setting - expected 'iv:encrypted'`);
|
|
5814
5627
|
return settingCopy;
|
|
5815
5628
|
}
|
|
5816
5629
|
const iv = Buffer.from(parts[0], "hex");
|
|
@@ -5880,19 +5693,17 @@ async function getWorldSettings2(runtime, serverId) {
|
|
|
5880
5693
|
return null;
|
|
5881
5694
|
}
|
|
5882
5695
|
}
|
|
5883
|
-
async function initializeOnboarding(runtime, world,
|
|
5696
|
+
async function initializeOnboarding(runtime, world, config) {
|
|
5884
5697
|
try {
|
|
5885
5698
|
if (world.metadata?.settings) {
|
|
5886
|
-
logger.info(
|
|
5887
|
-
`Onboarding state already exists for server ${world.serverId}`
|
|
5888
|
-
);
|
|
5699
|
+
logger.info(`Onboarding state already exists for server ${world.serverId}`);
|
|
5889
5700
|
const saltedSettings = world.metadata.settings;
|
|
5890
5701
|
const salt = getSalt(runtime);
|
|
5891
5702
|
return unsaltWorldSettings(saltedSettings, salt);
|
|
5892
5703
|
}
|
|
5893
5704
|
const worldSettings = {};
|
|
5894
|
-
if (
|
|
5895
|
-
for (const [key, configSetting] of Object.entries(
|
|
5705
|
+
if (config.settings) {
|
|
5706
|
+
for (const [key, configSetting] of Object.entries(config.settings)) {
|
|
5896
5707
|
worldSettings[key] = createSettingFromConfig(configSetting);
|
|
5897
5708
|
}
|
|
5898
5709
|
}
|
|
@@ -5945,9 +5756,7 @@ ${runtime.character.name} still needs to configure ${requiredUnconfigured} requi
|
|
|
5945
5756
|
${formattedSettings.filter((s) => s.required && !s.configured).map((s) => `${s.key}: ${s.value}
|
|
5946
5757
|
(${s.name}) ${s.usageDescription}`).join("\n\n")}
|
|
5947
5758
|
|
|
5948
|
-
Valid settings keys: ${Object.keys(
|
|
5949
|
-
worldSettings
|
|
5950
|
-
).join(
|
|
5759
|
+
Valid settings keys: ${Object.keys(worldSettings).join(
|
|
5951
5760
|
", "
|
|
5952
5761
|
)}
|
|
5953
5762
|
|
|
@@ -5962,11 +5771,9 @@ Value: ${s.value}`).join("\n")}`;
|
|
|
5962
5771
|
|
|
5963
5772
|
${requiredUnconfigured > 0 ? `IMPORTANT!: ${requiredUnconfigured} required settings still need configuration. ${runtime.character.name} should get onboarded with the OWNER as soon as possible.
|
|
5964
5773
|
|
|
5965
|
-
` : "All required settings are configured.\n\n"}${formattedSettings.map(
|
|
5966
|
-
(s) => `### ${s.name}
|
|
5774
|
+
` : "All required settings are configured.\n\n"}${formattedSettings.map((s) => `### ${s.name}
|
|
5967
5775
|
**Value:** ${s.value}
|
|
5968
|
-
**Description:** ${s.description}`
|
|
5969
|
-
).join("\n\n")}`;
|
|
5776
|
+
**Description:** ${s.description}`).join("\n\n")}`;
|
|
5970
5777
|
} catch (error) {
|
|
5971
5778
|
logger.error(`Error generating status message: ${error}`);
|
|
5972
5779
|
return "Error generating configuration status.";
|
|
@@ -5997,7 +5804,7 @@ var settingsProvider = {
|
|
|
5997
5804
|
};
|
|
5998
5805
|
}
|
|
5999
5806
|
const type = room.type;
|
|
6000
|
-
const isOnboarding = type === "
|
|
5807
|
+
const isOnboarding = type === "dm" /* DM */;
|
|
6001
5808
|
let world;
|
|
6002
5809
|
let serverId;
|
|
6003
5810
|
let worldSettings;
|
|
@@ -6017,8 +5824,6 @@ var settingsProvider = {
|
|
|
6017
5824
|
} else {
|
|
6018
5825
|
try {
|
|
6019
5826
|
world = await runtime.getWorld(room.worldId);
|
|
6020
|
-
console.log("*** world", world);
|
|
6021
|
-
console.log("*** room", room);
|
|
6022
5827
|
serverId = world.serverId;
|
|
6023
5828
|
if (serverId) {
|
|
6024
5829
|
worldSettings = await getWorldSettings2(runtime, serverId);
|
|
@@ -6072,12 +5877,7 @@ var settingsProvider = {
|
|
|
6072
5877
|
text: "Configuration has not been completed yet."
|
|
6073
5878
|
};
|
|
6074
5879
|
}
|
|
6075
|
-
const output = generateStatusMessage(
|
|
6076
|
-
runtime,
|
|
6077
|
-
worldSettings,
|
|
6078
|
-
isOnboarding,
|
|
6079
|
-
state
|
|
6080
|
-
);
|
|
5880
|
+
const output = generateStatusMessage(runtime, worldSettings, isOnboarding, state);
|
|
6081
5881
|
return {
|
|
6082
5882
|
data: {
|
|
6083
5883
|
settings: worldSettings
|
|
@@ -6112,9 +5912,7 @@ var timeProvider = {
|
|
|
6112
5912
|
dateStyle: "full",
|
|
6113
5913
|
timeStyle: "long"
|
|
6114
5914
|
};
|
|
6115
|
-
const humanReadable = new Intl.DateTimeFormat("en-US", options2).format(
|
|
6116
|
-
currentDate
|
|
6117
|
-
);
|
|
5915
|
+
const humanReadable = new Intl.DateTimeFormat("en-US", options2).format(currentDate);
|
|
6118
5916
|
return {
|
|
6119
5917
|
data: {
|
|
6120
5918
|
time: currentDate
|
|
@@ -6138,16 +5936,14 @@ var ScenarioService = class _ScenarioService extends Service {
|
|
|
6138
5936
|
constructor(runtime) {
|
|
6139
5937
|
super(runtime);
|
|
6140
5938
|
this.runtime = runtime;
|
|
6141
|
-
this.capabilityDescription = "The agent is currently in a scenario testing environment. It can create rooms, send messages, and talk to other agents in a live interactive testing environment.";
|
|
6142
|
-
this.messageHandlers = /* @__PURE__ */ new Map();
|
|
6143
|
-
this.worlds = /* @__PURE__ */ new Map();
|
|
6144
|
-
this.activeActions = /* @__PURE__ */ new Map();
|
|
6145
|
-
this.activeEvaluators = /* @__PURE__ */ new Map();
|
|
6146
5939
|
this.setupEventListeners();
|
|
6147
5940
|
}
|
|
6148
|
-
static
|
|
6149
|
-
|
|
6150
|
-
|
|
5941
|
+
static serviceType = "scenario";
|
|
5942
|
+
capabilityDescription = "The agent is currently in a scenario testing environment. It can create rooms, send messages, and talk to other agents in a live interactive testing environment.";
|
|
5943
|
+
messageHandlers = /* @__PURE__ */ new Map();
|
|
5944
|
+
worlds = /* @__PURE__ */ new Map();
|
|
5945
|
+
activeActions = /* @__PURE__ */ new Map();
|
|
5946
|
+
activeEvaluators = /* @__PURE__ */ new Map();
|
|
6151
5947
|
setupEventListeners() {
|
|
6152
5948
|
this.runtime.registerEvent("ACTION_STARTED" /* ACTION_STARTED */, async (data) => {
|
|
6153
5949
|
this.activeActions.set(data.actionId, {
|
|
@@ -6176,15 +5972,18 @@ var ScenarioService = class _ScenarioService extends Service {
|
|
|
6176
5972
|
logger_default.debug("Evaluator started", data);
|
|
6177
5973
|
return Promise.resolve();
|
|
6178
5974
|
});
|
|
6179
|
-
this.runtime.registerEvent(
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
evaluator
|
|
6183
|
-
evaluator
|
|
5975
|
+
this.runtime.registerEvent(
|
|
5976
|
+
"EVALUATOR_COMPLETED" /* EVALUATOR_COMPLETED */,
|
|
5977
|
+
async (data) => {
|
|
5978
|
+
const evaluator = this.activeEvaluators.get(data.evaluatorId);
|
|
5979
|
+
if (evaluator) {
|
|
5980
|
+
evaluator.completed = true;
|
|
5981
|
+
evaluator.error = data.error;
|
|
5982
|
+
}
|
|
5983
|
+
logger_default.debug("Evaluator completed", data);
|
|
5984
|
+
return Promise.resolve();
|
|
6184
5985
|
}
|
|
6185
|
-
|
|
6186
|
-
return Promise.resolve();
|
|
6187
|
-
});
|
|
5986
|
+
);
|
|
6188
5987
|
}
|
|
6189
5988
|
/**
|
|
6190
5989
|
* Start the scenario service with the given runtime.
|
|
@@ -6260,7 +6059,7 @@ var ScenarioService = class _ScenarioService extends Service {
|
|
|
6260
6059
|
id: roomId,
|
|
6261
6060
|
name,
|
|
6262
6061
|
source: "scenario",
|
|
6263
|
-
type: "
|
|
6062
|
+
type: "group" /* GROUP */,
|
|
6264
6063
|
channelId: roomId,
|
|
6265
6064
|
serverId: worldId
|
|
6266
6065
|
});
|
|
@@ -6304,7 +6103,7 @@ var ScenarioService = class _ScenarioService extends Service {
|
|
|
6304
6103
|
source: "scenario",
|
|
6305
6104
|
name: sender.character.name,
|
|
6306
6105
|
userName: sender.character.name,
|
|
6307
|
-
channelType: "
|
|
6106
|
+
channelType: "group" /* GROUP */
|
|
6308
6107
|
}
|
|
6309
6108
|
};
|
|
6310
6109
|
const participants = await this.runtime.getParticipantsForRoom(roomId);
|
|
@@ -6315,7 +6114,7 @@ var ScenarioService = class _ScenarioService extends Service {
|
|
|
6315
6114
|
roomId,
|
|
6316
6115
|
entityId: participantId,
|
|
6317
6116
|
source: "scenario",
|
|
6318
|
-
type: "
|
|
6117
|
+
type: "group" /* GROUP */
|
|
6319
6118
|
});
|
|
6320
6119
|
}
|
|
6321
6120
|
}
|
|
@@ -6362,16 +6161,11 @@ var ScenarioService = class _ScenarioService extends Service {
|
|
|
6362
6161
|
|
|
6363
6162
|
// src/services/task.ts
|
|
6364
6163
|
var TaskService = class _TaskService extends Service {
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
}
|
|
6371
|
-
static {
|
|
6372
|
-
// Check every second
|
|
6373
|
-
this.serviceType = ServiceType.TASK;
|
|
6374
|
-
}
|
|
6164
|
+
timer = null;
|
|
6165
|
+
TICK_INTERVAL = 1e3;
|
|
6166
|
+
// Check every second
|
|
6167
|
+
static serviceType = ServiceType.TASK;
|
|
6168
|
+
capabilityDescription = "The agent is able to schedule and execute tasks";
|
|
6375
6169
|
/**
|
|
6376
6170
|
* Start the TaskService with the given runtime.
|
|
6377
6171
|
* @param {IAgentRuntime} runtime - The runtime for the TaskService.
|
|
@@ -6465,11 +6259,7 @@ var TaskService = class _TaskService extends Service {
|
|
|
6465
6259
|
}
|
|
6466
6260
|
if (worker.validate) {
|
|
6467
6261
|
try {
|
|
6468
|
-
const isValid = await worker.validate(
|
|
6469
|
-
this.runtime,
|
|
6470
|
-
{},
|
|
6471
|
-
{}
|
|
6472
|
-
);
|
|
6262
|
+
const isValid = await worker.validate(this.runtime, {}, {});
|
|
6473
6263
|
if (!isValid) {
|
|
6474
6264
|
continue;
|
|
6475
6265
|
}
|
|
@@ -6493,9 +6283,6 @@ var TaskService = class _TaskService extends Service {
|
|
|
6493
6283
|
tags: ["queue"]
|
|
6494
6284
|
});
|
|
6495
6285
|
const tasks = await this.validateTasks(allTasks);
|
|
6496
|
-
if (tasks.length > 0) {
|
|
6497
|
-
logger_default.debug(`Found ${tasks.length} queued tasks`);
|
|
6498
|
-
}
|
|
6499
6286
|
const now = Date.now();
|
|
6500
6287
|
for (const task of tasks) {
|
|
6501
6288
|
let taskStartTime;
|
|
@@ -6550,14 +6337,10 @@ var TaskService = class _TaskService extends Service {
|
|
|
6550
6337
|
updatedAt: Date.now()
|
|
6551
6338
|
}
|
|
6552
6339
|
});
|
|
6553
|
-
logger_default.debug(
|
|
6554
|
-
`Updated repeating task ${task.name} (${task.id}) with new timestamp`
|
|
6555
|
-
);
|
|
6340
|
+
logger_default.debug(`Updated repeating task ${task.name} (${task.id}) with new timestamp`);
|
|
6556
6341
|
} else {
|
|
6557
6342
|
await this.runtime.deleteTask(task.id);
|
|
6558
|
-
logger_default.debug(
|
|
6559
|
-
`Deleted non-repeating task ${task.name} (${task.id}) after execution`
|
|
6560
|
-
);
|
|
6343
|
+
logger_default.debug(`Deleted non-repeating task ${task.name} (${task.id}) after execution`);
|
|
6561
6344
|
}
|
|
6562
6345
|
} catch (error) {
|
|
6563
6346
|
logger_default.error(`Error executing task ${task.id}:`, error);
|
|
@@ -6593,7 +6376,6 @@ var messageReceivedHandler = async ({
|
|
|
6593
6376
|
message,
|
|
6594
6377
|
callback
|
|
6595
6378
|
}) => {
|
|
6596
|
-
console.log("*** messageReceivedHandler for " + runtime.character.name + " ***", message);
|
|
6597
6379
|
const responseId = v4();
|
|
6598
6380
|
if (!latestResponseIds.has(runtime.agentId)) {
|
|
6599
6381
|
latestResponseIds.set(runtime.agentId, /* @__PURE__ */ new Map());
|
|
@@ -6643,7 +6425,7 @@ var messageReceivedHandler = async ({
|
|
|
6643
6425
|
]);
|
|
6644
6426
|
const agentUserState = await runtime.getParticipantUserState(message.roomId, runtime.agentId);
|
|
6645
6427
|
if (agentUserState === "MUTED" && !message.content.text?.toLowerCase().includes(runtime.character.name.toLowerCase())) {
|
|
6646
|
-
|
|
6428
|
+
logger.debug("Ignoring muted room");
|
|
6647
6429
|
return;
|
|
6648
6430
|
}
|
|
6649
6431
|
let state = await runtime.composeState(message, [
|
|
@@ -6658,16 +6440,15 @@ var messageReceivedHandler = async ({
|
|
|
6658
6440
|
template: runtime.character.templates?.shouldRespondTemplate || shouldRespondTemplate
|
|
6659
6441
|
});
|
|
6660
6442
|
logger.debug(
|
|
6661
|
-
`*** Should Respond Prompt for ${runtime.character.name}
|
|
6443
|
+
`*** Should Respond Prompt for ${runtime.character.name} ***
|
|
6444
|
+
`,
|
|
6662
6445
|
shouldRespondPrompt
|
|
6663
6446
|
);
|
|
6664
6447
|
const response = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
6665
6448
|
prompt: shouldRespondPrompt
|
|
6666
6449
|
});
|
|
6667
|
-
logger.debug(
|
|
6668
|
-
|
|
6669
|
-
response
|
|
6670
|
-
);
|
|
6450
|
+
logger.debug(`*** Should Respond Response for ${runtime.character.name} ***
|
|
6451
|
+
`, response);
|
|
6671
6452
|
const responseObject = parseJSONObjectFromText(response);
|
|
6672
6453
|
const providers = responseObject.providers;
|
|
6673
6454
|
const shouldRespond = responseObject?.action && responseObject.action === "RESPOND";
|
|
@@ -6689,7 +6470,6 @@ var messageReceivedHandler = async ({
|
|
|
6689
6470
|
retries++;
|
|
6690
6471
|
if ((!responseContent?.thought || !responseContent?.plan) && !responseContent?.actions) {
|
|
6691
6472
|
logger.warn("*** Missing required fields, retrying... ***");
|
|
6692
|
-
console.log("*** responseContent is", responseContent);
|
|
6693
6473
|
}
|
|
6694
6474
|
}
|
|
6695
6475
|
const currentResponseId = agentResponses.get(message.roomId);
|
|
@@ -6712,18 +6492,21 @@ var messageReceivedHandler = async ({
|
|
|
6712
6492
|
createdAt: Date.now()
|
|
6713
6493
|
}
|
|
6714
6494
|
];
|
|
6715
|
-
await runtime.createMemory(
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6495
|
+
await runtime.createMemory(
|
|
6496
|
+
{
|
|
6497
|
+
entityId: runtime.agentId,
|
|
6498
|
+
agentId: runtime.agentId,
|
|
6499
|
+
content: {
|
|
6500
|
+
thought: responseContent.thought,
|
|
6501
|
+
plan: responseContent.plan,
|
|
6502
|
+
actions: responseContent.actions,
|
|
6503
|
+
providers: responseContent.providers
|
|
6504
|
+
},
|
|
6505
|
+
roomId: message.roomId,
|
|
6506
|
+
createdAt: Date.now()
|
|
6723
6507
|
},
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
}, "messages");
|
|
6508
|
+
"messages"
|
|
6509
|
+
);
|
|
6727
6510
|
}
|
|
6728
6511
|
agentResponses.delete(message.roomId);
|
|
6729
6512
|
if (agentResponses.size === 0) {
|
|
@@ -6731,13 +6514,7 @@ var messageReceivedHandler = async ({
|
|
|
6731
6514
|
}
|
|
6732
6515
|
await runtime.processActions(message, responseMessages, state, callback);
|
|
6733
6516
|
}
|
|
6734
|
-
await runtime.evaluate(
|
|
6735
|
-
message,
|
|
6736
|
-
state,
|
|
6737
|
-
shouldRespond,
|
|
6738
|
-
callback,
|
|
6739
|
-
responseMessages
|
|
6740
|
-
);
|
|
6517
|
+
await runtime.evaluate(message, state, shouldRespond, callback, responseMessages);
|
|
6741
6518
|
await runtime.emitEvent("RUN_ENDED" /* RUN_ENDED */, {
|
|
6742
6519
|
runtime,
|
|
6743
6520
|
runId,
|
|
@@ -6839,7 +6616,6 @@ var postGeneratedHandler = async ({
|
|
|
6839
6616
|
return cleanedText2;
|
|
6840
6617
|
}
|
|
6841
6618
|
const cleanedText = cleanupTweetText(jsonResponse.post);
|
|
6842
|
-
console.log("creating memory");
|
|
6843
6619
|
const responseMessages = [
|
|
6844
6620
|
{
|
|
6845
6621
|
id: v4(),
|
|
@@ -6858,8 +6634,6 @@ var postGeneratedHandler = async ({
|
|
|
6858
6634
|
}
|
|
6859
6635
|
];
|
|
6860
6636
|
for (const message2 of responseMessages) {
|
|
6861
|
-
console.log("message is", message2);
|
|
6862
|
-
console.log("message.content is", message2.content);
|
|
6863
6637
|
await callback(message2.content);
|
|
6864
6638
|
}
|
|
6865
6639
|
};
|
|
@@ -6886,23 +6660,12 @@ var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source
|
|
|
6886
6660
|
});
|
|
6887
6661
|
logger.success(`Successfully synced user: ${entity.id}`);
|
|
6888
6662
|
} catch (error) {
|
|
6889
|
-
logger.error(
|
|
6890
|
-
`Error syncing user: ${error instanceof Error ? error.message : String(error)}`
|
|
6891
|
-
);
|
|
6663
|
+
logger.error(`Error syncing user: ${error instanceof Error ? error.message : String(error)}`);
|
|
6892
6664
|
}
|
|
6893
6665
|
};
|
|
6894
|
-
var handleServerSync = async ({
|
|
6895
|
-
|
|
6896
|
-
world,
|
|
6897
|
-
rooms,
|
|
6898
|
-
entities,
|
|
6899
|
-
source
|
|
6900
|
-
}) => {
|
|
6901
|
-
logger.info(`Handling server sync event for server: ${world.name}`);
|
|
6666
|
+
var handleServerSync = async ({ runtime, world, rooms, entities, source }) => {
|
|
6667
|
+
logger.debug(`Handling server sync event for server: ${world.name}`);
|
|
6902
6668
|
try {
|
|
6903
|
-
console.log("world.id", world.id);
|
|
6904
|
-
console.log("agentId", runtime.agentId);
|
|
6905
|
-
console.log("runtime.serverId", runtime.agentId);
|
|
6906
6669
|
await runtime.ensureWorldExists({
|
|
6907
6670
|
id: world.id,
|
|
6908
6671
|
name: world.name,
|
|
@@ -6945,9 +6708,7 @@ var handleServerSync = async ({
|
|
|
6945
6708
|
worldId: world.id
|
|
6946
6709
|
});
|
|
6947
6710
|
} catch (err) {
|
|
6948
|
-
logger.warn(
|
|
6949
|
-
`Failed to sync user ${entity.metadata.username}: ${err}`
|
|
6950
|
-
);
|
|
6711
|
+
logger.warn(`Failed to sync user ${entity.metadata.username}: ${err}`);
|
|
6951
6712
|
}
|
|
6952
6713
|
})
|
|
6953
6714
|
);
|
|
@@ -6956,9 +6717,7 @@ var handleServerSync = async ({
|
|
|
6956
6717
|
}
|
|
6957
6718
|
}
|
|
6958
6719
|
}
|
|
6959
|
-
logger.
|
|
6960
|
-
`Successfully synced standardized world structure for ${world.name}`
|
|
6961
|
-
);
|
|
6720
|
+
logger.debug(`Successfully synced standardized world structure for ${world.name}`);
|
|
6962
6721
|
} catch (error) {
|
|
6963
6722
|
logger.error(
|
|
6964
6723
|
`Error processing standardized server data: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -7107,8 +6866,8 @@ var bootstrapPlugin = {
|
|
|
7107
6866
|
|
|
7108
6867
|
// src/uuid.ts
|
|
7109
6868
|
import { sha1 } from "js-sha1";
|
|
7110
|
-
import { z as
|
|
7111
|
-
var uuidSchema =
|
|
6869
|
+
import { z as z2 } from "zod";
|
|
6870
|
+
var uuidSchema = z2.string().uuid();
|
|
7112
6871
|
function validateUuid(value) {
|
|
7113
6872
|
const result = uuidSchema.safeParse(value);
|
|
7114
6873
|
return result.success ? result.data : null;
|
|
@@ -7147,9 +6906,69 @@ function stringToUuid(target) {
|
|
|
7147
6906
|
}
|
|
7148
6907
|
|
|
7149
6908
|
// src/runtime.ts
|
|
6909
|
+
import fs2 from "node:fs";
|
|
6910
|
+
import path2 from "node:path";
|
|
6911
|
+
var environmentSettings = {};
|
|
6912
|
+
function loadEnvConfig() {
|
|
6913
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
6914
|
+
return environmentSettings;
|
|
6915
|
+
}
|
|
6916
|
+
let dotenv = null;
|
|
6917
|
+
try {
|
|
6918
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
6919
|
+
dotenv = __require("dotenv");
|
|
6920
|
+
}
|
|
6921
|
+
} catch (err) {
|
|
6922
|
+
logger_default.debug("dotenv module not available");
|
|
6923
|
+
}
|
|
6924
|
+
function findNearestEnvFile(startDir = process.cwd()) {
|
|
6925
|
+
let currentDir = startDir;
|
|
6926
|
+
while (currentDir !== path2.parse(currentDir).root) {
|
|
6927
|
+
const envPath2 = path2.join(currentDir, ".env");
|
|
6928
|
+
if (fs2.existsSync(envPath2)) {
|
|
6929
|
+
return envPath2;
|
|
6930
|
+
}
|
|
6931
|
+
currentDir = path2.dirname(currentDir);
|
|
6932
|
+
}
|
|
6933
|
+
const rootEnvPath = path2.join(path2.parse(currentDir).root, ".env");
|
|
6934
|
+
return fs2.existsSync(rootEnvPath) ? rootEnvPath : null;
|
|
6935
|
+
}
|
|
6936
|
+
const envPath = findNearestEnvFile();
|
|
6937
|
+
try {
|
|
6938
|
+
if (dotenv) {
|
|
6939
|
+
const result = dotenv.config(envPath ? { path: envPath } : {});
|
|
6940
|
+
if (!result.error && envPath) {
|
|
6941
|
+
logger_default.log(`Loaded .env file from: ${envPath}`);
|
|
6942
|
+
}
|
|
6943
|
+
}
|
|
6944
|
+
} catch (err) {
|
|
6945
|
+
logger_default.warn("Failed to load .env file:", err);
|
|
6946
|
+
}
|
|
6947
|
+
const env = typeof process !== "undefined" ? process.env : import.meta.env;
|
|
6948
|
+
const namespacedSettings = parseNamespacedSettings(env);
|
|
6949
|
+
if (typeof process !== "undefined") {
|
|
6950
|
+
Object.entries(namespacedSettings).forEach(([namespace, settings]) => {
|
|
6951
|
+
process.env[`__namespaced_${namespace}`] = JSON.stringify(settings);
|
|
6952
|
+
});
|
|
6953
|
+
}
|
|
6954
|
+
return env;
|
|
6955
|
+
}
|
|
6956
|
+
function parseNamespacedSettings(env) {
|
|
6957
|
+
const namespaced = {};
|
|
6958
|
+
for (const [key, value] of Object.entries(env)) {
|
|
6959
|
+
if (!value) continue;
|
|
6960
|
+
const [namespace, ...rest] = key.split(".");
|
|
6961
|
+
if (!namespace || rest.length === 0) continue;
|
|
6962
|
+
const settingKey = rest.join(".");
|
|
6963
|
+
namespaced[namespace] = namespaced[namespace] || {};
|
|
6964
|
+
namespaced[namespace][settingKey] = value;
|
|
6965
|
+
}
|
|
6966
|
+
return namespaced;
|
|
6967
|
+
}
|
|
7150
6968
|
var Semaphore = class {
|
|
6969
|
+
permits;
|
|
6970
|
+
waiting = [];
|
|
7151
6971
|
constructor(count) {
|
|
7152
|
-
this.waiting = [];
|
|
7153
6972
|
this.permits = count;
|
|
7154
6973
|
}
|
|
7155
6974
|
async acquire() {
|
|
@@ -7171,44 +6990,54 @@ var Semaphore = class {
|
|
|
7171
6990
|
}
|
|
7172
6991
|
};
|
|
7173
6992
|
var AgentRuntime = class {
|
|
6993
|
+
#conversationLength = 32;
|
|
6994
|
+
agentId;
|
|
6995
|
+
character;
|
|
6996
|
+
adapter;
|
|
6997
|
+
actions = [];
|
|
6998
|
+
evaluators = [];
|
|
6999
|
+
providers = [];
|
|
7000
|
+
plugins = [];
|
|
7001
|
+
events = /* @__PURE__ */ new Map();
|
|
7002
|
+
stateCache = /* @__PURE__ */ new Map();
|
|
7003
|
+
fetch = fetch;
|
|
7004
|
+
services = /* @__PURE__ */ new Map();
|
|
7005
|
+
models = /* @__PURE__ */ new Map();
|
|
7006
|
+
routes = [];
|
|
7007
|
+
taskWorkers = /* @__PURE__ */ new Map();
|
|
7008
|
+
// Event emitter methods
|
|
7009
|
+
eventHandlers = /* @__PURE__ */ new Map();
|
|
7010
|
+
runtimeLogger;
|
|
7011
|
+
knowledgeProcessingSemaphore = new Semaphore(10);
|
|
7012
|
+
settings;
|
|
7174
7013
|
constructor(opts) {
|
|
7175
|
-
this.#conversationLength = 32;
|
|
7176
|
-
this.actions = [];
|
|
7177
|
-
this.evaluators = [];
|
|
7178
|
-
this.providers = [];
|
|
7179
|
-
this.plugins = [];
|
|
7180
|
-
this.events = /* @__PURE__ */ new Map();
|
|
7181
|
-
this.stateCache = /* @__PURE__ */ new Map();
|
|
7182
|
-
this.fetch = fetch;
|
|
7183
|
-
this.services = /* @__PURE__ */ new Map();
|
|
7184
|
-
this.models = /* @__PURE__ */ new Map();
|
|
7185
|
-
this.routes = [];
|
|
7186
|
-
this.taskWorkers = /* @__PURE__ */ new Map();
|
|
7187
|
-
// Event emitter methods
|
|
7188
|
-
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
7189
|
-
this.knowledgeProcessingSemaphore = new Semaphore(10);
|
|
7190
7014
|
this.agentId = opts.character?.id ?? opts?.agentId ?? stringToUuid(opts.character?.name ?? uuidv43());
|
|
7191
7015
|
this.character = opts.character;
|
|
7016
|
+
const logLevel = process.env.LOG_LEVEL || "info";
|
|
7192
7017
|
this.runtimeLogger = logger_default.child({
|
|
7193
7018
|
agentName: this.character?.name,
|
|
7194
|
-
agentId: this.agentId
|
|
7019
|
+
agentId: this.agentId,
|
|
7020
|
+
level: logLevel === "debug" ? "debug" : "error"
|
|
7021
|
+
// Show only errors unless debug mode is enabled
|
|
7195
7022
|
});
|
|
7196
|
-
this.runtimeLogger.debug(
|
|
7197
|
-
`[AgentRuntime] Process working directory: ${process.cwd()}`
|
|
7198
|
-
);
|
|
7023
|
+
this.runtimeLogger.debug(`[AgentRuntime] Process working directory: ${process.cwd()}`);
|
|
7199
7024
|
this.#conversationLength = opts.conversationLength ?? this.#conversationLength;
|
|
7200
7025
|
if (opts.adapter) {
|
|
7201
7026
|
this.registerDatabaseAdapter(opts.adapter);
|
|
7202
7027
|
}
|
|
7203
|
-
this.runtimeLogger.success(`Agent ID: ${this.agentId}`);
|
|
7204
7028
|
this.fetch = opts.fetch ?? this.fetch;
|
|
7029
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
7030
|
+
this.settings = environmentSettings;
|
|
7031
|
+
} else {
|
|
7032
|
+
this.settings = loadEnvConfig();
|
|
7033
|
+
}
|
|
7205
7034
|
const plugins = opts?.plugins ?? [];
|
|
7206
7035
|
if (!opts?.ignoreBootstrap) {
|
|
7207
7036
|
plugins.push(bootstrapPlugin);
|
|
7208
7037
|
}
|
|
7209
7038
|
this.plugins = plugins;
|
|
7039
|
+
this.runtimeLogger.debug(`Success: Agent ID: ${this.agentId}`);
|
|
7210
7040
|
}
|
|
7211
|
-
#conversationLength;
|
|
7212
7041
|
/**
|
|
7213
7042
|
* Registers a plugin with the runtime and initializes its components
|
|
7214
7043
|
* @param plugin The plugin to register
|
|
@@ -7220,22 +7049,16 @@ var AgentRuntime = class {
|
|
|
7220
7049
|
}
|
|
7221
7050
|
if (!this.plugins.some((p) => p.name === plugin.name)) {
|
|
7222
7051
|
this.plugins.push(plugin);
|
|
7223
|
-
this.runtimeLogger.
|
|
7224
|
-
`Plugin ${plugin.name} registered successfully`
|
|
7225
|
-
);
|
|
7052
|
+
this.runtimeLogger.debug(`Success: Plugin ${plugin.name} registered successfully`);
|
|
7226
7053
|
}
|
|
7227
7054
|
if (plugin.init) {
|
|
7228
7055
|
try {
|
|
7229
7056
|
await plugin.init(plugin.config || {}, this);
|
|
7230
|
-
this.runtimeLogger.
|
|
7231
|
-
`Plugin ${plugin.name} initialized successfully`
|
|
7232
|
-
);
|
|
7057
|
+
this.runtimeLogger.debug(`Success: Plugin ${plugin.name} initialized successfully`);
|
|
7233
7058
|
} catch (error) {
|
|
7234
7059
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
7235
7060
|
if (errorMessage.includes("API key") || errorMessage.includes("environment variables") || errorMessage.includes("Invalid plugin configuration")) {
|
|
7236
|
-
console.warn(
|
|
7237
|
-
`Plugin ${plugin.name} requires configuration. ${errorMessage}`
|
|
7238
|
-
);
|
|
7061
|
+
console.warn(`Plugin ${plugin.name} requires configuration. ${errorMessage}`);
|
|
7239
7062
|
console.warn(
|
|
7240
7063
|
"Please check your environment variables and ensure all required API keys are set."
|
|
7241
7064
|
);
|
|
@@ -7246,9 +7069,7 @@ var AgentRuntime = class {
|
|
|
7246
7069
|
}
|
|
7247
7070
|
}
|
|
7248
7071
|
if (plugin.adapter) {
|
|
7249
|
-
this.runtimeLogger.debug(
|
|
7250
|
-
`Registering database adapter for plugin ${plugin.name}`
|
|
7251
|
-
);
|
|
7072
|
+
this.runtimeLogger.debug(`Registering database adapter for plugin ${plugin.name}`);
|
|
7252
7073
|
this.registerDatabaseAdapter(plugin.adapter);
|
|
7253
7074
|
}
|
|
7254
7075
|
if (plugin.actions) {
|
|
@@ -7268,10 +7089,7 @@ var AgentRuntime = class {
|
|
|
7268
7089
|
}
|
|
7269
7090
|
if (plugin.models) {
|
|
7270
7091
|
for (const [modelType, handler2] of Object.entries(plugin.models)) {
|
|
7271
|
-
this.registerModel(
|
|
7272
|
-
modelType,
|
|
7273
|
-
handler2
|
|
7274
|
-
);
|
|
7092
|
+
this.registerModel(modelType, handler2);
|
|
7275
7093
|
}
|
|
7276
7094
|
}
|
|
7277
7095
|
if (plugin.routes) {
|
|
@@ -7287,22 +7105,16 @@ var AgentRuntime = class {
|
|
|
7287
7105
|
}
|
|
7288
7106
|
}
|
|
7289
7107
|
if (plugin.services) {
|
|
7290
|
-
await Promise.all(
|
|
7291
|
-
plugin.services.map((service) => this.registerService(service))
|
|
7292
|
-
);
|
|
7108
|
+
await Promise.all(plugin.services.map((service) => this.registerService(service)));
|
|
7293
7109
|
}
|
|
7294
7110
|
}
|
|
7295
7111
|
getAllServices() {
|
|
7296
7112
|
return this.services;
|
|
7297
7113
|
}
|
|
7298
7114
|
async stop() {
|
|
7299
|
-
this.runtimeLogger.debug(
|
|
7300
|
-
`runtime::stop - character ${this.character.name}`
|
|
7301
|
-
);
|
|
7115
|
+
this.runtimeLogger.debug(`runtime::stop - character ${this.character.name}`);
|
|
7302
7116
|
for (const [serviceName, service] of this.services) {
|
|
7303
|
-
this.runtimeLogger.
|
|
7304
|
-
`runtime::stop - requesting service stop for ${serviceName}`
|
|
7305
|
-
);
|
|
7117
|
+
this.runtimeLogger.debug(`runtime::stop - requesting service stop for ${serviceName}`);
|
|
7306
7118
|
await service.stop();
|
|
7307
7119
|
}
|
|
7308
7120
|
}
|
|
@@ -7310,9 +7122,7 @@ var AgentRuntime = class {
|
|
|
7310
7122
|
const registeredPluginNames = /* @__PURE__ */ new Set();
|
|
7311
7123
|
const pluginRegistrationPromises = [];
|
|
7312
7124
|
if (this.character.plugins) {
|
|
7313
|
-
const characterPlugins = await handlePluginImporting(
|
|
7314
|
-
this.character.plugins
|
|
7315
|
-
);
|
|
7125
|
+
const characterPlugins = await handlePluginImporting(this.character.plugins);
|
|
7316
7126
|
for (const plugin of characterPlugins) {
|
|
7317
7127
|
if (plugin && !registeredPluginNames.has(plugin.name)) {
|
|
7318
7128
|
registeredPluginNames.add(plugin.name);
|
|
@@ -7328,9 +7138,7 @@ var AgentRuntime = class {
|
|
|
7328
7138
|
}
|
|
7329
7139
|
await this.adapter.init();
|
|
7330
7140
|
try {
|
|
7331
|
-
const agentExists = await this.adapter.ensureAgentExists(
|
|
7332
|
-
this.character
|
|
7333
|
-
);
|
|
7141
|
+
const agentExists = await this.adapter.ensureAgentExists(this.character);
|
|
7334
7142
|
const agent = await this.adapter.getAgent(this.agentId);
|
|
7335
7143
|
if (!agent) {
|
|
7336
7144
|
throw new Error(
|
|
@@ -7339,19 +7147,17 @@ var AgentRuntime = class {
|
|
|
7339
7147
|
}
|
|
7340
7148
|
const agentEntity = await this.adapter.getEntityById(this.agentId);
|
|
7341
7149
|
if (!agentEntity) {
|
|
7342
|
-
const created = await this.
|
|
7150
|
+
const created = await this.createEntity({
|
|
7343
7151
|
id: this.agentId,
|
|
7344
7152
|
agentId: this.agentId,
|
|
7345
|
-
names: Array.from(
|
|
7346
|
-
new Set([this.character.name].filter(Boolean))
|
|
7347
|
-
),
|
|
7153
|
+
names: Array.from(new Set([this.character.name].filter(Boolean))),
|
|
7348
7154
|
metadata: {}
|
|
7349
7155
|
});
|
|
7350
7156
|
if (!created) {
|
|
7351
7157
|
throw new Error(`Failed to create entity for agent ${this.agentId}`);
|
|
7352
7158
|
}
|
|
7353
|
-
this.runtimeLogger.
|
|
7354
|
-
`Agent entity created successfully for ${this.character.name}`
|
|
7159
|
+
this.runtimeLogger.debug(
|
|
7160
|
+
`Success: Agent entity created successfully for ${this.character.name}`
|
|
7355
7161
|
);
|
|
7356
7162
|
}
|
|
7357
7163
|
} catch (error) {
|
|
@@ -7377,20 +7183,13 @@ var AgentRuntime = class {
|
|
|
7377
7183
|
throw error;
|
|
7378
7184
|
}
|
|
7379
7185
|
try {
|
|
7380
|
-
const participants = await this.adapter.getParticipantsForRoom(
|
|
7381
|
-
this.agentId
|
|
7382
|
-
);
|
|
7186
|
+
const participants = await this.adapter.getParticipantsForRoom(this.agentId);
|
|
7383
7187
|
if (!participants.includes(this.agentId)) {
|
|
7384
|
-
const added = await this.adapter.addParticipant(
|
|
7385
|
-
this.agentId,
|
|
7386
|
-
this.agentId
|
|
7387
|
-
);
|
|
7188
|
+
const added = await this.adapter.addParticipant(this.agentId, this.agentId);
|
|
7388
7189
|
if (!added) {
|
|
7389
|
-
throw new Error(
|
|
7390
|
-
`Failed to add agent ${this.agentId} as participant to its own room`
|
|
7391
|
-
);
|
|
7190
|
+
throw new Error(`Failed to add agent ${this.agentId} as participant to its own room`);
|
|
7392
7191
|
}
|
|
7393
|
-
this.runtimeLogger.
|
|
7192
|
+
this.runtimeLogger.debug(
|
|
7394
7193
|
`Agent ${this.character.name} linked to its own room successfully`
|
|
7395
7194
|
);
|
|
7396
7195
|
}
|
|
@@ -7416,10 +7215,7 @@ var AgentRuntime = class {
|
|
|
7416
7215
|
}
|
|
7417
7216
|
}
|
|
7418
7217
|
async handleProcessingError(error, context) {
|
|
7419
|
-
this.runtimeLogger.error(
|
|
7420
|
-
`Error ${context}:`,
|
|
7421
|
-
error?.message || error || "Unknown error"
|
|
7422
|
-
);
|
|
7218
|
+
this.runtimeLogger.error(`Error ${context}:`, error?.message || error || "Unknown error");
|
|
7423
7219
|
throw error;
|
|
7424
7220
|
}
|
|
7425
7221
|
async checkExistingKnowledge(knowledgeId) {
|
|
@@ -7452,7 +7248,7 @@ var AgentRuntime = class {
|
|
|
7452
7248
|
const uniqueSources = [
|
|
7453
7249
|
...new Set(
|
|
7454
7250
|
fragments.map((memory) => {
|
|
7455
|
-
this.runtimeLogger.
|
|
7251
|
+
this.runtimeLogger.debug(
|
|
7456
7252
|
`Matched fragment: ${memory.content.text} with similarity: ${memory.similarity}`
|
|
7457
7253
|
);
|
|
7458
7254
|
return memory.content.source;
|
|
@@ -7481,16 +7277,9 @@ var AgentRuntime = class {
|
|
|
7481
7277
|
}
|
|
7482
7278
|
};
|
|
7483
7279
|
await this.createMemory(documentMemory, "documents");
|
|
7484
|
-
const fragments = await splitChunks(
|
|
7485
|
-
item.content.text,
|
|
7486
|
-
options2.targetTokens,
|
|
7487
|
-
options2.overlap
|
|
7488
|
-
);
|
|
7280
|
+
const fragments = await splitChunks(item.content.text, options2.targetTokens, options2.overlap);
|
|
7489
7281
|
for (let i = 0; i < fragments.length; i++) {
|
|
7490
|
-
const embedding = await this.useModel(
|
|
7491
|
-
ModelType.TEXT_EMBEDDING,
|
|
7492
|
-
fragments[i]
|
|
7493
|
-
);
|
|
7282
|
+
const embedding = await this.useModel(ModelType.TEXT_EMBEDDING, fragments[i]);
|
|
7494
7283
|
const fragmentMemory = {
|
|
7495
7284
|
id: createUniqueUuid(this, `${item.id}-fragment-${i}`),
|
|
7496
7285
|
agentId: this.agentId,
|
|
@@ -7518,7 +7307,7 @@ var AgentRuntime = class {
|
|
|
7518
7307
|
if (await this.checkExistingKnowledge(knowledgeId)) {
|
|
7519
7308
|
return;
|
|
7520
7309
|
}
|
|
7521
|
-
this.runtimeLogger.
|
|
7310
|
+
this.runtimeLogger.debug(
|
|
7522
7311
|
"Processing knowledge for ",
|
|
7523
7312
|
this.character.name,
|
|
7524
7313
|
" - ",
|
|
@@ -7531,10 +7320,7 @@ var AgentRuntime = class {
|
|
|
7531
7320
|
}
|
|
7532
7321
|
});
|
|
7533
7322
|
} catch (error) {
|
|
7534
|
-
await this.handleProcessingError(
|
|
7535
|
-
error,
|
|
7536
|
-
"processing character knowledge"
|
|
7537
|
-
);
|
|
7323
|
+
await this.handleProcessingError(error, "processing character knowledge");
|
|
7538
7324
|
} finally {
|
|
7539
7325
|
this.knowledgeProcessingSemaphore.release();
|
|
7540
7326
|
}
|
|
@@ -7555,7 +7341,7 @@ var AgentRuntime = class {
|
|
|
7555
7341
|
}
|
|
7556
7342
|
}
|
|
7557
7343
|
getSetting(key) {
|
|
7558
|
-
const value = this.character.secrets?.[key] || this.character.settings?.[key] || this.character.settings?.secrets?.[key] || settings[key];
|
|
7344
|
+
const value = this.character.secrets?.[key] || this.character.settings?.[key] || this.character.settings?.secrets?.[key] || this.settings[key];
|
|
7559
7345
|
if (value === "true") return true;
|
|
7560
7346
|
if (value === "false") return false;
|
|
7561
7347
|
return value || null;
|
|
@@ -7574,7 +7360,7 @@ var AgentRuntime = class {
|
|
|
7574
7360
|
);
|
|
7575
7361
|
} else {
|
|
7576
7362
|
this.adapter = adapter;
|
|
7577
|
-
this.runtimeLogger.
|
|
7363
|
+
this.runtimeLogger.debug("Success: Database adapter registered successfully.");
|
|
7578
7364
|
}
|
|
7579
7365
|
}
|
|
7580
7366
|
/**
|
|
@@ -7583,9 +7369,7 @@ var AgentRuntime = class {
|
|
|
7583
7369
|
*/
|
|
7584
7370
|
registerProvider(provider) {
|
|
7585
7371
|
this.providers.push(provider);
|
|
7586
|
-
this.runtimeLogger.
|
|
7587
|
-
`Provider ${provider.name} registered successfully.`
|
|
7588
|
-
);
|
|
7372
|
+
this.runtimeLogger.debug(`Success: Provider ${provider.name} registered successfully.`);
|
|
7589
7373
|
}
|
|
7590
7374
|
/**
|
|
7591
7375
|
* Register an action for the agent to perform.
|
|
@@ -7601,7 +7385,7 @@ var AgentRuntime = class {
|
|
|
7601
7385
|
);
|
|
7602
7386
|
} else {
|
|
7603
7387
|
this.actions.push(action);
|
|
7604
|
-
this.runtimeLogger.
|
|
7388
|
+
this.runtimeLogger.debug(
|
|
7605
7389
|
`${this.character.name}(${this.agentId}) - Action ${action.name} registered successfully.`
|
|
7606
7390
|
);
|
|
7607
7391
|
}
|
|
@@ -7637,12 +7421,12 @@ var AgentRuntime = class {
|
|
|
7637
7421
|
continue;
|
|
7638
7422
|
}
|
|
7639
7423
|
const actions = response.content.actions;
|
|
7640
|
-
this.runtimeLogger.
|
|
7424
|
+
this.runtimeLogger.debug(
|
|
7641
7425
|
`Found actions: ${this.actions.map((a) => normalizeAction(a.name))}`
|
|
7642
7426
|
);
|
|
7643
7427
|
for (const responseAction of actions) {
|
|
7644
7428
|
state = await this.composeState(message, ["RECENT_MESSAGES"]);
|
|
7645
|
-
this.runtimeLogger.
|
|
7429
|
+
this.runtimeLogger.debug(`Success: Calling action: ${responseAction}`);
|
|
7646
7430
|
const normalizedResponseAction = normalizeAction(responseAction);
|
|
7647
7431
|
let action = this.actions.find(
|
|
7648
7432
|
(a) => normalizeAction(a.name).includes(normalizedResponseAction) || // the || is kind of a fuzzy match
|
|
@@ -7650,32 +7434,22 @@ var AgentRuntime = class {
|
|
|
7650
7434
|
//
|
|
7651
7435
|
);
|
|
7652
7436
|
if (action) {
|
|
7653
|
-
this.runtimeLogger.
|
|
7437
|
+
this.runtimeLogger.debug(`Success: Found action: ${action?.name}`);
|
|
7654
7438
|
} else {
|
|
7655
|
-
this.runtimeLogger.
|
|
7656
|
-
}
|
|
7657
|
-
if (!action) {
|
|
7658
|
-
this.runtimeLogger.info("Attempting to find action in similes.");
|
|
7439
|
+
this.runtimeLogger.debug("Attempting to find action in similes.");
|
|
7659
7440
|
for (const _action of this.actions) {
|
|
7660
7441
|
const simileAction = _action.similes?.find(
|
|
7661
|
-
(simile) => simile.toLowerCase().replace("_", "").includes(normalizedResponseAction) || normalizedResponseAction.includes(
|
|
7662
|
-
simile.toLowerCase().replace("_", "")
|
|
7663
|
-
)
|
|
7442
|
+
(simile) => simile.toLowerCase().replace("_", "").includes(normalizedResponseAction) || normalizedResponseAction.includes(simile.toLowerCase().replace("_", ""))
|
|
7664
7443
|
);
|
|
7665
7444
|
if (simileAction) {
|
|
7666
7445
|
action = _action;
|
|
7667
|
-
this.runtimeLogger.
|
|
7668
|
-
`Action found in similes: ${action.name}`
|
|
7669
|
-
);
|
|
7446
|
+
this.runtimeLogger.debug(`Success: Action found in similes: ${action.name}`);
|
|
7670
7447
|
break;
|
|
7671
7448
|
}
|
|
7672
7449
|
}
|
|
7673
7450
|
}
|
|
7674
7451
|
if (!action) {
|
|
7675
|
-
this.runtimeLogger.error(
|
|
7676
|
-
"No action found in",
|
|
7677
|
-
JSON.stringify(response)
|
|
7678
|
-
);
|
|
7452
|
+
this.runtimeLogger.error(`No action found for: ${responseAction}`);
|
|
7679
7453
|
continue;
|
|
7680
7454
|
}
|
|
7681
7455
|
if (!action.handler) {
|
|
@@ -7683,13 +7457,9 @@ var AgentRuntime = class {
|
|
|
7683
7457
|
continue;
|
|
7684
7458
|
}
|
|
7685
7459
|
try {
|
|
7686
|
-
this.runtimeLogger.
|
|
7687
|
-
`Executing handler for action: ${action.name}`
|
|
7688
|
-
);
|
|
7460
|
+
this.runtimeLogger.debug(`Executing handler for action: ${action.name}`);
|
|
7689
7461
|
await action.handler(this, message, state, {}, callback, responses);
|
|
7690
|
-
this.runtimeLogger.
|
|
7691
|
-
`Action ${action.name} executed successfully.`
|
|
7692
|
-
);
|
|
7462
|
+
this.runtimeLogger.debug(`Success: Action ${action.name} executed successfully.`);
|
|
7693
7463
|
this.adapter.log({
|
|
7694
7464
|
entityId: message.entityId,
|
|
7695
7465
|
roomId: message.roomId,
|
|
@@ -7718,24 +7488,20 @@ var AgentRuntime = class {
|
|
|
7718
7488
|
* @returns The results of the evaluation.
|
|
7719
7489
|
*/
|
|
7720
7490
|
async evaluate(message, state, didRespond, callback, responses) {
|
|
7721
|
-
const evaluatorPromises = this.evaluators.map(
|
|
7722
|
-
|
|
7723
|
-
if (!evaluator.handler) {
|
|
7724
|
-
return null;
|
|
7725
|
-
}
|
|
7726
|
-
if (!didRespond && !evaluator.alwaysRun) {
|
|
7727
|
-
return null;
|
|
7728
|
-
}
|
|
7729
|
-
const result = await evaluator.validate(this, message, state);
|
|
7730
|
-
if (result) {
|
|
7731
|
-
return evaluator;
|
|
7732
|
-
}
|
|
7491
|
+
const evaluatorPromises = this.evaluators.map(async (evaluator) => {
|
|
7492
|
+
if (!evaluator.handler) {
|
|
7733
7493
|
return null;
|
|
7734
7494
|
}
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7495
|
+
if (!didRespond && !evaluator.alwaysRun) {
|
|
7496
|
+
return null;
|
|
7497
|
+
}
|
|
7498
|
+
const result = await evaluator.validate(this, message, state);
|
|
7499
|
+
if (result) {
|
|
7500
|
+
return evaluator;
|
|
7501
|
+
}
|
|
7502
|
+
return null;
|
|
7503
|
+
});
|
|
7504
|
+
const evaluators = (await Promise.all(evaluatorPromises)).filter(Boolean);
|
|
7739
7505
|
if (evaluators.length === 0) {
|
|
7740
7506
|
return [];
|
|
7741
7507
|
}
|
|
@@ -7743,14 +7509,7 @@ var AgentRuntime = class {
|
|
|
7743
7509
|
await Promise.all(
|
|
7744
7510
|
evaluators.map(async (evaluator) => {
|
|
7745
7511
|
if (evaluator.handler) {
|
|
7746
|
-
await evaluator.handler(
|
|
7747
|
-
this,
|
|
7748
|
-
message,
|
|
7749
|
-
state,
|
|
7750
|
-
{},
|
|
7751
|
-
callback,
|
|
7752
|
-
responses
|
|
7753
|
-
);
|
|
7512
|
+
await evaluator.handler(this, message, state, {}, callback, responses);
|
|
7754
7513
|
this.adapter.log({
|
|
7755
7514
|
entityId: message.entityId,
|
|
7756
7515
|
roomId: message.roomId,
|
|
@@ -7767,30 +7526,6 @@ var AgentRuntime = class {
|
|
|
7767
7526
|
);
|
|
7768
7527
|
return evaluators;
|
|
7769
7528
|
}
|
|
7770
|
-
async ensureParticipantInRoom(entityId, roomId) {
|
|
7771
|
-
const entity = await this.adapter.getEntityById(entityId);
|
|
7772
|
-
if (!entity) {
|
|
7773
|
-
throw new Error(`User ${entityId} not found`);
|
|
7774
|
-
}
|
|
7775
|
-
const participants = await this.adapter.getParticipantsForRoom(roomId);
|
|
7776
|
-
if (!participants.includes(entityId)) {
|
|
7777
|
-
const added = await this.adapter.addParticipant(entityId, roomId);
|
|
7778
|
-
if (!added) {
|
|
7779
|
-
throw new Error(
|
|
7780
|
-
`Failed to add participant ${entityId} to room ${roomId}`
|
|
7781
|
-
);
|
|
7782
|
-
}
|
|
7783
|
-
if (entityId === this.agentId) {
|
|
7784
|
-
this.runtimeLogger.log(
|
|
7785
|
-
`Agent ${this.character.name} linked to room ${roomId} successfully.`
|
|
7786
|
-
);
|
|
7787
|
-
} else {
|
|
7788
|
-
this.runtimeLogger.log(
|
|
7789
|
-
`User ${entityId} linked to room ${roomId} successfully.`
|
|
7790
|
-
);
|
|
7791
|
-
}
|
|
7792
|
-
}
|
|
7793
|
-
}
|
|
7794
7529
|
async ensureConnection({
|
|
7795
7530
|
entityId,
|
|
7796
7531
|
roomId,
|
|
@@ -7808,57 +7543,142 @@ var AgentRuntime = class {
|
|
|
7808
7543
|
if (!worldId && serverId) {
|
|
7809
7544
|
worldId = createUniqueUuid(this, serverId);
|
|
7810
7545
|
}
|
|
7811
|
-
const names4 = [name, userName];
|
|
7546
|
+
const names4 = [name, userName].filter(Boolean);
|
|
7812
7547
|
const metadata = {
|
|
7813
7548
|
[source]: {
|
|
7814
7549
|
name,
|
|
7815
7550
|
userName
|
|
7816
7551
|
}
|
|
7817
7552
|
};
|
|
7818
|
-
const entity = await this.adapter.getEntityById(entityId);
|
|
7819
|
-
if (!entity) {
|
|
7820
|
-
await this.adapter.createEntity({
|
|
7821
|
-
id: entityId,
|
|
7822
|
-
names: names4,
|
|
7823
|
-
metadata,
|
|
7824
|
-
agentId: this.agentId
|
|
7825
|
-
});
|
|
7826
|
-
}
|
|
7827
|
-
if (worldId) {
|
|
7828
|
-
await this.ensureWorldExists({
|
|
7829
|
-
id: worldId,
|
|
7830
|
-
name: serverId ? `World for server ${serverId}` : `World for room ${roomId}`,
|
|
7831
|
-
agentId: this.agentId,
|
|
7832
|
-
serverId: serverId || "default",
|
|
7833
|
-
metadata
|
|
7834
|
-
});
|
|
7835
|
-
}
|
|
7836
|
-
await this.ensureRoomExists({
|
|
7837
|
-
id: roomId,
|
|
7838
|
-
source,
|
|
7839
|
-
type,
|
|
7840
|
-
channelId,
|
|
7841
|
-
serverId,
|
|
7842
|
-
worldId
|
|
7843
|
-
});
|
|
7844
7553
|
try {
|
|
7845
|
-
await this.
|
|
7554
|
+
let entity = await this.adapter.getEntityById(entityId);
|
|
7555
|
+
if (!entity) {
|
|
7556
|
+
try {
|
|
7557
|
+
const success = await this.adapter.createEntity({
|
|
7558
|
+
id: entityId,
|
|
7559
|
+
names: names4,
|
|
7560
|
+
metadata,
|
|
7561
|
+
agentId: this.agentId
|
|
7562
|
+
});
|
|
7563
|
+
if (success) {
|
|
7564
|
+
this.runtimeLogger.debug(
|
|
7565
|
+
`Created new entity ${entityId} for user ${name || userName || "unknown"}`
|
|
7566
|
+
);
|
|
7567
|
+
} else {
|
|
7568
|
+
throw new Error(`Failed to create entity ${entityId}`);
|
|
7569
|
+
}
|
|
7570
|
+
} catch (error) {
|
|
7571
|
+
if (error.message?.includes("duplicate key") || error.code === "23505") {
|
|
7572
|
+
this.runtimeLogger.debug(
|
|
7573
|
+
`Entity ${entityId} exists in database but not for this agent. This is normal in multi-agent setups.`
|
|
7574
|
+
);
|
|
7575
|
+
} else {
|
|
7576
|
+
throw error;
|
|
7577
|
+
}
|
|
7578
|
+
}
|
|
7579
|
+
} else {
|
|
7580
|
+
await this.adapter.updateEntity({
|
|
7581
|
+
id: entityId,
|
|
7582
|
+
names: [.../* @__PURE__ */ new Set([...entity.names || [], ...names4])].filter(Boolean),
|
|
7583
|
+
metadata: {
|
|
7584
|
+
...entity.metadata,
|
|
7585
|
+
[source]: {
|
|
7586
|
+
...entity.metadata?.[source],
|
|
7587
|
+
name,
|
|
7588
|
+
userName
|
|
7589
|
+
}
|
|
7590
|
+
},
|
|
7591
|
+
agentId: this.agentId
|
|
7592
|
+
});
|
|
7593
|
+
}
|
|
7594
|
+
if (worldId) {
|
|
7595
|
+
await this.ensureWorldExists({
|
|
7596
|
+
id: worldId,
|
|
7597
|
+
name: serverId ? `World for server ${serverId}` : `World for room ${roomId}`,
|
|
7598
|
+
agentId: this.agentId,
|
|
7599
|
+
serverId: serverId || "default",
|
|
7600
|
+
metadata
|
|
7601
|
+
});
|
|
7602
|
+
}
|
|
7603
|
+
await this.ensureRoomExists({
|
|
7604
|
+
id: roomId,
|
|
7605
|
+
name,
|
|
7606
|
+
source,
|
|
7607
|
+
type,
|
|
7608
|
+
channelId,
|
|
7609
|
+
serverId,
|
|
7610
|
+
worldId
|
|
7611
|
+
});
|
|
7612
|
+
try {
|
|
7613
|
+
await this.ensureParticipantInRoom(entityId, roomId);
|
|
7614
|
+
} catch (error) {
|
|
7615
|
+
if (error.message?.includes("not found")) {
|
|
7616
|
+
const added = await this.adapter.addParticipant(entityId, roomId);
|
|
7617
|
+
if (!added) {
|
|
7618
|
+
throw new Error(`Failed to add participant ${entityId} to room ${roomId}`);
|
|
7619
|
+
}
|
|
7620
|
+
this.runtimeLogger.debug(`Added participant ${entityId} to room ${roomId} directly`);
|
|
7621
|
+
} else {
|
|
7622
|
+
throw error;
|
|
7623
|
+
}
|
|
7624
|
+
}
|
|
7846
7625
|
await this.ensureParticipantInRoom(this.agentId, roomId);
|
|
7626
|
+
this.runtimeLogger.debug(
|
|
7627
|
+
`Success: Successfully connected entity ${entityId} in room ${roomId}`
|
|
7628
|
+
);
|
|
7847
7629
|
} catch (error) {
|
|
7848
7630
|
this.runtimeLogger.error(
|
|
7849
|
-
`Failed to
|
|
7631
|
+
`Failed to ensure connection: ${error instanceof Error ? error.message : String(error)}`
|
|
7850
7632
|
);
|
|
7851
7633
|
throw error;
|
|
7852
7634
|
}
|
|
7853
7635
|
}
|
|
7636
|
+
/**
|
|
7637
|
+
* Ensures a participant is added to a room, checking that the entity exists first
|
|
7638
|
+
*/
|
|
7639
|
+
async ensureParticipantInRoom(entityId, roomId) {
|
|
7640
|
+
const entity = await this.adapter.getEntityById(entityId);
|
|
7641
|
+
if (!entity && entityId !== this.agentId) {
|
|
7642
|
+
this.runtimeLogger.warn(
|
|
7643
|
+
`Entity ${entityId} not directly accessible to agent ${this.agentId}. Will attempt to add as participant anyway.`
|
|
7644
|
+
);
|
|
7645
|
+
} else if (!entity) {
|
|
7646
|
+
throw new Error(`User ${entityId} not found`);
|
|
7647
|
+
}
|
|
7648
|
+
const participants = await this.adapter.getParticipantsForRoom(roomId);
|
|
7649
|
+
if (!participants.includes(entityId)) {
|
|
7650
|
+
const added = await this.adapter.addParticipant(entityId, roomId);
|
|
7651
|
+
if (!added) {
|
|
7652
|
+
throw new Error(`Failed to add participant ${entityId} to room ${roomId}`);
|
|
7653
|
+
}
|
|
7654
|
+
if (entityId === this.agentId) {
|
|
7655
|
+
this.runtimeLogger.debug(
|
|
7656
|
+
`Agent ${this.character.name} linked to room ${roomId} successfully.`
|
|
7657
|
+
);
|
|
7658
|
+
} else {
|
|
7659
|
+
this.runtimeLogger.debug(`User ${entityId} linked to room ${roomId} successfully.`);
|
|
7660
|
+
}
|
|
7661
|
+
}
|
|
7662
|
+
}
|
|
7663
|
+
async removeParticipant(entityId, roomId) {
|
|
7664
|
+
return await this.adapter.removeParticipant(entityId, roomId);
|
|
7665
|
+
}
|
|
7666
|
+
async getParticipantsForEntity(entityId) {
|
|
7667
|
+
return await this.adapter.getParticipantsForEntity(entityId);
|
|
7668
|
+
}
|
|
7669
|
+
async getParticipantsForRoom(roomId) {
|
|
7670
|
+
return await this.adapter.getParticipantsForRoom(roomId);
|
|
7671
|
+
}
|
|
7672
|
+
async addParticipant(entityId, roomId) {
|
|
7673
|
+
return await this.adapter.addParticipant(entityId, roomId);
|
|
7674
|
+
}
|
|
7854
7675
|
/**
|
|
7855
7676
|
* Ensure the existence of a world.
|
|
7856
7677
|
*/
|
|
7857
7678
|
async ensureWorldExists({ id, name, serverId, metadata }) {
|
|
7858
|
-
console.trace("ensureWorldExists");
|
|
7859
7679
|
const world = await this.getWorld(id);
|
|
7860
7680
|
if (!world) {
|
|
7861
|
-
this.runtimeLogger.
|
|
7681
|
+
this.runtimeLogger.debug("Creating world:", {
|
|
7862
7682
|
id,
|
|
7863
7683
|
name,
|
|
7864
7684
|
serverId,
|
|
@@ -7871,7 +7691,7 @@ var AgentRuntime = class {
|
|
|
7871
7691
|
serverId: serverId || "default",
|
|
7872
7692
|
metadata
|
|
7873
7693
|
});
|
|
7874
|
-
this.runtimeLogger.
|
|
7694
|
+
this.runtimeLogger.debug(`World ${id} created successfully.`);
|
|
7875
7695
|
}
|
|
7876
7696
|
}
|
|
7877
7697
|
/**
|
|
@@ -7881,15 +7701,7 @@ var AgentRuntime = class {
|
|
|
7881
7701
|
* @returns The room ID of the room between the agent and the user.
|
|
7882
7702
|
* @throws An error if the room cannot be created.
|
|
7883
7703
|
*/
|
|
7884
|
-
async ensureRoomExists({
|
|
7885
|
-
id,
|
|
7886
|
-
name,
|
|
7887
|
-
source,
|
|
7888
|
-
type,
|
|
7889
|
-
channelId,
|
|
7890
|
-
serverId,
|
|
7891
|
-
worldId
|
|
7892
|
-
}) {
|
|
7704
|
+
async ensureRoomExists({ id, name, source, type, channelId, serverId, worldId }) {
|
|
7893
7705
|
const room = await this.adapter.getRoom(id);
|
|
7894
7706
|
if (!room) {
|
|
7895
7707
|
await this.adapter.createRoom({
|
|
@@ -7902,7 +7714,7 @@ var AgentRuntime = class {
|
|
|
7902
7714
|
serverId,
|
|
7903
7715
|
worldId
|
|
7904
7716
|
});
|
|
7905
|
-
this.runtimeLogger.
|
|
7717
|
+
this.runtimeLogger.debug(`Room ${id} created successfully.`);
|
|
7906
7718
|
}
|
|
7907
7719
|
}
|
|
7908
7720
|
/**
|
|
@@ -7923,9 +7735,7 @@ var AgentRuntime = class {
|
|
|
7923
7735
|
if (filterList && filterList.length > 0) {
|
|
7924
7736
|
filterList.forEach((name) => providerNames.add(name));
|
|
7925
7737
|
} else {
|
|
7926
|
-
this.providers.filter(
|
|
7927
|
-
(p) => !p.private && !p.dynamic && !existingProviderNames.includes(p.name)
|
|
7928
|
-
).forEach((p) => providerNames.add(p.name));
|
|
7738
|
+
this.providers.filter((p) => !p.private && !p.dynamic && !existingProviderNames.includes(p.name)).forEach((p) => providerNames.add(p.name));
|
|
7929
7739
|
}
|
|
7930
7740
|
if (includeList && includeList.length > 0) {
|
|
7931
7741
|
includeList.forEach((name) => providerNames.add(name));
|
|
@@ -7938,9 +7748,7 @@ var AgentRuntime = class {
|
|
|
7938
7748
|
const start = Date.now();
|
|
7939
7749
|
const result = await provider.get(this, message, cachedState);
|
|
7940
7750
|
const duration = Date.now() - start;
|
|
7941
|
-
this.runtimeLogger.
|
|
7942
|
-
`${provider.name} Provider took ${duration}ms to respond`
|
|
7943
|
-
);
|
|
7751
|
+
this.runtimeLogger.debug(`${provider.name} Provider took ${duration}ms to respond`);
|
|
7944
7752
|
return {
|
|
7945
7753
|
...result,
|
|
7946
7754
|
providerName: provider.name
|
|
@@ -7998,7 +7806,7 @@ ${newProvidersText}`;
|
|
|
7998
7806
|
if (!serviceType) {
|
|
7999
7807
|
return;
|
|
8000
7808
|
}
|
|
8001
|
-
this.runtimeLogger.
|
|
7809
|
+
this.runtimeLogger.debug(
|
|
8002
7810
|
`${this.character.name}(${this.agentId}) - Registering service:`,
|
|
8003
7811
|
serviceType
|
|
8004
7812
|
);
|
|
@@ -8010,7 +7818,7 @@ ${newProvidersText}`;
|
|
|
8010
7818
|
}
|
|
8011
7819
|
const serviceInstance = await service.start(this);
|
|
8012
7820
|
this.services.set(serviceType, serviceInstance);
|
|
8013
|
-
this.runtimeLogger.
|
|
7821
|
+
this.runtimeLogger.debug(
|
|
8014
7822
|
`${this.character.name}(${this.agentId}) - Service ${serviceType} registered successfully`
|
|
8015
7823
|
);
|
|
8016
7824
|
}
|
|
@@ -8043,10 +7851,7 @@ ${newProvidersText}`;
|
|
|
8043
7851
|
if (!model) {
|
|
8044
7852
|
throw new Error(`No handler found for delegate type: ${modelKey}`);
|
|
8045
7853
|
}
|
|
8046
|
-
this.runtimeLogger.debug(
|
|
8047
|
-
`[useModel] ${modelKey} input:`,
|
|
8048
|
-
JSON.stringify(params, null, 2)
|
|
8049
|
-
);
|
|
7854
|
+
this.runtimeLogger.debug(`[useModel] ${modelKey} input:`, JSON.stringify(params, null, 2));
|
|
8050
7855
|
let paramsWithRuntime;
|
|
8051
7856
|
if (params === null || params === void 0 || typeof params !== "object" || Array.isArray(params) || typeof Buffer !== "undefined" && Buffer.isBuffer(params)) {
|
|
8052
7857
|
paramsWithRuntime = params;
|
|
@@ -8059,9 +7864,7 @@ ${newProvidersText}`;
|
|
|
8059
7864
|
const startTime = performance.now();
|
|
8060
7865
|
const response = await model(this, paramsWithRuntime);
|
|
8061
7866
|
const elapsedTime = performance.now() - startTime;
|
|
8062
|
-
this.runtimeLogger.
|
|
8063
|
-
`[useModel] ${modelKey} completed in ${elapsedTime.toFixed(2)}ms`
|
|
8064
|
-
);
|
|
7867
|
+
this.runtimeLogger.debug(`[useModel] ${modelKey} completed in ${elapsedTime.toFixed(2)}ms`);
|
|
8065
7868
|
this.runtimeLogger.debug(
|
|
8066
7869
|
`[useModel] ${modelKey} output:`,
|
|
8067
7870
|
// if response is an array, should the first and last 5 items with a "..." in the middle, and a (x items) at the end
|
|
@@ -8121,9 +7924,7 @@ ${newProvidersText}`;
|
|
|
8121
7924
|
);
|
|
8122
7925
|
const embedding = await this.useModel(ModelType.TEXT_EMBEDDING, null);
|
|
8123
7926
|
if (!embedding || !embedding.length) {
|
|
8124
|
-
throw new Error(
|
|
8125
|
-
`[AgentRuntime][${this.character.name}] Invalid embedding received`
|
|
8126
|
-
);
|
|
7927
|
+
throw new Error(`[AgentRuntime][${this.character.name}] Invalid embedding received`);
|
|
8127
7928
|
}
|
|
8128
7929
|
this.runtimeLogger.debug(
|
|
8129
7930
|
`[AgentRuntime][${this.character.name}] Setting embedding dimension: ${embedding.length}`
|
|
@@ -8133,7 +7934,7 @@ ${newProvidersText}`;
|
|
|
8133
7934
|
`[AgentRuntime][${this.character.name}] Successfully set embedding dimension`
|
|
8134
7935
|
);
|
|
8135
7936
|
} catch (error) {
|
|
8136
|
-
this.runtimeLogger.
|
|
7937
|
+
this.runtimeLogger.debug(
|
|
8137
7938
|
`[AgentRuntime][${this.character.name}] Error in ensureEmbeddingDimension:`,
|
|
8138
7939
|
error
|
|
8139
7940
|
);
|
|
@@ -8189,18 +7990,16 @@ ${newProvidersText}`;
|
|
|
8189
7990
|
return await this.adapter.getEntitiesForRoom(roomId, includeComponents);
|
|
8190
7991
|
}
|
|
8191
7992
|
async createEntity(entity) {
|
|
7993
|
+
if (!entity.agentId) {
|
|
7994
|
+
entity.agentId = this.agentId;
|
|
7995
|
+
}
|
|
8192
7996
|
return await this.adapter.createEntity(entity);
|
|
8193
7997
|
}
|
|
8194
7998
|
async updateEntity(entity) {
|
|
8195
7999
|
await this.adapter.updateEntity(entity);
|
|
8196
8000
|
}
|
|
8197
8001
|
async getComponent(entityId, type, worldId, sourceEntityId) {
|
|
8198
|
-
return await this.adapter.getComponent(
|
|
8199
|
-
entityId,
|
|
8200
|
-
type,
|
|
8201
|
-
worldId,
|
|
8202
|
-
sourceEntityId
|
|
8203
|
-
);
|
|
8002
|
+
return await this.adapter.getComponent(entityId, type, worldId, sourceEntityId);
|
|
8204
8003
|
}
|
|
8205
8004
|
async getComponents(entityId, worldId, sourceEntityId) {
|
|
8206
8005
|
return await this.adapter.getComponents(entityId, worldId, sourceEntityId);
|
|
@@ -8256,6 +8055,9 @@ ${newProvidersText}`;
|
|
|
8256
8055
|
async createMemory(memory, tableName, unique) {
|
|
8257
8056
|
return await this.adapter.createMemory(memory, tableName, unique);
|
|
8258
8057
|
}
|
|
8058
|
+
async updateMemory(memory) {
|
|
8059
|
+
return await this.adapter.updateMemory(memory);
|
|
8060
|
+
}
|
|
8259
8061
|
async deleteMemory(memoryId) {
|
|
8260
8062
|
await this.adapter.deleteMemory(memoryId);
|
|
8261
8063
|
}
|
|
@@ -8286,15 +8088,7 @@ ${newProvidersText}`;
|
|
|
8286
8088
|
async getRoom(roomId) {
|
|
8287
8089
|
return await this.adapter.getRoom(roomId);
|
|
8288
8090
|
}
|
|
8289
|
-
async createRoom({
|
|
8290
|
-
id,
|
|
8291
|
-
name,
|
|
8292
|
-
source,
|
|
8293
|
-
type,
|
|
8294
|
-
channelId,
|
|
8295
|
-
serverId,
|
|
8296
|
-
worldId
|
|
8297
|
-
}) {
|
|
8091
|
+
async createRoom({ id, name, source, type, channelId, serverId, worldId }) {
|
|
8298
8092
|
return await this.adapter.createRoom({
|
|
8299
8093
|
id,
|
|
8300
8094
|
name,
|
|
@@ -8320,18 +8114,6 @@ ${newProvidersText}`;
|
|
|
8320
8114
|
async getRooms(worldId) {
|
|
8321
8115
|
return await this.adapter.getRooms(worldId);
|
|
8322
8116
|
}
|
|
8323
|
-
async addParticipant(entityId, roomId) {
|
|
8324
|
-
return await this.adapter.addParticipant(entityId, roomId);
|
|
8325
|
-
}
|
|
8326
|
-
async removeParticipant(entityId, roomId) {
|
|
8327
|
-
return await this.adapter.removeParticipant(entityId, roomId);
|
|
8328
|
-
}
|
|
8329
|
-
async getParticipantsForEntity(entityId) {
|
|
8330
|
-
return await this.adapter.getParticipantsForEntity(entityId);
|
|
8331
|
-
}
|
|
8332
|
-
async getParticipantsForRoom(roomId) {
|
|
8333
|
-
return await this.adapter.getParticipantsForRoom(roomId);
|
|
8334
|
-
}
|
|
8335
8117
|
async getParticipantUserState(roomId, entityId) {
|
|
8336
8118
|
return await this.adapter.getParticipantUserState(roomId, entityId);
|
|
8337
8119
|
}
|
|
@@ -8408,15 +8190,12 @@ export {
|
|
|
8408
8190
|
AgentStatus,
|
|
8409
8191
|
CacheKeyPrefix,
|
|
8410
8192
|
ChannelType,
|
|
8411
|
-
CharacterSchema,
|
|
8412
8193
|
DatabaseAdapter,
|
|
8413
|
-
|
|
8194
|
+
EventType,
|
|
8414
8195
|
KnowledgeScope,
|
|
8415
8196
|
MemoryType,
|
|
8416
|
-
MessageExampleSchema,
|
|
8417
8197
|
ModelType,
|
|
8418
8198
|
PlatformPrefix,
|
|
8419
|
-
PluginSchema,
|
|
8420
8199
|
Role,
|
|
8421
8200
|
SOCKET_MESSAGE_TYPE,
|
|
8422
8201
|
Semaphore,
|
|
@@ -8433,7 +8212,6 @@ export {
|
|
|
8433
8212
|
composePrompt,
|
|
8434
8213
|
composePromptFromState,
|
|
8435
8214
|
composeRandomUser,
|
|
8436
|
-
configureSettings,
|
|
8437
8215
|
createMessageMemory,
|
|
8438
8216
|
createServiceError,
|
|
8439
8217
|
createUniqueUuid,
|
|
@@ -8441,7 +8219,6 @@ export {
|
|
|
8441
8219
|
elizaLogger,
|
|
8442
8220
|
extractAttributes,
|
|
8443
8221
|
findEntityByName,
|
|
8444
|
-
findNearestEnvFile,
|
|
8445
8222
|
findWorldForOwner,
|
|
8446
8223
|
formatActionNames,
|
|
8447
8224
|
formatActions,
|
|
@@ -8451,7 +8228,6 @@ export {
|
|
|
8451
8228
|
formatTimestamp,
|
|
8452
8229
|
getBrowserService,
|
|
8453
8230
|
getEntityDetails,
|
|
8454
|
-
getEnvVariable,
|
|
8455
8231
|
getFileService,
|
|
8456
8232
|
getMemoryText,
|
|
8457
8233
|
getPdfService,
|
|
@@ -8460,7 +8236,6 @@ export {
|
|
|
8460
8236
|
getVideoService,
|
|
8461
8237
|
getWorldSettings2 as getWorldSettings,
|
|
8462
8238
|
handlePluginImporting,
|
|
8463
|
-
hasEnvVariable,
|
|
8464
8239
|
initializeOnboarding,
|
|
8465
8240
|
isCustomMetadata,
|
|
8466
8241
|
isDescriptionMetadata,
|
|
@@ -8480,7 +8255,6 @@ export {
|
|
|
8480
8255
|
postActionResponseFooter,
|
|
8481
8256
|
postCreationTemplate,
|
|
8482
8257
|
registerDynamicImport,
|
|
8483
|
-
settings,
|
|
8484
8258
|
shouldRespondTemplate,
|
|
8485
8259
|
splitChunks,
|
|
8486
8260
|
stringArrayFooter,
|
|
@@ -8489,6 +8263,5 @@ export {
|
|
|
8489
8263
|
truncateToCompleteSentence,
|
|
8490
8264
|
updateWorldSettings2 as updateWorldSettings,
|
|
8491
8265
|
uuidSchema,
|
|
8492
|
-
validateCharacterConfig,
|
|
8493
8266
|
validateUuid
|
|
8494
8267
|
};
|