Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nulLeeKH authored Dec 28, 2024
2 parents 9359470 + 0bcf50d commit 0ca3f64
Show file tree
Hide file tree
Showing 37 changed files with 2,068 additions and 249 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,6 @@ PINATA_JWT= # Pinata JWT for uploading files to IPFS
# Cronos zkEVM
CRONOSZKEVM_ADDRESS=
CRONOSZKEVM_PRIVATE_KEY=

# Fuel Ecosystem (FuelVM)
FUEL_WALLET_PRIVATE_KEY=
17 changes: 17 additions & 0 deletions agent/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
};
7 changes: 6 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"start": "node --loader ts-node/esm src/index.ts",
"dev": "node --loader ts-node/esm src/index.ts",
"check-types": "tsc --noEmit"
"check-types": "tsc --noEmit",
"test": "jest"
},
"nodemonConfig": {
"watch": [
Expand Down Expand Up @@ -55,11 +56,15 @@
"@elizaos/plugin-twitter": "workspace:*",
"@elizaos/plugin-cronoszkevm": "workspace:*",
"@elizaos/plugin-3d-generation": "workspace:*",
"@elizaos/plugin-fuel": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
Expand Down
53 changes: 53 additions & 0 deletions agent/src/__tests__/client-type-identification.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Client, IAgentRuntime } from "@elizaos/core";
import { describe, it, expect } from '@jest/globals';

// Helper function to identify client types
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()}`;
}

// Mock client implementations for testing
class MockNamedClient implements Client {
type = "named-client";
async start(_runtime?: IAgentRuntime) { return this; }
async stop(_runtime?: IAgentRuntime) { }
}

class MockConstructorClient implements Client {
async start(_runtime?: IAgentRuntime) { return this; }
async stop(_runtime?: IAgentRuntime) { }
}

const mockPlainClient: Client = {
async start(_runtime?: IAgentRuntime) { return {}; },
async stop(_runtime?: IAgentRuntime) { }
};

describe("Client Type Identification", () => {
it("should identify client type from type property", () => {
const client = new MockNamedClient();
expect(determineClientType(client)).toBe("named-client");
});

it("should identify client type from constructor name", () => {
const client = new MockConstructorClient();
expect(determineClientType(client)).toBe("mockconstructor");
});

it("should generate fallback identifier for plain objects", () => {
const result = determineClientType(mockPlainClient);
expect(result).toMatch(/^client_\d+$/);
});
});
25 changes: 23 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import {
elizaLogger,
FsCacheAdapter,
IAgentRuntime,
ICacheManager,
IDatabaseAdapter,
IDatabaseCacheAdapter,
ModelProviderName,
settings,
stringToUuid,
validateCharacterConfig,
CacheStore,
Client,
ICacheManager,
} from "@elizaos/core";
import { RedisClient } from "@elizaos/adapter-redis";
import { zgPlugin } from "@elizaos/plugin-0g";
Expand All @@ -45,6 +46,7 @@ import { confluxPlugin } from "@elizaos/plugin-conflux";
import { evmPlugin } from "@elizaos/plugin-evm";
import { storyPlugin } from "@elizaos/plugin-story";
import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { imageGenerationPlugin } from "@elizaos/plugin-image-generation";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { multiversxPlugin } from "@elizaos/plugin-multiversx";
Expand Down Expand Up @@ -437,12 +439,30 @@ export async function initializeClients(
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) {
for (const client of plugin.clients) {
const startedClient = await client.start(runtime);
clients[client.name] = startedClient; // Assuming client has a name property
const clientType = determineClientType(client);
elizaLogger.debug(`Initializing client of type: ${clientType}`);
clients[clientType] = startedClient;
}
}
}
Expand Down Expand Up @@ -572,6 +592,7 @@ export async function createAgent(
getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null,
getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null,
getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null,
getSecret(character, "FUEL_PRIVATE_KEY") ? fuelPlugin : null,
].filter(Boolean),
providers: [],
actions: [],
Expand Down
3 changes: 2 additions & 1 deletion agent/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"module": "ESNext",
"moduleResolution": "Bundler",
"types": [
"node"
"node",
"jest"
]
},
"ts-node": {
Expand Down
20 changes: 13 additions & 7 deletions client/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
"@/*": [
"./src/*"
]
}
},
"include": ["src"]
}
"include": [
"src"
]
}
16 changes: 9 additions & 7 deletions client/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"lib": [
"ES2023"
],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
"noFallthroughCasesInSwitch": true
},
"include": ["vite.config.ts"]
}
"include": [
"vite.config.ts"
]
}
31 changes: 31 additions & 0 deletions docs/docs/packages/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,37 @@ console.log("Webhook creation response:", response);
- **Validation**: Always validate input parameters to ensure compliance with expected formats and supported networks.
- **Error Handling**: Monitor logs for errors during webhook creation and adjust retry logic as needed.

### 10. Fuel Plugin (`@elizaos/plugin-fuel`)

The Fuel plugin provides an interface to the Fuel Ignition blockchain.

**Actions:**

1. `TRANSFER_FUEL_ETH` - Transfer ETH to a given Fuel address. - **Inputs**: - `toAddress` (string): The Fuel address to transfer ETH to. - `amount` (string): The amount of ETH to transfer. - **Outputs**: Confirmation message with transaction details. - **Example**:
`json
{
"toAddress": "0x8F8afB12402C9a4bD9678Bec363E51360142f8443FB171655eEd55dB298828D1",
"amount": "0.00001"
}
`
**Setup and Configuration:**

1. **Configure the Plugin**
Add the plugin to your character's configuration:

```typescript
import { fuelPlugin } from "@eliza/plugin-fuel";

const character = {
plugins: [fuelPlugin],
};
```

1. **Required Configurations**
Set the following environment variables or runtime settings:

- `FUEL_WALLET_PRIVATE_KEY`: Private key for secure transactions

### Writing Custom Plugins

Create a new plugin by implementing the Plugin interface:
Expand Down
13 changes: 10 additions & 3 deletions packages/client-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ export class GitHubClient {
while (retries < maxRetries) {
try {
await this.git.clone(repositoryUrl, this.repoPath);
elizaLogger.log(`Successfully cloned repository from ${repositoryUrl}`);
elizaLogger.log(
`Successfully cloned repository from ${repositoryUrl}`
);
return;
} catch (error) {
elizaLogger.error(`Failed to clone repository from ${repositoryUrl}. Retrying...`);
elizaLogger.error(
`Failed to clone repository from ${repositoryUrl}. Retrying...`,
error
);
retries++;
if (retries === maxRetries) {
throw new Error(`Unable to clone repository from ${repositoryUrl} after ${maxRetries} retries.`);
throw new Error(
`Unable to clone repository from ${repositoryUrl} after ${maxRetries} retries.`
);
}
}
}
Expand Down
Loading

0 comments on commit 0ca3f64

Please sign in to comment.