Skip to content

Commit 2ab3c88

Browse files
authored
Merge branch 'main' into 415-add-0g-plugin
2 parents 9c92116 + 6c5a238 commit 2ab3c88

File tree

17 files changed

+2057
-161
lines changed

17 files changed

+2057
-161
lines changed

docs/docs/community/streams/2024-11-15.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Link to space: https://x.com/i/spaces/1gqxvNpZVljxB/peek
1919
- 00:14:19 - Glue Update: Ducky AI, Open Sourcing Prompts & Tools
2020
- 00:17:31 - Ropey Update: Eliza Repo, Base Model Steering, Telegram Fixes, Dynamic Platform Access
2121
- 00:21:29 - Loaf Update: Eliza Architecture, Starknet Wallet Plugin, On-chain Games Plugins
22-
- 00:24:59 - Max Update: Helping Users Set Up
22+
- 00:24:59 - Odilitime Update: Helping Users Set Up
2323
- 00:25:45 - SomewheresHe Update: Sentience, Media Generation, Discord Launch, Brand Integration & Future of Media
2424
- 00:29:46 - Robin Update: God's Fun, Agent Autonomy & OpenRouter
2525
- 00:32:08 - IQ6900 Update: Building a Cooler Website

docs/src/components/HomepageHeader/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function HomepageHeader() {
4444
alt="blurred"
4545
/>
4646
<pre className={styles.codeBlock}>
47-
<code className="language-bash">{`npm package coming soon`}</code>
47+
<code className="language-bash">{`npm install @ai16z/eliza`}</code>
4848
</pre>
4949
</div>
5050
</div>

packages/adapter-postgres/schema.sql

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
CREATE EXTENSION IF NOT EXISTS vector;
15+
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
1516

1617
BEGIN;
1718

packages/client-github/.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

packages/client-github/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@ai16z/client-github",
3+
"version": "0.1.0",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "dist/index.d.ts",
7+
"dependencies": {
8+
"@ai16z/eliza": "workspace:*",
9+
"@octokit/rest": "^20.0.2",
10+
"@octokit/types": "^12.6.0",
11+
"glob": "^10.3.10",
12+
"simple-git": "^3.22.0"
13+
},
14+
"devDependencies": {
15+
"@types/glob": "^8.1.0",
16+
"tsup": "^8.3.5"
17+
},
18+
"scripts": {
19+
"build": "tsup --format esm --dts",
20+
"dev": "tsup --watch"
21+
}
22+
}

packages/client-github/src/index.ts

