@elizaos/agent 2.0.0-alpha.435 → 2.0.0-alpha.436
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/package.json +4 -4
- package/packages/typescript/src/features/advanced-capabilities/providers/roles.d.ts.map +1 -1
- package/packages/typescript/src/features/advanced-capabilities/providers/roles.js +60 -9
- package/packages/typescript/src/services/message.d.ts +1 -1
- package/packages/typescript/src/services/message.d.ts.map +1 -1
- package/packages/typescript/src/services/message.js +2 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/agent",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.436",
|
|
4
4
|
"description": "Standalone elizaOS-based agent and backend server package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -467,7 +467,7 @@
|
|
|
467
467
|
"@elizaos/app-steward": "^0.0.0",
|
|
468
468
|
"@elizaos/app-task-coordinator": "^0.0.0",
|
|
469
469
|
"@elizaos/app-training": "^0.0.1",
|
|
470
|
-
"@elizaos/core": "^2.0.0-alpha.
|
|
470
|
+
"@elizaos/core": "^2.0.0-alpha.436",
|
|
471
471
|
"@elizaos/plugin-agent-orchestrator": "^0.6.2-alpha.0",
|
|
472
472
|
"@elizaos/plugin-browser-bridge": "^0.1.0",
|
|
473
473
|
"@elizaos/plugin-local-embedding": "^2.0.0-alpha.12",
|
|
@@ -476,8 +476,8 @@
|
|
|
476
476
|
"@elizaos/plugin-solana": "^2.0.0-alpha.6",
|
|
477
477
|
"@elizaos/plugin-sql": "^2.0.0-alpha.19",
|
|
478
478
|
"@elizaos/plugin-wechat": "^0.1.0",
|
|
479
|
-
"@elizaos/shared": "^2.0.0-alpha.
|
|
480
|
-
"@elizaos/skills": "^2.0.0-alpha.
|
|
479
|
+
"@elizaos/shared": "^2.0.0-alpha.436",
|
|
480
|
+
"@elizaos/skills": "^2.0.0-alpha.436",
|
|
481
481
|
"@hapi/boom": "^10.0.1",
|
|
482
482
|
"@noble/curves": "^2.0.1",
|
|
483
483
|
"@solana/web3.js": "^1.98.4",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../../../../../../../typescript/src/features/advanced-capabilities/providers/roles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../../../../../../../typescript/src/features/advanced-capabilities/providers/roles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAKX,QAAQ,EAIR,MAAM,yBAAyB,CAAC;AAsEjC;;;;;;;;;;GAUG;AACH;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,QAwM1B,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -3,6 +3,59 @@ import { logger } from "../../../logger.js";
|
|
|
3
3
|
import { ChannelType } from "../../../types/index.js";
|
|
4
4
|
// Get text content from centralized specs
|
|
5
5
|
const spec = requireProviderSpec("ROLES");
|
|
6
|
+
function isIdentityFields(value) {
|
|
7
|
+
return value !== null && typeof value === "object";
|
|
8
|
+
}
|
|
9
|
+
function getString(value) {
|
|
10
|
+
return typeof value === "string" && value.trim().length > 0
|
|
11
|
+
? value
|
|
12
|
+
: undefined;
|
|
13
|
+
}
|
|
14
|
+
function getMetadataIdentity(metadata) {
|
|
15
|
+
if (!metadata) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const sourceOrder = [
|
|
19
|
+
"default",
|
|
20
|
+
"discord",
|
|
21
|
+
"telegram",
|
|
22
|
+
"twitter",
|
|
23
|
+
"twitch",
|
|
24
|
+
"slack",
|
|
25
|
+
];
|
|
26
|
+
const candidates = [metadata];
|
|
27
|
+
for (const source of sourceOrder) {
|
|
28
|
+
const sourceMetadata = metadata[source];
|
|
29
|
+
if (isIdentityFields(sourceMetadata)) {
|
|
30
|
+
candidates.push(sourceMetadata);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const value of Object.values(metadata)) {
|
|
34
|
+
if (isIdentityFields(value)) {
|
|
35
|
+
candidates.push(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const identity = {};
|
|
39
|
+
for (const candidate of candidates) {
|
|
40
|
+
identity.name ??= getString(candidate.name);
|
|
41
|
+
identity.username ??=
|
|
42
|
+
getString(candidate.username) ?? getString(candidate.userName);
|
|
43
|
+
if (identity.name && identity.username) {
|
|
44
|
+
return identity;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return identity;
|
|
48
|
+
}
|
|
49
|
+
function getRoleUser(entity) {
|
|
50
|
+
const names = entity?.names?.filter((name) => name.trim().length > 0) ?? [];
|
|
51
|
+
const metadataIdentity = getMetadataIdentity(entity?.metadata);
|
|
52
|
+
const name = metadataIdentity.name ?? names[0];
|
|
53
|
+
const username = metadataIdentity.username ?? names[0];
|
|
54
|
+
if (!name || !username || names.length === 0) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return { name, username, names };
|
|
58
|
+
}
|
|
6
59
|
/**
|
|
7
60
|
* Role provider that retrieves roles in the server based on the provided runtime, message, and state.
|
|
8
61
|
* * @type { Provider }
|
|
@@ -105,10 +158,8 @@ export const roleProvider = {
|
|
|
105
158
|
for (const entityId of entityIds) {
|
|
106
159
|
const userRole = roles[entityId];
|
|
107
160
|
const user = entityMap.get(entityId);
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
const names = user?.names;
|
|
111
|
-
if (!name || !username || !names) {
|
|
161
|
+
const roleUser = getRoleUser(user);
|
|
162
|
+
if (!roleUser) {
|
|
112
163
|
logger.warn({
|
|
113
164
|
src: "plugin:advanced-capabilities:provider:roles",
|
|
114
165
|
agentId: runtime.agentId,
|
|
@@ -116,20 +167,20 @@ export const roleProvider = {
|
|
|
116
167
|
}, "User has no name or username, skipping");
|
|
117
168
|
continue;
|
|
118
169
|
}
|
|
119
|
-
if (seenUsernames.has(username)) {
|
|
170
|
+
if (seenUsernames.has(roleUser.username)) {
|
|
120
171
|
continue;
|
|
121
172
|
}
|
|
122
|
-
seenUsernames.add(username);
|
|
173
|
+
seenUsernames.add(roleUser.username);
|
|
123
174
|
// Add to appropriate group
|
|
124
175
|
switch (userRole) {
|
|
125
176
|
case "OWNER":
|
|
126
|
-
owners.push(
|
|
177
|
+
owners.push(roleUser);
|
|
127
178
|
break;
|
|
128
179
|
case "ADMIN":
|
|
129
|
-
admins.push(
|
|
180
|
+
admins.push(roleUser);
|
|
130
181
|
break;
|
|
131
182
|
default:
|
|
132
|
-
members.push(
|
|
183
|
+
members.push(roleUser);
|
|
133
184
|
break;
|
|
134
185
|
}
|
|
135
186
|
}
|
|
@@ -57,7 +57,7 @@ export declare function findOwnedActionCorrectionFromMetadata(runtime: Pick<IAge
|
|
|
57
57
|
*/
|
|
58
58
|
export declare function shouldEmitPlannerPreamble(runtime: IAgentRuntime, responseContent: Pick<Content, "text" | "actions"> | null | undefined): boolean;
|
|
59
59
|
export declare function stripReplyWhenActionOwnsTurn(runtime: Pick<IAgentRuntime, "actions" | "logger">, actions: readonly string[] | null | undefined): string[];
|
|
60
|
-
export declare function wrapSingleTurnVisibleCallback(
|
|
60
|
+
export declare function wrapSingleTurnVisibleCallback(_runtime: Pick<IAgentRuntime, "agentId" | "logger">, _message: Pick<Memory, "id" | "roomId">, callback?: HandlerCallback): HandlerCallback | undefined;
|
|
61
61
|
export declare function withActionResultsForPrompt(state: State, actionResults: ActionResult[]): State;
|
|
62
62
|
/**
|
|
63
63
|
* Default implementation of the MessageService interface.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../../../typescript/src/services/message.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EACX,MAAM,EAEN,YAAY,EACZ,eAAe,EAEf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,IA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EACZ,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;CA4ChB"}
|
|
@@ -1638,132 +1638,8 @@ export function stripReplyWhenActionOwnsTurn(runtime, actions) {
|
|
|
1638
1638
|
}, "Dropped passive actions because another selected action already owns the turn");
|
|
1639
1639
|
return filtered.length > 0 ? filtered : ["REPLY"];
|
|
1640
1640
|
}
|
|
1641
|
-
function
|
|
1642
|
-
|
|
1643
|
-
return "";
|
|
1644
|
-
}
|
|
1645
|
-
const text = typeof content.text === "string" ? content.text.trim() : "";
|
|
1646
|
-
if (!text) {
|
|
1647
|
-
return "";
|
|
1648
|
-
}
|
|
1649
|
-
return text.replace(/\s+/g, " ").slice(0, 200);
|
|
1650
|
-
}
|
|
1651
|
-
function callbackHasVisibleOutput(content) {
|
|
1652
|
-
if (!content || typeof content !== "object") {
|
|
1653
|
-
return false;
|
|
1654
|
-
}
|
|
1655
|
-
if (typeof content.text === "string" && content.text.trim().length > 0) {
|
|
1656
|
-
return true;
|
|
1657
|
-
}
|
|
1658
|
-
return Array.isArray(content.attachments) && content.attachments.length > 0;
|
|
1659
|
-
}
|
|
1660
|
-
function summarizeAttachmentKeyPart(url) {
|
|
1661
|
-
const trimmed = url.trim();
|
|
1662
|
-
if (trimmed.length <= 256) {
|
|
1663
|
-
return trimmed;
|
|
1664
|
-
}
|
|
1665
|
-
return `${trimmed.slice(0, 128)}...(${trimmed.length})`;
|
|
1666
|
-
}
|
|
1667
|
-
function callbackDeliveryKey(content) {
|
|
1668
|
-
if (!content || typeof content !== "object") {
|
|
1669
|
-
return "";
|
|
1670
|
-
}
|
|
1671
|
-
const text = typeof content.text === "string"
|
|
1672
|
-
? content.text.replace(/\s+/g, " ").trim()
|
|
1673
|
-
: "";
|
|
1674
|
-
const attachmentKeys = Array.isArray(content.attachments)
|
|
1675
|
-
? content.attachments
|
|
1676
|
-
.map((attachment) => {
|
|
1677
|
-
if (!attachment || typeof attachment !== "object") {
|
|
1678
|
-
return "";
|
|
1679
|
-
}
|
|
1680
|
-
const url = typeof attachment.url === "string"
|
|
1681
|
-
? summarizeAttachmentKeyPart(attachment.url)
|
|
1682
|
-
: "";
|
|
1683
|
-
const title = typeof attachment.title === "string" ? attachment.title.trim() : "";
|
|
1684
|
-
const contentType = typeof attachment.contentType === "string"
|
|
1685
|
-
? attachment.contentType
|
|
1686
|
-
: "";
|
|
1687
|
-
if (!url && !title && !contentType) {
|
|
1688
|
-
return "";
|
|
1689
|
-
}
|
|
1690
|
-
return `${contentType}:${title}:${url}`;
|
|
1691
|
-
})
|
|
1692
|
-
.filter((key) => key.length > 0)
|
|
1693
|
-
.sort()
|
|
1694
|
-
: [];
|
|
1695
|
-
if (!text && attachmentKeys.length === 0) {
|
|
1696
|
-
return "";
|
|
1697
|
-
}
|
|
1698
|
-
return JSON.stringify({
|
|
1699
|
-
text,
|
|
1700
|
-
attachments: attachmentKeys,
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
export function wrapSingleTurnVisibleCallback(runtime, message, callback) {
|
|
1704
|
-
if (!callback) {
|
|
1705
|
-
return undefined;
|
|
1706
|
-
}
|
|
1707
|
-
let visibleCallbackCount = 0;
|
|
1708
|
-
let firstVisibleCallbackPreview = "";
|
|
1709
|
-
const deliveredCallbackKeys = new Set();
|
|
1710
|
-
return async (content, actionName) => {
|
|
1711
|
-
const deliveryKey = callbackDeliveryKey(content);
|
|
1712
|
-
const preview = callbackTextPreview(content);
|
|
1713
|
-
const hasVisibleOutput = callbackHasVisibleOutput(content);
|
|
1714
|
-
if (deliveryKey && deliveredCallbackKeys.has(deliveryKey)) {
|
|
1715
|
-
runtime.logger.warn({
|
|
1716
|
-
src: "service:message",
|
|
1717
|
-
agentId: runtime.agentId,
|
|
1718
|
-
messageId: message.id,
|
|
1719
|
-
roomId: message.roomId,
|
|
1720
|
-
action: typeof content?.action === "string"
|
|
1721
|
-
? String(content.action)
|
|
1722
|
-
: actionName,
|
|
1723
|
-
source: typeof content.source === "string" ? content.source : undefined,
|
|
1724
|
-
preview: preview ||
|
|
1725
|
-
(Array.isArray(content.attachments) &&
|
|
1726
|
-
content.attachments.length > 0
|
|
1727
|
-
? `[attachments:${content.attachments.length}]`
|
|
1728
|
-
: ""),
|
|
1729
|
-
}, "Suppressing duplicate visible callback reply emitted for a single turn");
|
|
1730
|
-
return [];
|
|
1731
|
-
}
|
|
1732
|
-
if (hasVisibleOutput && visibleCallbackCount >= 1) {
|
|
1733
|
-
runtime.logger.warn({
|
|
1734
|
-
src: "service:message",
|
|
1735
|
-
agentId: runtime.agentId,
|
|
1736
|
-
messageId: message.id,
|
|
1737
|
-
roomId: message.roomId,
|
|
1738
|
-
callbackCount: visibleCallbackCount + 1,
|
|
1739
|
-
action: typeof content?.action === "string"
|
|
1740
|
-
? String(content.action)
|
|
1741
|
-
: actionName,
|
|
1742
|
-
source: typeof content.source === "string" ? content.source : undefined,
|
|
1743
|
-
firstPreview: firstVisibleCallbackPreview,
|
|
1744
|
-
currentPreview: preview ||
|
|
1745
|
-
(Array.isArray(content.attachments) &&
|
|
1746
|
-
content.attachments.length > 0
|
|
1747
|
-
? `[attachments:${content.attachments.length}]`
|
|
1748
|
-
: ""),
|
|
1749
|
-
}, "Suppressing additional visible callback reply emitted for a single turn");
|
|
1750
|
-
return [];
|
|
1751
|
-
}
|
|
1752
|
-
if (deliveryKey) {
|
|
1753
|
-
deliveredCallbackKeys.add(deliveryKey);
|
|
1754
|
-
}
|
|
1755
|
-
if (hasVisibleOutput) {
|
|
1756
|
-
visibleCallbackCount += 1;
|
|
1757
|
-
firstVisibleCallbackPreview =
|
|
1758
|
-
preview ||
|
|
1759
|
-
(Array.isArray(content.attachments) && content.attachments.length > 0
|
|
1760
|
-
? `[attachments:${content.attachments.length}]`
|
|
1761
|
-
: "");
|
|
1762
|
-
}
|
|
1763
|
-
return actionName === undefined
|
|
1764
|
-
? callback(content)
|
|
1765
|
-
: callback(content, actionName);
|
|
1766
|
-
};
|
|
1641
|
+
export function wrapSingleTurnVisibleCallback(_runtime, _message, callback) {
|
|
1642
|
+
return callback;
|
|
1767
1643
|
}
|
|
1768
1644
|
function getLatestVisibleReplyText(responseContent, actionResults) {
|
|
1769
1645
|
for (let index = actionResults.length - 1; index >= 0; index--) {
|