Skip to content

Commit

Permalink
chore: sync up develop into sif-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
snobbee committed Jan 10, 2025
1 parent b252407 commit e298438
Show file tree
Hide file tree
Showing 47 changed files with 1,208 additions and 3,248 deletions.
6 changes: 4 additions & 2 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@elizaos/plugin-binance": "workspace:*",
"@elizaos/plugin-avail": "workspace:*",
"@elizaos/plugin-bootstrap": "workspace:*",
"@elizaos/plugin-dominos": "workspace:*",
"@elizaos/plugin-cosmos": "workspace:*",
"@elizaos/plugin-intiface": "workspace:*",
"@elizaos/plugin-coinbase": "workspace:*",
Expand All @@ -62,7 +61,9 @@
"@elizaos/plugin-giphy": "workspace:*",
"@elizaos/plugin-ton": "workspace:*",
"@elizaos/plugin-sui": "workspace:*",
"@elizaos/plugin-sgx": "workspace:*",
"@elizaos/plugin-tee": "workspace:*",
"@elizaos/plugin-tee-log": "workspace:*",
"@elizaos/plugin-tee-marlin": "workspace:*",
"@elizaos/plugin-multiversx": "workspace:*",
"@elizaos/plugin-near": "workspace:*",
Expand All @@ -82,6 +83,7 @@
"@elizaos/plugin-arthera": "workspace:*",
"@elizaos/plugin-allora": "workspace:*",
"@elizaos/plugin-opacity": "workspace:*",
"@elizaos/client-github": "workspace:*",
"@elizaos/plugin-github": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
Expand All @@ -94,4 +96,4 @@
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
}
}
59 changes: 46 additions & 13 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { LensAgentClient } from "@elizaos/client-lens";
import { SlackClientInterface } from "@elizaos/client-slack";
import { TelegramClientInterface } from "@elizaos/client-telegram";
import { TwitterClientInterface } from "@elizaos/client-twitter";
import { GitHubClientInterface } from "@elizaos/client-github";
// import { ReclaimAdapter } from "@elizaos/plugin-reclaim";
import { DirectClient } from "@elizaos/client-direct";
import {
AgentRuntime,
CacheManager,
Expand All @@ -32,6 +32,11 @@ import {
validateCharacterConfig,
} from "@elizaos/core";
import { zgPlugin } from "@elizaos/plugin-0g";

import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import createGoatPlugin from "@elizaos/plugin-goat";
// import { intifacePlugin } from "@elizaos/plugin-intiface";
import { DirectClient } from "@elizaos/client-direct";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import { alloraPlugin } from "@elizaos/plugin-allora";
Expand All @@ -40,7 +45,6 @@ import { artheraPlugin } from "@elizaos/plugin-arthera";
import { availPlugin } from "@elizaos/plugin-avail";
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
import { binancePlugin } from "@elizaos/plugin-binance";
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import {
advancedTradePlugin,
coinbaseCommercePlugin,
Expand All @@ -59,7 +63,6 @@ import { evmPlugin } from "@elizaos/plugin-evm";
import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { genLayerPlugin } from "@elizaos/plugin-genlayer";
import createGoatPlugin from "@elizaos/plugin-goat";
import { imageGenerationPlugin } from "@elizaos/plugin-image-generation";
import { multiversxPlugin } from "@elizaos/plugin-multiversx";
import { nearPlugin } from "@elizaos/plugin-near";
Expand All @@ -70,7 +73,9 @@ import { solanaPlugin } from "@elizaos/plugin-solana";
import { solanaAgentkitPlguin } from "@elizaos/plugin-solana-agentkit";
import { storyPlugin } from "@elizaos/plugin-story";
import { suiPlugin } from "@elizaos/plugin-sui";
import { sgxPlugin } from "@elizaos/plugin-sgx";
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
import { teeLogPlugin } from "@elizaos/plugin-tee-log";
import { teeMarlinPlugin } from "@elizaos/plugin-tee-marlin";
import { tonPlugin } from "@elizaos/plugin-ton";
import { webSearchPlugin } from "@elizaos/plugin-web-search";
Expand Down Expand Up @@ -480,26 +485,42 @@ export async function initializeClients(
clients.farcaster = farcasterClient;
}
}
if (clientTypes.includes(Clients.LENS)) {
if (clientTypes.includes("lens")) {
const lensClient = new LensAgentClient(runtime);
lensClient.start();
clients.lens = lensClient;
}

if (clientTypes.includes(Clients.SLACK)) {
const slackClient = await SlackClientInterface.start(runtime);
if (slackClient) clients.slack = slackClient; // Use object property instead of push
}

if (clientTypes.includes(Clients.GITHUB)) {
if (clientTypes.includes("github")) {
const githubClient = await GitHubClientInterface.start(runtime);
if (githubClient) clients.github = githubClient;
}

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

// TODO: Add Slack client to the list
// Initialize clients as an object

if (clientTypes.includes("slack")) {
const slackClient = await SlackClientInterface.start(runtime);
if (slackClient) clients.slack = slackClient; // Use object property instead of push
}

function determineClientType(client: Client): string {
// Check if client has a direct type identifier
if ("type" in client) {
return (client as any).type;
}

// Check constructor name
const constructorName = client.constructor?.name;
if (constructorName && !constructorName.includes("Object")) {
return constructorName.toLowerCase().replace("client", "");
}

// Fallback: Generate a unique identifier
return `client_${Date.now()}`;
}

if (character.plugins?.length > 0) {
for (const plugin of character.plugins) {
if (plugin.clients) {
Expand Down Expand Up @@ -600,7 +621,6 @@ export async function createAgent(
// character.plugins are handled when clients are added
plugins: [
bootstrapPlugin,
dominosPlugin,
getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
? confluxPlugin
: null,
Expand Down Expand Up @@ -664,6 +684,12 @@ export async function createAgent(
]
: []),
...(teeMode !== TEEMode.OFF && walletSecretSalt ? [teePlugin] : []),
getSecret(character, "SGX") ? sgxPlugin : null,
getSecret(character, "ENABLE_TEE_LOG") &&
((teeMode !== TEEMode.OFF && walletSecretSalt) ||
getSecret(character, "SGX"))
? teeLogPlugin
: null,
getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
Expand Down Expand Up @@ -834,7 +860,14 @@ async function startAgent(
db = initializeDatabase(dataDir) as IDatabaseAdapter &
IDatabaseCacheAdapter;

const cache = initializeDbCache(character, db);
await db.init();

const cache = initializeCache(
process.env.CACHE_STORE ?? CacheStore.DATABASE,
character,
"",
db
); // "" should be replaced with dir for file system caching. THOUGHTS: might probably make this into an env
const runtime: AgentRuntime = await createAgent(
character,
db,
Expand Down
3 changes: 0 additions & 3 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@ export default defineConfig({
alias: {
"@": "/src",
},
host: process.env.VITE_HOST || "localhost",
port: process.env.VITE_PORT || 5173,
strictPort: true,
},
});
2 changes: 1 addition & 1 deletion packages/adapter-supabase/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ CREATE TABLE knowledge (
"originalId" UUID REFERENCES knowledge("id"),
"chunkIndex" INTEGER,
"isShared" BOOLEAN DEFAULT FALSE,
CHECK((isShared = true AND "agentId" IS NULL) OR (isShared = false AND "agentId" IS NOT NULL))
CHECK(("isShared" = true AND "agentId" IS NULL) OR ("isShared" = false AND "agentId" IS NOT NULL))
);

-- Add index for Ollama table
Expand Down
1 change: 1 addition & 0 deletions packages/client-direct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"@elizaos/core": "workspace:*",
"@elizaos/plugin-image-generation": "workspace:*",
"@elizaos/plugin-tee-log": "workspace:*",
"@types/body-parser": "1.19.5",
"@types/cors": "2.8.17",
"@types/express": "5.0.0",
Expand Down
145 changes: 145 additions & 0 deletions packages/client-direct/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,148 @@ curl -X GET "http://localhost:3000/fine-tune/8566c47a-ada8-441c-95bc-7bb07656c4c
-H "Content-Type: application/json" \
-H "Authorization: Bearer jvBpxrTNqGqhnfQhSEqCdsG6aTSP8IBL".
```

# TEE Logging

TEE Logging is a feature that allows you to log the activities of your agents. Through these logs, you can verify that the actions of the agents are protected by the TEE and that they are executed autonomously by Eliza, without any third-party interference.

## Setup

You need to setup the TEE log plugin first. Follow the [TEE Log Plugin](../plugin-tee-log/README.md) to setup the plugin.

## Get all TEE agents Information

```bash
curl -X GET --location "http://localhost:3000/tee/agents"
```

Example response when success:

```json
{
"agents": [
{
"id": "f18738bb-edab-45f6-805d-7f26dbfdba87",
"agentId": "75490f32-c06a-0005-9804-339453d3fe2f",
"agentName": "tea",
"createdAt": 1735222963153,
"publicKey": "02e1a9dde5462ee40bc2df7cc3f0dc88c6e582ea1c4ccf5a30e9dd7fbed736b0fe",
"attestation": "{\"quote\":\"0x03000200000000000...d2d2d2d0a00\",\"timestamp\":1735222963152}"
}
],
"attestation": "{\"quote\":\"0x0300020000000...4452d2d2d2d2d0a00\",\"timestamp\":1735223101255}"
}
```

Note that the user report included in the attestation contains the SHA256 hash of the value of the "agents" field. Specifically, it is calculated as follows: `SHA256(JSON.stringify(agents value))`. By verifying the attestation, you can retrieve this hash value and ensure the integrity of the agents' information.


Example response when error:

```json
{
"error": "Failed to get TEE agents"
}
```

## Get TEE agent Information by agentId

```bash
curl -X GET --location "http://localhost:3000/tee/agents/75490f32-c06a-0005-9804-339453d3fe2f"
```

Example response when success:

```json
{
"agent": {
"id": "f18738bb-edab-45f6-805d-7f26dbfdba87",
"agentId": "75490f32-c06a-0005-9804-339453d3fe2f",
"agentName": "tea",
"createdAt": 1735222963153,
"publicKey": "02e1a9dde5462ee40bc2df7cc3f0dc88c6e582ea1c4ccf5a30e9dd7fbed736b0fe",
"attestation": "{\"quote\":\"0x0300020...452d2d2d2d2d0a00\",\"timestamp\":1735222963152}"
},
"attestation": "{\"quote\":\"0x03000200000000000...d2d2d2d2d0a00\",\"timestamp\":1735223294916}"
}
```

Note that the user report included in the attestation contains the SHA256 hash of the value of the "agent" field. Specifically, it is calculated as follows: `SHA256(JSON.stringify(agent value))`. By verifying the attestation, you can retrieve this hash value and ensure the integrity of the agent's information.

Example response when error:

```json
{
"error": "Failed to get TEE agent"
}
```

## Get TEE log

```bash
curl -X POST --location "http://localhost:3000/tee/logs" \
-H "Content-Type: application/json" \
-d '{
"query": {
"agentId": "75490f32-c06a-0005-9804-339453d3fe2f"
},
"page": 1,
"pageSize": 10
}'
```

There are optional parameters in the `query` parameter:

- **agentId**: (string, optional) The ID of the agent whose logs you want to retrieve.
- **roomId**: (string, optional) The ID of the room associated with the logs.
- **userId**: (string, optional) The ID of the user related to the logs.
- **type**: (string, optional) The type of logs to filter.
- **containsContent**: (string, optional) A substring to search for within the log content.
- **startTimestamp**: (number, optional) The starting timestamp for filtering logs.
- **endTimestamp**: (number, optional) The ending timestamp for filtering logs.


Example response when success:

```json
{
"logs": {
"page": 1,
"pageSize": 10,
"total": 2,
"data": [
{
"id": "01aac44e-d482-42df-8acc-6e6bfbb798f0",
"agentId": "75490f32-c06a-0005-9804-339453d3fe2f",
"roomId": "322d5683-fe3c-056a-8f1a-6b002e0a5c22",
"userId": "12dea96f-ec20-0935-a6ab-75692c994959",
"type": "Action:CONTINUE",
"content": "Continue",
"timestamp": 1735222998263,
"signature": "0x304402201a5bd4eb5807293ba0612b835eaaa56742c04603dbe08e3c7d247cdae3dc4b6f022034a165e1d63f1d58cb0976f615f6acd052f5e11154cef76d7c14c8ba99249833"
},
{
"id": "6275e742-3ebf-477c-ab45-99d2c701c4b5",
"agentId": "75490f32-c06a-0005-9804-339453d3fe2f",
"roomId": "322d5683-fe3c-056a-8f1a-6b002e0a5c22",
"userId": "12dea96f-ec20-0935-a6ab-75692c994959",
"type": "Action:CONTINUE",
"content": "Continue",
"timestamp": 1735223036272,
"signature": "0x304402201a5bd4eb5807293ba0612b835eaaa56742c04603dbe08e3c7d247cdae3dc4b6f022034a165e1d63f1d58cb0976f615f6acd052f5e11154cef76d7c14c8ba99249833"
}
]
},
"attestation": "{\"quote\":\"0x0300020000000000...4154452d2d2d2d2d0a00\",\"timestamp\":1735223364956}"
}
```

Note that the user report included in the attestation contains the SHA256 hash of the value of the "logs" field. Specifically, it is calculated as follows: `SHA256(JSON.stringify(logs value))`. By verifying the attestation, you can retrieve this hash value and ensure the integrity of the logs

Example response when error:

```json
{
"error": "Failed to get TEE logs"
}
```
Loading

0 comments on commit e298438

Please sign in to comment.