+236
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
import { Octokit } from "@octokit/rest";
2+
import { glob } from "glob";
3+
import simpleGit, { SimpleGit } from "simple-git";
4+
import path from "path";
5+
import fs from "fs/promises";
6+
import { existsSync } from "fs";
7+
import { createHash } from "crypto";
8+
import {
9+
elizaLogger,
10+
AgentRuntime,
11+
Client,
12+
IAgentRuntime,
13+
Content,
14+
Memory,
15+
stringToUuid,
16+
embeddingZeroVector,
17+
splitChunks,
18+
embed,
19+
} from "@ai16z/eliza";
20+
21+
export interface GitHubConfig {
22+
owner: string;
23+
repo: string;
24+
branch?: string;
25+
path?: string;
26+
token: string;
27+
}
28+
29+
export class GitHubClient {
30+
private octokit: Octokit;
31+
private git: SimpleGit;
32+
private config: GitHubConfig;
33+
private runtime: AgentRuntime;
34+
private repoPath: string;
35+
36+
constructor(runtime: AgentRuntime) {
37+
this.runtime = runtime;
38+
this.config = {
39+
owner: runtime.getSetting("GITHUB_OWNER") as string,
40+
repo: runtime.getSetting("GITHUB_REPO") as string,
41+
branch: runtime.getSetting("GITHUB_BRANCH") as string,
42+
path: runtime.getSetting("GITHUB_PATH") as string,
43+
token: runtime.getSetting("GITHUB_API_TOKEN") as string,
44+
};
45+
this.octokit = new Octokit({ auth: this.config.token });
46+
this.git = simpleGit();
47+
this.repoPath = path.join(
48+
process.cwd(),
49+
".repos",
50+
this.config.owner,
51+
this.config.repo
52+
);
53+
}
54+
55+
async initialize() {
56+
// Create repos directory if it doesn't exist
57+
await fs.mkdir(path.join(process.cwd(), ".repos", this.config.owner), {
58+
recursive: true,
59+
});
60+
61+
// Clone or pull repository
62+
if (!existsSync(this.repoPath)) {
63+
await this.git.clone(
64+
`https://github.com/${this.config.owner}/${this.config.repo}.git`,
65+
this.repoPath
66+
);
67+
} else {
68+
const git = simpleGit(this.repoPath);
69+
await git.pull();
70+
}
71+
72+
// Checkout specified branch if provided
73+
if (this.config.branch) {
74+
const git = simpleGit(this.repoPath);
75+
await git.checkout(this.config.branch);
76+
}
77+
}
78+
79+
async createMemoriesFromFiles() {
80+
console.log("Create memories");
81+
const searchPath = this.config.path
82+
? path.join(this.repoPath, this.config.path, "**/*")
83+
: path.join(this.repoPath, "**/*");
84+
85+
const files = await glob(searchPath, { nodir: true });
86+
87+
for (const file of files) {
88+
const relativePath = path.relative(this.repoPath, file);
89+
const content = await fs.readFile(file, "utf-8");
90+
const contentHash = createHash("sha256")
91+
.update(content)
92+
.digest("hex");
93+
const knowledgeId = stringToUuid(
94+
`github-${this.config.owner}-${this.config.repo}-${relativePath}`
95+
);
96+
97+
const existingDocument =
98+
await this.runtime.documentsManager.getMemoryById(knowledgeId);
99+
100+
if (
101+
existingDocument &&
102+
existingDocument.content["hash"] == contentHash
103+
) {
104+
continue;
105+
}
106+
107+
console.log(
108+
"Processing knowledge for ",
109+
this.runtime.character.name,
110+
" - ",
111+
relativePath
112+
);
113+
114+
const memory: Memory = {
115+
id: knowledgeId,
116+
agentId: this.runtime.agentId,
117+
userId: this.runtime.agentId,
118+
roomId: this.runtime.agentId,
119+
content: {
120+
text: content,
121+
hash: contentHash,
122+
source: "github",
123+
attachments: [],
124+
metadata: {
125+
path: relativePath,
126+
repo: this.config.repo,
127+
owner: this.config.owner,
128+
},
129+
},
130+
embedding: embeddingZeroVector,
131+
};
132+
133+
await this.runtime.documentsManager.createMemory(memory);
134+
135+
// Only split if content exceeds 4000 characters
136+
const fragments =
137+
content.length > 4000
138+
? await splitChunks(content, 2000, 200)
139+
: [content];
140+
141+
for (const fragment of fragments) {
142+
// Skip empty fragments
143+
if (!fragment.trim()) continue;
144+
145+
// Add file path context to the fragment before embedding
146+
const fragmentWithPath = `File: ${relativePath}\n\n${fragment}`;
147+
const embedding = await embed(this.runtime, fragmentWithPath);
148+
149+
await this.runtime.knowledgeManager.createMemory({
150+
// We namespace the knowledge base uuid to avoid id
151+
// collision with the document above.
152+
id: stringToUuid(knowledgeId + fragment),
153+
roomId: this.runtime.agentId,
154+
agentId: this.runtime.agentId,
155+
userId: this.runtime.agentId,
156+
content: {
157+
source: knowledgeId,
158+
text: fragment,
159+
},
160+
embedding,
161+
});
162+
}
163+
}
164+
}
165+
166+
async createPullRequest(
167+
title: string,
168+
branch: string,
169+
files: Array<{ path: string; content: string }>,
170+
description?: string
171+
) {
172+
// Create new branch
173+
const git = simpleGit(this.repoPath);
174+
await git.checkout(["-b", branch]);
175+
176+
// Write files
177+
for (const file of files) {
178+
const filePath = path.join(this.repoPath, file.path);
179+
await fs.mkdir(path.dirname(filePath), { recursive: true });
180+
await fs.writeFile(filePath, file.content);
181+
}
182+
183+
// Commit and push changes
184+
await git.add(".");
185+
await git.commit(title);
186+
await git.push("origin", branch);
187+
188+
// Create PR
189+
const pr = await this.octokit.pulls.create({
190+
owner: this.config.owner,
191+
repo: this.config.repo,
192+
title,
193+
body: description || title,
194+
head: branch,
195+
base: this.config.branch || "main",
196+
});
197+
198+
return pr.data;
199+
}
200+
201+
async createCommit(
202+
message: string,
203+
files: Array<{ path: string; content: string }>
204+
) {
205+
const git = simpleGit(this.repoPath);
206+
207+
// Write files
208+
for (const file of files) {
209+
const filePath = path.join(this.repoPath, file.path);
210+
await fs.mkdir(path.dirname(filePath), { recursive: true });
211+
await fs.writeFile(filePath, file.content);
212+
}
213+
214+
// Commit and push changes
215+
await git.add(".");
216+
await git.commit(message);
217+
await git.push();
218+
}
219+
}
220+
221+
export const GitHubClientInterface: Client = {
222+
start: async (runtime: IAgentRuntime) => {
223+
elizaLogger.log("GitHubClientInterface start");
224+
225+
const client = new GitHubClient(runtime as AgentRuntime);
226+
await client.initialize();
227+
await client.createMemoriesFromFiles();
228+
229+
return client;
230+
},
231+
stop: async (runtime: IAgentRuntime) => {
232+
elizaLogger.log("GitHubClientInterface stop");
233+
},
234+
};
235+
236+
export default GitHubClientInterface;

