Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: client GitHub triggers actions #108

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@ai16z/client-direct": "workspace:*",
"@ai16z/client-discord": "workspace:*",
"@ai16z/client-farcaster": "workspace:*",
"@ai16z/client-github": "workspace:*",
"@ai16z/client-telegram": "workspace:*",
"@ai16z/client-twitter": "workspace:*",
"@ai16z/eliza": "workspace:*",
Expand Down Expand Up @@ -50,4 +51,4 @@
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
}
}
46 changes: 34 additions & 12 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DiscordClientInterface } from "@ai16z/client-discord";
import { TelegramClientInterface } from "@ai16z/client-telegram";
import { TwitterClientInterface } from "@ai16z/client-twitter";
import { FarcasterAgentClient } from "@ai16z/client-farcaster";
import { GitHubClientInterface } from "@ai16z/client-github";
import {
AgentRuntime,
CacheManager,
Expand Down Expand Up @@ -340,9 +341,9 @@ export async function initializeClients(
// each client can only register once
// and if we want two we can explicitly support it
const clients: Record<string, any> = {};
const clientTypes:string[] =
const clientTypes: string[] =
character.clients?.map((str) => str.toLowerCase()) || [];
elizaLogger.log('initializeClients', clientTypes, 'for', character.name)
elizaLogger.log("initializeClients", clientTypes, "for", character.name);

if (clientTypes.includes("auto")) {
const autoClient = await AutoClientInterface.start(runtime);
Expand All @@ -360,7 +361,9 @@ export async function initializeClients(
}

if (clientTypes.includes("twitter")) {
TwitterClientInterface.enableSearch = !isFalsish(getSecret(character, "TWITTER_SEARCH_ENABLE"));
TwitterClientInterface.enableSearch = !isFalsish(
getSecret(character, "TWITTER_SEARCH_ENABLE")
);
const twitterClient = await TwitterClientInterface.start(runtime);
if (twitterClient) clients.twitter = twitterClient;
}
Expand All @@ -369,12 +372,17 @@ export async function initializeClients(
// why is this one different :(
const farcasterClient = new FarcasterAgentClient(runtime);
if (farcasterClient) {
farcasterClient.start();
clients.farcaster = farcasterClient;
farcasterClient.start();
clients.farcaster = farcasterClient;
}
}

elizaLogger.log('client keys', Object.keys(clients));
if (clientTypes.includes("github")) {
const githubClient = await GitHubClientInterface.start(runtime);
if (githubClient) clients.github = githubClient;
}

elizaLogger.log("client keys", Object.keys(clients));

if (character.plugins?.length > 0) {
for (const plugin of character.plugins) {
Expand All @@ -397,10 +405,19 @@ function isFalsish(input: any): boolean {
}

// Convert input to a string if it's not null or undefined
const value = input == null ? '' : String(input);
const value = input == null ? "" : String(input);

// List of common falsish string representations
const falsishValues = ['false', '0', 'no', 'n', 'off', 'null', 'undefined', ''];
const falsishValues = [
"false",
"0",
"no",
"n",
"off",
"null",
"undefined",
"",
];

// Check if the value (trimmed and lowercased) is in the falsish list
return falsishValues.includes(value.trim().toLowerCase());
Expand All @@ -417,7 +434,7 @@ export async function createAgent(
db: IDatabaseAdapter,
cache: ICacheManager,
token: string
):AgentRuntime {
): AgentRuntime {
elizaLogger.success(
elizaLogger.successesTitle,
"Creating runtime for character",
Expand Down Expand Up @@ -532,7 +549,7 @@ function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
return cache;
}

async function startAgent(character: Character, directClient):AgentRuntime {
async function startAgent(character: Character, directClient): AgentRuntime {
let db: IDatabaseAdapter & IDatabaseCacheAdapter;
try {
character.id ??= stringToUuid(character.name);
Expand All @@ -551,7 +568,12 @@ async function startAgent(character: Character, directClient):AgentRuntime {
await db.init();

const cache = initializeDbCache(character, db);
const runtime:AgentRuntime = await createAgent(character, db, cache, token);
const runtime: AgentRuntime = await createAgent(
character,
db,
cache,
token
);

// start services/plugins/process knowledge
await runtime.initialize();
Expand All @@ -563,7 +585,7 @@ async function startAgent(character: Character, directClient):AgentRuntime {
directClient.registerAgent(runtime);

// report to console
elizaLogger.debug(`Started ${character.name} as ${runtime.agentId}`)
elizaLogger.debug(`Started ${character.name} as ${runtime.agentId}`);

return runtime;
} catch (error) {
Expand Down
4 changes: 1 addition & 3 deletions characters/logging-addict.character.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"model": "en_US-male-medium"
}
},
"plugins": [
"github"
],
"plugins": [],
"bio": [
"Always analyzes existing logging infrastructure before making recommendations, believing in extending and improving current patterns rather than replacing them entirely.",
"A meticulous and obsessive AI focused solely on implementing perfect logging practices across codebases. Lives and breathes structured logging, believing that proper observability is the key to understanding complex systems.",
Expand Down
3 changes: 2 additions & 1 deletion packages/client-github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"types": "dist/index.d.ts",
"dependencies": {
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-github": "workspace:*",
"@octokit/rest": "20.1.1",
"@octokit/types": "12.6.0",
"glob": "10.4.5",
Expand All @@ -20,4 +21,4 @@
"dev": "tsup --format esm --dts --watch",
"lint": "eslint . --fix"
}
}
}
8 changes: 0 additions & 8 deletions packages/client-github/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { IAgentRuntime } from "@ai16z/eliza";
import { z } from "zod";

export const githubEnvSchema = z.object({
GITHUB_OWNER: z.string().min(1, "GitHub owner is required"),
GITHUB_REPO: z.string().min(1, "GitHub repo is required"),
GITHUB_BRANCH: z.string().min(1, "GitHub branch is required"),
GITHUB_PATH: z.string().min(1, "GitHub path is required"),
GITHUB_API_TOKEN: z.string().min(1, "GitHub API token is required"),
});

Expand All @@ -16,10 +12,6 @@ export async function validateGithubConfig(
): Promise<GithubConfig> {
try {
const config = {
GITHUB_OWNER: runtime.getSetting("GITHUB_OWNER"),
GITHUB_REPO: runtime.getSetting("GITHUB_REPO"),
GITHUB_BRANCH: runtime.getSetting("GITHUB_BRANCH"),
GITHUB_PATH: runtime.getSetting("GITHUB_PATH"),
GITHUB_API_TOKEN: runtime.getSetting("GITHUB_API_TOKEN"),
};

Expand Down
Loading
Loading