Skip to content

Commit

Permalink
Merge branch 'develop' into direct-client_agent-crud
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo authored Jan 14, 2025
2 parents 2567aac + d3305c3 commit f47f7e4
Show file tree
Hide file tree
Showing 27 changed files with 821 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ GIPHY_API_KEY=
# OpenWeather
OPEN_WEATHER_API_KEY= # OpenWeather API key


#GITCOIN Passport
PASSPORT_API_KEY= #Gitcoin Passport key
PASSPORT_SCORER= #Scorer number

# EchoChambers Configuration
ECHOCHAMBERS_API_URL=http://127.0.0.1:3333
Expand Down
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@elizaos/plugin-flow": "workspace:*",
"@elizaos/plugin-gitbook": "workspace:*",
"@elizaos/plugin-story": "workspace:*",
"@elizaos/plugin-gitcoin-passport": "workspace:*",
"@elizaos/plugin-goat": "workspace:*",
"@elizaos/plugin-lensNetwork": "workspace:*",
"@elizaos/plugin-icp": "workspace:*",
Expand Down
6 changes: 5 additions & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { genLayerPlugin } from "@elizaos/plugin-genlayer";
import { giphyPlugin } from "@elizaos/plugin-giphy";
import { gitcoinPassportPlugin } from "@elizaos/plugin-gitcoin-passport";
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
import { imageGenerationPlugin } from "@elizaos/plugin-image-generation";
import { lensPlugin } from "@elizaos/plugin-lensNetwork";
Expand Down Expand Up @@ -826,7 +827,7 @@ export async function createAgent(
getSecret(character, "ABSTRACT_PRIVATE_KEY")
? abstractPlugin
: null,
getSecret(character, "B2_PRIVATE_KEY") ? b2Plugin: null,
getSecret(character, "B2_PRIVATE_KEY") ? b2Plugin : null,
getSecret(character, "BINANCE_API_KEY") &&
getSecret(character, "BINANCE_SECRET_KEY")
? binancePlugin
Expand Down Expand Up @@ -869,6 +870,9 @@ export async function createAgent(
getSecret(character, "LETZAI_API_KEY") ? letzAIPlugin : null,
getSecret(character, "STARGAZE_ENDPOINT") ? stargazePlugin : null,
getSecret(character, "GIPHY_API_KEY") ? giphyPlugin : null,
getSecret(character, "PASSPORT_API_KEY")
? gitcoinPassportPlugin
: null,
getSecret(character, "GENLAYER_PRIVATE_KEY")
? genLayerPlugin
: null,
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ export default function Page({ agentId }: { agentId: UUID }) {

const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
if (e.nativeEvent.isComposing) return;
handleSendMessage(e as unknown as React.FormEvent<HTMLFormElement>);
}
};


const handleSendMessage = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (!input) return;
Expand Down
18 changes: 12 additions & 6 deletions docs/docs/advanced/eliza-in-tee.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,22 @@ Example usage:
const provider = new DeriveKeyProvider(teeMode);
// For Solana
const { keypair, attestation } = await provider.deriveEd25519Keypair(
"/",
secretSalt,
"solana",
agentId,
);
// For EVM
const { keypair, attestation } = await provider.deriveEcdsaKeypair(
"/",
secretSalt,
"evm",
agentId,
);

// For raw key derivation
const rawKey = await provider.deriveRawKey(
secretSalt,
"raw",
);
```

---
Expand Down Expand Up @@ -161,7 +167,7 @@ To set up your environment for TEE development:
4. **Verify TEE Attestation**
You can verify the TEE attestation quote by going to the [TEE RA Explorer](https://ra-quote-explorer.vercel.app/) and pasting the attestation quote from the agent logs. Here's an example of interacting with the Eliza agent to ask for the agent's wallet address:
You can verify the TEE attestation quote by going to the [TEE RA Explorer](https://proof.t16z.com/) and pasting the attestation quote from the agent logs. Here's an example of interacting with the Eliza agent to ask for the agent's wallet address:
```bash
You: what's your wallet address?
Expand Down Expand Up @@ -227,7 +233,7 @@ Now we are ready to deploy the Eliza agent to a real TEE environment.

### Run an Eliza Agent in a Real TEE Environment

Before deploying the Eliza agent to a real TEE environment, you need to create a new TEE account on the [TEE Cloud](https://teehouse.vercel.app). Reach out to Phala Network on [Discord](https://discord.gg/phalanetwork) if you need help.
Before deploying the Eliza agent to a real TEE environment, you need to create a new TEE account on the [TEE Cloud](https://cloud.phala.network/login). Reach out to Phala Network on [Discord](https://discord.gg/phalanetwork) if you need help.

Next, you will need to take the docker-compose.yaml file in the root folder of the project and edit it based on your agent configuration.

Expand Down Expand Up @@ -285,7 +291,7 @@ volumes:
tee:
```
Now you can deploy the Eliza agent to a real TEE environment. Go to the [TEE Cloud](https://teehouse.vercel.app) and click on the `Create VM` button to configure your Eliza agent deployment.
Now you can deploy the Eliza agent to a real TEE environment. Go to the [TEE Cloud](https://cloud.phala.network/login) and click on the `Create VM` button to configure your Eliza agent deployment.

Click on the `Compose Manifest Mode` tab and paste the docker-compose.yaml file content into the `Compose Manifest` field.

Expand Down Expand Up @@ -313,7 +319,7 @@ Click on the `Logs` tab to view the agent logs.

![Agent Logs](https://i.imgur.com/aU3i0Dv.png)

Now we can verify the REAL TEE attestation quote by going to the [TEE RA Explorer](https://ra-quote-explorer.vercel.app/) and pasting the attestation quote from the agent logs.
Now we can verify the REAL TEE attestation quote by going to the [TEE RA Explorer](https://proof.t16z.com/) and pasting the attestation quote from the agent logs.

![TEE RA Explorer](https://i.imgur.com/TJ5299l.png)

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/packages/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ const provider = new DeriveKeyProvider();
// Derive a raw key
try {
const rawKey = await provider.rawDeriveKey(
"/path/to/derive",
"/path/to/derive", // This is what the WALLET_SECRET_SALT is used for
"subject-identifier",
);
// rawKey is a DeriveKeyResponse that can be used for further processing
Expand All @@ -482,7 +482,7 @@ try {
// Derive a Solana keypair (Ed25519)
try {
const solanaKeypair = await provider.deriveEd25519Keypair(
"/path/to/derive",
"/path/to/derive", // This is what the WALLET_SECRET_SALT is used for
"subject-identifier",
);
// solanaKeypair can now be used for Solana operations
Expand All @@ -493,7 +493,7 @@ try {
// Derive an Ethereum keypair (ECDSA)
try {
const evmKeypair = await provider.deriveEcdsaKeypair(
"/path/to/derive",
"/path/to/derive", // This is what the WALLET_SECRET_SALT is used for
"subject-identifier",
);
// evmKeypair can now be used for Ethereum operations
Expand Down
3 changes: 2 additions & 1 deletion packages/_examples/plugin/src/plugins/samplePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Plugin } from "@elizaos/core";
import { createResourceAction } from "../actions/sampleAction";
import { sampleProvider } from "../providers/sampleProvider";
import { sampleEvaluator } from "../evaluators/sampleEvalutor";
import SampleService from "../services/sampleService";

export const samplePlugin: Plugin = {
name: "sample",
Expand All @@ -10,6 +11,6 @@ export const samplePlugin: Plugin = {
providers: [sampleProvider],
evaluators: [sampleEvaluator],
// separate examples will be added for services and clients
services: [],
services: [new SampleService()],
clients: [],
};
136 changes: 136 additions & 0 deletions packages/_examples/plugin/src/services/sampleService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {
Service,
ServiceType,
IAgentRuntime,
// Memory,
// State,
elizaLogger,
// stringToUuid,
} from "@elizaos/core";
// import { sampleProvider } from "../providers/sampleProvider"; // TODO: Uncomment this line to use the sampleProvider

// Add SAMPLE to ServiceType enum in types.ts
declare module "@elizaos/core" {
export enum ServiceType {
SAMPLE = "sample",
}
}

// The SampleService is a simple service that logs "Hello world" every 15 minutes.
export class SampleService extends Service {
private runtime: IAgentRuntime | null = null;
private intervalId: NodeJS.Timeout | null = null;
private readonly DEFAULT_INTERVAL = 15 * 60 * 1000; // 15 minutes in milliseconds

static get serviceType(): ServiceType {
return ServiceType.SAMPLE;
}

private static isInitialized = false;

async initialize(runtime: IAgentRuntime): Promise<void> {
// Verify if the service is already initialized
if (SampleService.isInitialized) {
return;
}

this.runtime = runtime;

// Start the periodic task
this.startPeriodicTask();
SampleService.isInitialized = true;
elizaLogger.info("SampleService initialized and started periodic task");
}

private static activeTaskCount = 0;

private startPeriodicTask(): void {
// Verify if a task is already active
if (SampleService.activeTaskCount > 0) {
elizaLogger.warn(
"SampleService: Periodic task already running, skipping"
);
return;
}

// Clear any existing interval
if (this.intervalId) {
clearInterval(this.intervalId);
}

SampleService.activeTaskCount++;
elizaLogger.info(
`SampleService: Starting periodic task (active tasks: ${SampleService.activeTaskCount})`
);

// Initial call immediately
this.fetchSample();

// Set up periodic calls
this.intervalId = setInterval(() => {
this.fetchSample();
}, this.DEFAULT_INTERVAL);
}

private async fetchSample(): Promise<void> {
if (!this.runtime) {
elizaLogger.error("SampleService: Runtime not initialized");
return;
}

try {
// Example of using the sampleProvider
// Create dummy memory and state objects for the provider
// const dummyMemory: Memory = {
// id: stringToUuid("sample-service-trigger"),
// userId: this.runtime.agentId,
// agentId: this.runtime.agentId,
// roomId: this.runtime.agentId,
// content: { text: "Periodic sample fetch" },
// createdAt: Date.now(),
// };

// const dummyState: State = {
// userId: this.runtime.agentId,
// bio: "",
// lore: "",
// messageDirections: "",
// postDirections: "",
// roomId: this.runtime.agentId,
// actors: "",
// recentMessages: "",
// recentMessagesData: [],
// };
// await sampleProvider.get(this.runtime, dummyMemory, dummyState);

// hello world log example
elizaLogger.info("SampleService: Hello world");

elizaLogger.info(
"SampleService: Successfully fetched and processed sample"
);
} catch (error) {
elizaLogger.error("SampleService: Error fetching sample:", error);
}
}

// Method to stop the service
stop(): void {
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;
SampleService.activeTaskCount--;
elizaLogger.info(
`SampleService stopped (active tasks: ${SampleService.activeTaskCount})`
);
}
SampleService.isInitialized = false;
}

// Method to manually trigger a sample fetch (for testing)
async forceFetch(): Promise<void> {
await this.fetchSample();
}
}

export default SampleService;
2 changes: 1 addition & 1 deletion packages/plugin-evm/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ export const initWalletProvider = async (runtime: IAgentRuntime) => {

const deriveKeyProvider = new DeriveKeyProvider(teeMode);
const deriveKeyResult = await deriveKeyProvider.deriveEcdsaKeypair(
"/",
walletSecretSalt,
"evm",
runtime.agentId
);
return new WalletProvider(
Expand Down
38 changes: 38 additions & 0 deletions packages/plugin-gitcoin-passport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `@elizaos/plugin-passport`

This plugin provides actions for interacting with Gitcoin passport
https://docs.passport.xyz/building-with-passport/passport-api/overview

---

## Installation

Just add it under your character profile in plugins as

```
"plugins": [
"@elizaos/plugin-gitcoin-passport"
],
```

## Configuration

Getting Your API Key

1. Log in to the developer portal: Go to developer.passport.xyz and log in to your account by connecting your wallet.
2. Navigate to the API Keys section: After logging in, go to the "API Keys" section.
3. Generate an API key: Click on the "+ Create a Key" button to generate a unique API key for your account.
4. Store your API key securely: Store your API key in a secure place, as it will be used to access the Passport API.

Getting your Scorer ID

1. Log in to the Developer Portal: Go to developer.passport.xyz and log in to your account by connecting your wallet.
2. Navigate to the Scorer section: After logging in, go to the "Scorer" section
3. Create a Scorer: Click on the "+ Create a Scorer" button and input a Scorer name and description. Make sure you use the Unique Humanity scorer, and not the Binary scorer.
4. Find your Scorer ID: Click on the newly created Scorer and you will see the Scorer ID in the page URL.
Example: https://developer.passport.xyz/dashboard/scorer/{scorer_id}

## Usage

Results are saved as message and agents can retrive it from there for different use cases.
Default passport treshold of 20 is used, but you can pick your own value and match it agains that
3 changes: 3 additions & 0 deletions packages/plugin-gitcoin-passport/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
20 changes: 20 additions & 0 deletions packages/plugin-gitcoin-passport/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@elizaos/plugin-gitcoin-passport",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"tsup": "8.3.5"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"lint": "eslint --fix --cache ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
Loading

0 comments on commit f47f7e4

Please sign in to comment.