Skip to content

Commit 8b9af19

Browse files
authored
Merge pull request #2 from JoeyKhd/develop
Develop
2 parents 9cb5762 + c8f1c08 commit 8b9af19

17 files changed

+592
-9
lines changed

agent/src/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,7 @@ export async function createAgent(
514514
cache: ICacheManager,
515515
token: string
516516
): Promise<AgentRuntime> {
517-
elizaLogger.success(
518-
elizaLogger.successesTitle,
519-
"Creating runtime for character",
520-
character.name
521-
);
517+
elizaLogger.log(`Creating runtime for character ${character.name}`);
522518

523519
nodePlugin ??= createNodePlugin();
524520

packages/adapter-sqlite/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,19 @@ export class SqliteDatabaseAdapter
215215
const content = JSON.stringify(memory.content);
216216
const createdAt = memory.createdAt ?? Date.now();
217217

218+
let embeddingValue: Float32Array = new Float32Array(384);
219+
// If embedding is not available, we just load an array with a length of 384
220+
if (memory?.embedding && memory?.embedding?.length > 0) {
221+
embeddingValue = new Float32Array(memory.embedding);
222+
}
223+
218224
// Insert the memory with the appropriate 'unique' value
219225
const sql = `INSERT OR REPLACE INTO memories (id, type, content, embedding, userId, roomId, agentId, \`unique\`, createdAt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
220226
this.db.prepare(sql).run(
221227
memory.id ?? v4(),
222228
tableName,
223229
content,
224-
new Float32Array(memory.embedding!), // Store as Float32Array
230+
embeddingValue,
225231
memory.userId,
226232
memory.roomId,
227233
memory.agentId,
@@ -707,4 +713,4 @@ export class SqliteDatabaseAdapter
707713
return false;
708714
}
709715
}
710-
}
716+
}

packages/core/src/runtime.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class AgentRuntime implements IAgentRuntime {
267267
this.ensureParticipantExists(this.agentId, this.agentId);
268268
});
269269

270-
elizaLogger.success("Agent ID", this.agentId);
270+
elizaLogger.success(`Agent ID: ${this.agentId}`);
271271

272272
this.fetch = (opts.fetch as typeof fetch) ?? this.fetch;
273273

packages/plugin-anyone/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
3+
!dist/**
4+
!package.json
5+
!readme.md
6+
!tsup.config.ts
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/plugin-anyone/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@elizaos/plugin-anyone",
3+
"version": "0.1.7-alpha.2",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "dist/index.d.ts",
7+
"dependencies": {
8+
"@anyone-protocol/anyone-client": "^0.4.3",
9+
"@elizaos/core": "workspace:*",
10+
"axios": "^1.7.9",
11+
"tsup": "8.3.5"
12+
},
13+
"scripts": {
14+
"build": "tsup --format esm --dts",
15+
"dev": "tsup --format esm --dts --watch",
16+
"lint": "eslint --fix --cache ."
17+
},
18+
"peerDependencies": {
19+
"whatwg-url": "7.1.0"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./startAnyone.ts";
2+
export * from "./stopAnyone.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import {
2+
ActionExample,
3+
HandlerCallback,
4+
IAgentRuntime,
5+
Memory,
6+
State,
7+
type Action,
8+
} from "@elizaos/core";
9+
import axios from "axios";
10+
import { AnyoneClientService } from "../services/AnyoneClientService";
11+
import { AnyoneProxyService } from "../services/AnyoneProxyService";
12+
13+
export const startAnyone: Action = {
14+
name: "START_ANYONE",
15+
similes: ["ANYONE"],
16+
validate: async (_runtime: IAgentRuntime, _message: Memory) => {
17+
return true;
18+
},
19+
description: "Start the Anyone client and proxy service",
20+
handler: async (
21+
_runtime: IAgentRuntime,
22+
_message: Memory,
23+
_state: State,
24+
_options: { [key: string]: unknown },
25+
_callback: HandlerCallback
26+
): Promise<boolean> => {
27+
await AnyoneClientService.initialize();
28+
const anon = AnyoneClientService.getInstance();
29+
const proxyService = AnyoneProxyService.getInstance();
30+
await proxyService.initialize();
31+
32+
_callback({
33+
text: `Started Anyone`,
34+
});
35+
36+
return true;
37+
},
38+
examples: [
39+
[
40+
{
41+
user: "{{user1}}",
42+
content: { text: "Can you start Anyone for me?" },
43+
},
44+
{
45+
user: "{{user2}}",
46+
content: {
47+
text: "I'll start Anyone right away",
48+
action: "START_ANYONE",
49+
},
50+
},
51+
],
52+
[
53+
{
54+
user: "{{user1}}",
55+
content: { text: "Initialize the Anyone client please" },
56+
},
57+
{
58+
user: "{{user2}}",
59+
content: {
60+
text: "Starting Anyone now",
61+
action: "START_ANYONE",
62+
},
63+
},
64+
],
65+
[
66+
{
67+
user: "{{user1}}",
68+
content: { text: "I need to start using Anyone" },
69+
},
70+
{
71+
user: "{{user2}}",
72+
content: {
73+
text: "I'll help you start Anyone",
74+
action: "START_ANYONE",
75+
},
76+
},
77+
],
78+
[
79+
{
80+
user: "{{user1}}",
81+
content: { text: "Launch Anyone for me" },
82+
},
83+
{
84+
user: "{{user2}}",
85+
content: {
86+
text: "I'll launch Anyone for you now",
87+
action: "START_ANYONE",
88+
},
89+
},
90+
],
91+
] as ActionExample[][],
92+
} as Action;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {
2+
ActionExample,
3+
HandlerCallback,
4+
IAgentRuntime,
5+
Memory,
6+
State,
7+
type Action,
8+
} from "@elizaos/core";
9+
import { AnyoneClientService } from "../services/AnyoneClientService";
10+
import { AnyoneProxyService } from "../services/AnyoneProxyService";
11+
12+
export const stopAnyone: Action = {
13+
name: "STOP_ANYONE",
14+
similes: ["STOP_PROXY"],
15+
validate: async (_runtime: IAgentRuntime, _message: Memory) => {
16+
return true;
17+
},
18+
description: "Stop the Anyone client and proxy service",
19+
handler: async (
20+
_runtime: IAgentRuntime,
21+
_message: Memory,
22+
_state: State,
23+
_options: { [key: string]: unknown },
24+
_callback: HandlerCallback
25+
): Promise<boolean> => {
26+
const proxyService = AnyoneProxyService.getInstance();
27+
proxyService.cleanup();
28+
29+
await AnyoneClientService.stop();
30+
31+
_callback({
32+
text: `Stopped Anyone and cleaned up proxy`,
33+
});
34+
35+
return true;
36+
},
37+
examples: [
38+
[
39+
{
40+
user: "{{user1}}",
41+
content: { text: "Can you stop Anyone for me?" },
42+
},
43+
{
44+
user: "{{user2}}",
45+
content: {
46+
text: "I'll stop Anyone right away",
47+
action: "STOP_ANYONE",
48+
},
49+
},
50+
],
51+
[
52+
{
53+
user: "{{user1}}",
54+
content: { text: "Please shut down Anyone" },
55+
},
56+
{
57+
user: "{{user2}}",
58+
content: {
59+
text: "Stopping Anyone now",
60+
action: "STOP_ANYONE",
61+
},
62+
},
63+
],
64+
[
65+
{
66+
user: "{{user1}}",
67+
content: { text: "I need to stop using Anyone" },
68+
},
69+
{
70+
user: "{{user2}}",
71+
content: {
72+
text: "I'll help you stop Anyone",
73+
action: "STOP_ANYONE",
74+
},
75+
},
76+
],
77+
[
78+
{
79+
user: "{{user1}}",
80+
content: { text: "Close Anyone for me" },
81+
},
82+
{
83+
user: "{{user2}}",
84+
content: {
85+
text: "I'll close Anyone for you now",
86+
action: "STOP_ANYONE",
87+
},
88+
},
89+
],
90+
] as ActionExample[][],
91+
} as Action;

packages/plugin-anyone/src/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Plugin } from "@elizaos/core";
2+
import { startAnyone } from "./actions/startAnyone.ts";
3+
import { stopAnyone } from "./actions/stopAnyone.ts";
4+
export * as actions from "./actions";
5+
6+
export const anyonePlugin: Plugin = {
7+
name: "anyone",
8+
description: "Proxy requests through Anyone",
9+
actions: [startAnyone, stopAnyone],
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Anon } from "@anyone-protocol/anyone-client";
2+
3+
export class AnyoneClientService {
4+
private static instance: Anon | null = null;
5+
6+
static getInstance(): Anon | null {
7+
return this.instance;
8+
}
9+
10+
static async initialize(): Promise<void> {
11+
if (!this.instance) {
12+
this.instance = new Anon({
13+
displayLog: true,
14+
socksPort: 9050,
15+
autoTermsAgreement: true,
16+
});
17+
await this.instance.start();
18+
}
19+
}
20+
21+
static async stop(): Promise<void> {
22+
if (this.instance) {
23+
await this.instance.stop();
24+
this.instance = null;
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { AnonSocksClient } from "@anyone-protocol/anyone-client";
2+
import axios from "axios";
3+
import { AnyoneClientService } from "./AnyoneClientService";
4+
5+
export class AnyoneProxyService {
6+
private static instance: AnyoneProxyService | null = null;
7+
private sockClient: AnonSocksClient | null = null;
8+
private originalAxios: any = null;
9+
private originalDefaults: any = null;
10+
11+
static getInstance(): AnyoneProxyService {
12+
if (!AnyoneProxyService.instance) {
13+
AnyoneProxyService.instance = new AnyoneProxyService();
14+
}
15+
return AnyoneProxyService.instance;
16+
}
17+
18+
async initialize(): Promise<void> {
19+
await AnyoneClientService.initialize();
20+
const anon = AnyoneClientService.getInstance();
21+
if (!anon) {
22+
throw new Error("Anyone client not initialized");
23+
}
24+
25+
this.sockClient = new AnonSocksClient(anon);
26+
27+
// Store original axios configuration
28+
this.originalDefaults = { ...axios.defaults };
29+
this.originalAxios = {
30+
request: axios.request,
31+
get: axios.get,
32+
post: axios.post,
33+
put: axios.put,
34+
delete: axios.delete,
35+
patch: axios.patch,
36+
};
37+
38+
// Create new defaults object instead of modifying existing one
39+
axios.defaults = {
40+
...axios.defaults,
41+
...this.sockClient.axios.defaults,
42+
};
43+
44+
// Apply proxy methods
45+
axios.request = this.sockClient.axios.request.bind(
46+
this.sockClient.axios
47+
);
48+
axios.get = this.sockClient.axios.get.bind(this.sockClient.axios);
49+
axios.post = this.sockClient.axios.post.bind(this.sockClient.axios);
50+
axios.put = this.sockClient.axios.put.bind(this.sockClient.axios);
51+
axios.delete = this.sockClient.axios.delete.bind(this.sockClient.axios);
52+
axios.patch = this.sockClient.axios.patch.bind(this.sockClient.axios);
53+
}
54+
55+
cleanup(): void {
56+
if (this.originalAxios && this.originalDefaults) {
57+
// Create fresh axios defaults
58+
axios.defaults = { ...this.originalDefaults };
59+
60+
// Create fresh bindings
61+
axios.request = this.originalAxios.request.bind(axios);
62+
axios.get = this.originalAxios.get.bind(axios);
63+
axios.post = this.originalAxios.post.bind(axios);
64+
axios.put = this.originalAxios.put.bind(axios);
65+
axios.delete = this.originalAxios.delete.bind(axios);
66+
axios.patch = this.originalAxios.patch.bind(axios);
67+
68+
this.originalAxios = null;
69+
this.originalDefaults = null;
70+
}
71+
AnyoneProxyService.instance = null;
72+
}
73+
}

0 commit comments

Comments
 (0)