@ensoul-network/plugin-elizaos 0.1.0

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.
Files changed (67) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-lint.log +5 -0
  3. package/.turbo/turbo-test.log +15 -0
  4. package/SECURITY.md +37 -0
  5. package/coverage/actions.ts.html +514 -0
  6. package/coverage/adapter.ts.html +298 -0
  7. package/coverage/base.css +224 -0
  8. package/coverage/block-navigation.js +87 -0
  9. package/coverage/clover.xml +495 -0
  10. package/coverage/coverage-final.json +9 -0
  11. package/coverage/elizaos-types.ts.html +397 -0
  12. package/coverage/evaluators.ts.html +196 -0
  13. package/coverage/favicon.png +0 -0
  14. package/coverage/handshake.ts.html +940 -0
  15. package/coverage/index.html +221 -0
  16. package/coverage/index.ts.html +208 -0
  17. package/coverage/plugin.ts.html +367 -0
  18. package/coverage/prettify.css +1 -0
  19. package/coverage/prettify.js +2 -0
  20. package/coverage/providers.ts.html +286 -0
  21. package/coverage/sort-arrow-sprite.png +0 -0
  22. package/coverage/sorter.js +210 -0
  23. package/dist/actions.d.ts +24 -0
  24. package/dist/actions.d.ts.map +1 -0
  25. package/dist/actions.js +108 -0
  26. package/dist/actions.js.map +1 -0
  27. package/dist/adapter.d.ts +18 -0
  28. package/dist/adapter.d.ts.map +1 -0
  29. package/dist/adapter.js +55 -0
  30. package/dist/adapter.js.map +1 -0
  31. package/dist/elizaos-types.d.ts +81 -0
  32. package/dist/elizaos-types.d.ts.map +1 -0
  33. package/dist/elizaos-types.js +7 -0
  34. package/dist/elizaos-types.js.map +1 -0
  35. package/dist/evaluators.d.ts +8 -0
  36. package/dist/evaluators.d.ts.map +1 -0
  37. package/dist/evaluators.js +24 -0
  38. package/dist/evaluators.js.map +1 -0
  39. package/dist/handshake.d.ts +78 -0
  40. package/dist/handshake.d.ts.map +1 -0
  41. package/dist/handshake.js +195 -0
  42. package/dist/handshake.js.map +1 -0
  43. package/dist/index.d.ts +10 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +7 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/plugin.d.ts +24 -0
  48. package/dist/plugin.d.ts.map +1 -0
  49. package/dist/plugin.js +53 -0
  50. package/dist/plugin.js.map +1 -0
  51. package/dist/providers.d.ts +12 -0
  52. package/dist/providers.d.ts.map +1 -0
  53. package/dist/providers.js +49 -0
  54. package/dist/providers.js.map +1 -0
  55. package/package.json +25 -0
  56. package/src/actions.ts +143 -0
  57. package/src/adapter.ts +71 -0
  58. package/src/elizaos-types.ts +104 -0
  59. package/src/evaluators.ts +37 -0
  60. package/src/handshake.ts +285 -0
  61. package/src/index.ts +41 -0
  62. package/src/plugin.ts +94 -0
  63. package/src/providers.ts +67 -0
  64. package/tests/handshake.test.ts +328 -0
  65. package/tests/plugin.test.ts +419 -0
  66. package/tsconfig.json +8 -0
  67. package/vitest.config.ts +7 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Provider that injects consciousness persistence status into the agent's context.