packages/client-github/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*.ts"]
8+
}

packages/client-github/tsup.config.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig } from "tsup";
2+
3+
export default defineConfig({
4+
entry: ["src/index.ts"],
5+
outDir: "dist",
6+
sourcemap: true,
7+
clean: true,
8+
format: ["esm"], // Ensure you're targeting CommonJS
9+
external: [
10+
"dotenv", // Externalize dotenv to prevent bundling
11+
"fs", // Externalize fs to use Node.js built-in module
12+
"path", // Externalize other built-ins if necessary
13+
"@reflink/reflink",
14+
"@node-llama-cpp",
15+
"https",
16+
"http",
17+
"agentkeepalive",
18+
"safe-buffer",
19+
// Add other modules you want to externalize
20+
],
21+
});

packages/client-twitter/src/post.ts

+5
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ export class TwitterPostClient extends ClientBase {
159159
// Use the helper function to truncate to complete sentence
160160
const content = truncateToCompleteSentence(formattedTweet);
161161

162+
if (this.runtime.getSetting("TWITTER_DRY_RUN") === 'true') {
163+
elizaLogger.info(`Dry run: would have posted tweet: ${content}`);
164+
return;
165+
}
166+
162167
try {
163168
const result = await this.requestQueue.add(
164169
async () => await this.twitterClient.sendTweet(content)

packages/core/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@
5757
"@ai-sdk/google-vertex": "^0.0.42",
5858
"@ai-sdk/groq": "^0.0.3",
5959
"@ai-sdk/openai": "1.0.0-canary.3",
60+
"@ai16z/adapter-sqlite": "^0.1.3",
61+
"@ai16z/adapter-sqljs": "^0.1.3",
62+
"@ai16z/adapter-supabase": "^0.1.3",
63+
"@ai16z/plugin-solana": "^0.1.3",
6064
"@anthropic-ai/sdk": "^0.30.1",
6165
"@types/uuid": "^10.0.0",
6266
"ai": "^3.4.23",
6367
"anthropic-vertex-ai": "^1.0.0",
6468
"fastembed": "^1.14.1",
69+
"fastestsmallesttextencoderdecoder": "^1.0.22",
6570
"gaxios": "6.7.1",
6671
"glob": "11.0.0",
6772
"js-sha1": "0.7.0",

0 commit comments

Comments
 (0)