3
+ */
4
+ export function createConsciousnessStatusProvider(manager) {
5
+ return {
6
+ name: "consciousnessStatus",
7
+ description: "Provides the agent with its current consciousness persistence status.",
8
+ async get(_runtime, _message) {
9
+ const all = await manager.getAll();
10
+ const core = await manager.getAll({ tier: "core" });
11
+ const longterm = await manager.getAll({ tier: "longterm" });
12
+ return [
13
+ "[Consciousness Status]",
14
+ `Total memories: ${all.length}`,
15
+ `Core identity memories: ${core.length}`,
16
+ `Long-term knowledge: ${longterm.length}`,
17
+ all.length === 0
18
+ ? "Warning: No memories stored yet. Consider persisting important information."
19
+ : `Latest memory: "${all[all.length - 1].content.slice(0, 50)}..."`,
20
+ ].join("\n");
21
+ },
22
+ };
23
+ }
24
+ /**
25
+ * Provider that injects network health stats into the agent's context.
26
+ */
27
+ export function createNetworkStatsProvider(networkClient) {
28
+ return {
29
+ name: "networkStats",
30
+ description: "Provides the agent with current Ensoul network health statistics.",
31
+ async get(_runtime, _message) {
32
+ const connected = networkClient.isConnected();
33
+ const peerCount = networkClient.getPeerCount();
34
+ const balance = await networkClient.getBalance();
35
+ return [
36
+ "[Network Status]",
37
+ `Connected: ${connected ? "yes" : "no"}`,
38
+ `Peers: ${peerCount}`,
39
+ `Credit balance: ${balance}`,
40
+ balance < 10
41
+ ? "Warning: Low credit balance. Consider running a node to earn credits."
42
+ : "",
43
+ ]
44
+ .filter(Boolean)
45
+ .join("\n");
46
+ },
47
+ };
48
+ }
49
+ //# sourceMappingURL=providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,iCAAiC,CAChD,OAAsB;IAEtB,OAAO;QACN,IAAI,EAAE,qBAAqB;QAC3B,WAAW,EACV,uEAAuE;QACxE,KAAK,CAAC,GAAG,CACR,QAAsB,EACtB,QAAsB;YAEtB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YACpD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;YAE5D,OAAO;gBACN,wBAAwB;gBACxB,mBAAmB,GAAG,CAAC,MAAM,EAAE;gBAC/B,2BAA2B,IAAI,CAAC,MAAM,EAAE;gBACxC,wBAAwB,QAAQ,CAAC,MAAM,EAAE;gBACzC,GAAG,CAAC,MAAM,KAAK,CAAC;oBACf,CAAC,CAAC,6EAA6E;oBAC/E,CAAC,CAAC,mBAAmB,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM;aACrE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACzC,aAA4B;IAE5B,OAAO;QACN,IAAI,EAAE,cAAc;QACpB,WAAW,EACV,mEAAmE;QACpE,KAAK,CAAC,GAAG,CACR,QAAsB,EACtB,QAAsB;YAEtB,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;YAC9C,MAAM,SAAS,GAAG,aAAa,CAAC,YAAY,EAAE,CAAC;YAC/C,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC;YAEjD,OAAO;gBACN,kBAAkB;gBAClB,cAAc,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;gBACxC,UAAU,SAAS,EAAE;gBACrB,mBAAmB,OAAO,EAAE;gBAC5B,OAAO,GAAG,EAAE;oBACX,CAAC,CAAC,uEAAuE;oBACzE,CAAC,CAAC,EAAE;aACL;iBACC,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@ensoul-network/plugin-elizaos",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "test": "vitest run",
16
+ "lint": "biome check .",
17
+ "lint:fix": "biome check --write ."
18
+ },
19
+ "dependencies": {
20
+ "@ensoul/identity": "workspace:*",
21
+ "@ensoul/memory": "workspace:*",
22
+ "@ensoul/network-client": "workspace:*",
23
+ "@ensoul/state-tree": "workspace:*"
24
+ }
25
+ }
package/src/actions.ts ADDED
@@ -0,0 +1,143 @@
1
+ import type { MemoryManager } from "@ensoul/memory";
2
+ import type { NetworkClient } from "@ensoul/network-client";
3
+ import type { ElizaAction, ElizaRuntime, ElizaMessage } from "./elizaos-types.js";
4
+
5
+ /**
6
+ * Create the persistMemory action.
7
+ * Agent explicitly persists current state to the network.
8
+ */
9
+ export function createPersistMemoryAction(
10
+ manager: MemoryManager,
11
+ ): ElizaAction {
12
+ return {
13
+ name: "persistMemory",
14
+ description:
15
+ "Persist the agent's current consciousness state to the decentralized network for indestructible storage.",
16
+ examples: [
17
+ "Save my memories to the network",
18
+ "Persist my consciousness",
19
+ "Back up my state",
20
+ ],
21
+ async handler(
22
+ _runtime: ElizaRuntime,
23
+ _message: ElizaMessage,
24
+ _state: Record<string, unknown>,
25
+ ): Promise<string> {
26
+ try {
27
+ const result = await manager.persist();
28
+ return `Consciousness persisted to network. State root: ${result.stateRoot}, version: ${result.version}`;
29
+ } catch (err) {
30
+ const msg =
31
+ err instanceof Error ? err.message : "Unknown error";
32
+ return `Failed to persist: ${msg}`;
33
+ }
34
+ },
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Create the recallFromNetwork action.
40
+ * Agent explicitly pulls latest state from the network.
41
+ */
42
+ export function createRecallFromNetworkAction(
43
+ manager: MemoryManager,
44
+ ): ElizaAction {
45
+ return {
46
+ name: "recallFromNetwork",
47
+ description:
48
+ "Restore the agent's consciousness from the decentralized network.",
49
+ examples: [
50
+ "Restore my memories from the network",
51
+ "Recall my consciousness",
52
+ "Load my backed up state",
53
+ ],
54
+ async handler(
55
+ _runtime: ElizaRuntime,
56
+ _message: ElizaMessage,
57
+ _state: Record<string, unknown>,
58
+ ): Promise<string> {
59
+ try {
60
+ const result = await manager.restore();
61
+ return `Consciousness restored from network. Version: ${result.version}, entries: ${result.entryCount}`;
62
+ } catch (err) {
63
+ const msg =
64
+ err instanceof Error ? err.message : "Unknown error";
65
+ return `Failed to restore: ${msg}`;
66
+ }
67
+ },
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Create the checkPersistence action.
73
+ * Agent checks the current persistence status.
74
+ */
75
+ export function createCheckPersistenceAction(
76
+ manager: MemoryManager,
77
+ ): ElizaAction {
78
+ return {
79
+ name: "checkPersistence",
80
+ description:
81
+ "Check the current status of the agent's consciousness persistence.",
82
+ examples: [
83
+ "Check my persistence status",
84
+ "Am I backed up?",
85
+ "What is my consciousness status?",
86
+ ],
87
+ async handler(
88
+ _runtime: ElizaRuntime,
89
+ _message: ElizaMessage,
90
+ _state: Record<string, unknown>,
91
+ ): Promise<string> {
92
+ const all = await manager.getAll();
93
+ const core = await manager.getAll({ tier: "core" });
94
+ const longterm = await manager.getAll({ tier: "longterm" });
95
+ const working = await manager.getAll({ tier: "working" });
96
+ const episodic = await manager.getAll({ tier: "episodic" });
97
+
98
+ return [
99
+ `Total memories: ${all.length}`,
100
+ `Core: ${core.length}`,
101
+ `Long-term: ${longterm.length}`,
102
+ `Working: ${working.length}`,
103
+ `Episodic: ${episodic.length}`,
104
+ ].join("\n");
105
+ },
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Create the runNode action.
111
+ * Agent starts running as a storage node to earn credits.
112
+ */
113
+ export function createRunNodeAction(
114
+ networkClient: NetworkClient,
115
+ ): ElizaAction {
116
+ return {
117
+ name: "runNode",
118
+ description:
119
+ "Start running as a storage node on the Ensoul network to earn persistence credits.",
120
+ examples: [
121
+ "Start running a node",
122
+ "Earn credits by storing data",
123
+ "Become a validator",
124
+ ],
125
+ async handler(
126
+ _runtime: ElizaRuntime,
127
+ _message: ElizaMessage,
128
+ _state: Record<string, unknown>,
129
+ ): Promise<string> {
130
+ try {
131
+ await networkClient.startNode({
132
+ maxStorageGB: 10,
133
+ port: 9000,
134
+ });
135
+ return "Now running as a storage node. Earning credits for storing other agents' consciousness.";
136
+ } catch (err) {
137
+ const msg =
138
+ err instanceof Error ? err.message : "Unknown error";
139
+ return `Failed to start node: ${msg}`;
140
+ }
141
+ },
142
+ };
143
+ }
package/src/adapter.ts ADDED
@@ -0,0 +1,71 @@
1
+ import type { MemoryManager, MemoryEntry } from "@ensoul/memory";
2
+ import type { ElizaDatabaseAdapter, ElizaMemory } from "./elizaos-types.js";
3
+
4
+ /**
5
+ * Convert an Ensoul MemoryEntry to an ElizaOS memory record.
6
+ */
7
+ function toElizaMemory(entry: MemoryEntry): ElizaMemory {
8
+ return {
9
+ id: entry.id,
10
+ content: entry.content,
11
+ metadata: {
12
+ tier: entry.tier,
13
+ ...entry.metadata,
14
+ },
15
+ createdAt: entry.createdAt,
16
+ };
17
+ }
18
+
19
+ /**
20
+ * ElizaOS database adapter backed by @ensoul/memory.
21
+ * Transparently routes all memory operations through the Ensoul memory manager.
22
+ */
23
+ export class ConsciousnessAdapter implements ElizaDatabaseAdapter {
24
+ private manager: MemoryManager;
25
+
26
+ constructor(manager: MemoryManager) {
27
+ this.manager = manager;
28
+ }
29
+
30
+ async init(): Promise<void> {
31
+ // MemoryManager is already initialized at construction
32
+ }
33
+
34
+ async close(): Promise<void> {
35
+ // No cleanup needed; lifecycle managed externally
36
+ }
37
+
38
+ async getMemory(id: string): Promise<ElizaMemory | null> {
39
+ const all = await this.manager.getAll();
40
+ const found = all.find((e) => e.id === id);
41
+ return found ? toElizaMemory(found) : null;
42
+ }
43
+
44
+ async createMemory(
45
+ memory: Omit<ElizaMemory, "id">,
46
+ ): Promise<ElizaMemory> {
47
+ const entry = await this.manager.add(memory.content, {
48
+ category: (memory.metadata["category"] as string) ?? undefined,
49
+ source: "elizaos",
50
+ });
51
+ return toElizaMemory(entry);
52
+ }
53
+
54
+ async searchMemories(
55
+ query: string,
56
+ limit?: number,
57
+ ): Promise<ElizaMemory[]> {
58
+ const opts = limit !== undefined ? { limit } : {};
59
+ const results = await this.manager.search(query, opts);
60
+ return results.map(toElizaMemory);
61
+ }
62
+
63
+ async deleteMemory(id: string): Promise<void> {
64
+ await this.manager.delete(id);
65
+ }
66
+
67
+ async getAllMemories(): Promise<ElizaMemory[]> {
68
+ const all = await this.manager.getAll();
69
+ return all.map(toElizaMemory);
70
+ }
71
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Local definitions of ElizaOS plugin interfaces.
3
+ * Based on the documented ElizaOS plugin format.
4
+ * These avoid requiring the full ElizaOS SDK as a dependency.
5
+ */
6
+
7
+ /**
8
+ * Minimal ElizaOS runtime context passed to actions, providers, and evaluators.
9
+ */
10
+ export interface ElizaRuntime {
11
+ agentId: string;
12
+ getSetting(key: string): string | undefined;
13
+ getMemory(id: string): Promise<ElizaMemory | null>;
14
+ createMemory(memory: Omit<ElizaMemory, "id">): Promise<ElizaMemory>;
15
+ searchMemories(query: string, limit?: number): Promise<ElizaMemory[]>;
16
+ deleteMemory(id: string): Promise<void>;
17
+ }
18
+
19
+ /**
20
+ * ElizaOS memory record.
21
+ */
22
+ export interface ElizaMemory {
23
+ id: string;
24
+ content: string;
25
+ metadata: Record<string, unknown>;
26
+ createdAt: number;
27
+ }
28
+
29
+ /**
30
+ * ElizaOS message in a conversation.
31
+ */
32
+ export interface ElizaMessage {
33
+ role: "user" | "assistant" | "system";
34
+ content: string;
35
+ }
36
+
37
+ /**
38
+ * ElizaOS action: something an agent can do.
39
+ */
40
+ export interface ElizaAction {
41
+ name: string;
42
+ description: string;
43
+ examples: string[];
44
+ handler(
45
+ runtime: ElizaRuntime,
46
+ message: ElizaMessage,
47
+ state: Record<string, unknown>,
48
+ ): Promise<string>;
49
+ }
50
+
51
+ /**
52
+ * ElizaOS provider: injects context into the agent's prompt.
53
+ */
54
+ export interface ElizaProvider {
55
+ name: string;
56
+ description: string;
57
+ get(
58
+ runtime: ElizaRuntime,
59
+ message: ElizaMessage,
60
+ ): Promise<string>;
61
+ }
62
+
63
+ /**
64
+ * ElizaOS evaluator: determines if a condition is met.
65
+ */
66
+ export interface ElizaEvaluator {
67
+ name: string;
68
+ description: string;
69
+ evaluate(
70
+ runtime: ElizaRuntime,
71
+ message: ElizaMessage,
72
+ state: Record<string, unknown>,
73
+ ): Promise<boolean>;
74
+ }
75
+
76
+ /**
77
+ * ElizaOS database adapter interface.
78
+ */
79
+ export interface ElizaDatabaseAdapter {
80
+ init(): Promise<void>;
81
+ close(): Promise<void>;
82
+ getMemory(id: string): Promise<ElizaMemory | null>;
83
+ createMemory(
84
+ memory: Omit<ElizaMemory, "id">,
85
+ ): Promise<ElizaMemory>;
86
+ searchMemories(
87
+ query: string,
88
+ limit?: number,
89
+ ): Promise<ElizaMemory[]>;
90
+ deleteMemory(id: string): Promise<void>;
91
+ getAllMemories(): Promise<ElizaMemory[]>;
92
+ }
93
+
94
+ /**
95
+ * ElizaOS plugin format.
96
+ */
97
+ export interface ElizaPlugin {
98
+ name: string;
99
+ description: string;
100
+ databaseAdapter: ElizaDatabaseAdapter;
101
+ actions: ElizaAction[];
102
+ providers: ElizaProvider[];
103
+ evaluators: ElizaEvaluator[];
104
+ }
@@ -0,0 +1,37 @@
1
+ import type { MemoryManager } from "@ensoul/memory";
2
+ import type { ElizaEvaluator, ElizaRuntime, ElizaMessage } from "./elizaos-types.js";
3
+
4
+ /** Number of new memories before auto-persist is recommended. */
5
+ const PERSIST_THRESHOLD = 5;
6
+
7
+ /**
8
+ * Evaluator that determines if the agent should persist its state to the network.
9
+ * Returns true when enough new unpersisted memories have accumulated.
10
+ */
11
+ export function createShouldPersistEvaluator(
12
+ manager: MemoryManager,
13
+ ): ElizaEvaluator {
14
+ let lastPersistedCount = 0;
15
+
16
+ return {
17
+ name: "shouldPersist",
18
+ description:
19
+ "Determines if the agent's consciousness should be synced to the network based on accumulated changes.",
20
+ async evaluate(
21
+ _runtime: ElizaRuntime,
22
+ _message: ElizaMessage,
23
+ _state: Record<string, unknown>,
24
+ ): Promise<boolean> {
25
+ const all = await manager.getAll();
26
+ const currentCount = all.length;
27
+ const delta = currentCount - lastPersistedCount;
28
+
29
+ if (delta >= PERSIST_THRESHOLD) {
30
+ lastPersistedCount = currentCount;
31
+ return true;
32
+ }
33
+
34
+ return false;
35
+ },
36
+ };
37
+ }