Skip to content

Commit 4c8a60a

Browse files
AIFlowMLwtfsayo
andauthored
feat: nvidia-nim-plugin (elizaOS#2599)
* Commit for the preparation of the PR * Fix conflicts in .env.example and package.json * fix node version * Update pnpm-lock.yaml * Fixed 2 issues from Coderabbit check * fixes build * fix coinbase agent kit loading * fix initialization issues --------- Co-authored-by: Sayo <82053242+wtfsayo@users.noreply.github.com>
1 parent e80c2e6 commit 4c8a60a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4661
-581
lines changed

.env.example

+24
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,27 @@ ROUTER_NITRO_EVM_PRIVATE_KEY=
718718
INITIA_PRIVATE_KEY= # Your Initia wallet private key
719719
INITIA_NODE_URL= # Initia node URL (default: testnet)
720720
INITIA_CHAIN_ID=initia-test # Chain ID (default: testnet)
721+
722+
# ####################################
723+
# #### NVIDIA Configuration ##########
724+
# ####################################
725+
NVIDIA_NIM_ENV=production
726+
NVIDIA_NIM_SPASH=false
727+
# Api Keys
728+
NVIDIA_NIM_API_KEY=
729+
NVIDIA_NGC_API_KEY=
730+
NVIDIA_NIM_MAX_RETRIES=3
731+
NVIDIA_NIM_RETRY_DELAY=1000
732+
NVIDIA_NIM_TIMEOUT=5000
733+
# Logging Configuration
734+
NVIDIA_GRANULAR_LOG=true
735+
NVIDIA_LOG_LEVEL=debug
736+
# NVIDIA Off-topic system and user configuration
737+
NVIDIA_OFFTOPIC_SYSTEM=
738+
NVIDIA_OFFTOPIC_USER=
739+
# NVIDIA Cosmos Model Configuration
740+
NVIDIA_NIM_BASE_VISION_URL=https://ai.api.nvidia.com/v1/vlm
741+
NVIDIA_COSMOS_MODEL=nvidia/cosmos-nemotron-34b
742+
NVIDIA_COSMOS_INVOKE_URL=https://ai.api.nvidia.com/v1/vlm/nvidia/cosmos-nemotron-34b
743+
NVIDIA_COSMOS_ASSET_URL=https://api.nvcf.nvidia.com/v2/nvcf/assets
744+
NVIDIA_COSMOS_MAX_TOKENS=1000

.github/workflows/integrationTests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- uses: actions/setup-node@v4
2323
with:
24-
node-version: "23"
24+
node-version: "23.3"
2525
cache: "pnpm"
2626

2727
- name: Clean up

.github/workflows/smoke-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- uses: actions/setup-node@v4
2323
with:
24-
node-version: "23"
24+
node-version: "23.3"
2525
cache: "pnpm"
2626

2727
- name: Run smoke tests

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ agent/content
6565
eliza.manifest
6666
eliza.manifest.sgx
6767
eliza.sig
68+
packages/plugin-nvidia-nim/extra
69+
packages/plugin-nvidia-nim/old_code
70+
packages/plugin-nvidia-nim/docs

agent/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@elizaos/plugin-goat": "workspace:*",
5858
"@elizaos/plugin-lensNetwork": "workspace:*",
5959
"@elizaos/plugin-icp": "workspace:*",
60-
"@elizaos/plugin-initia": "workspace:*",
60+
"@elizaos/plugin-initia": "workspace:*",
6161
"@elizaos/plugin-image-generation": "workspace:*",
6262
"@elizaos/plugin-movement": "workspace:*",
6363
"@elizaos/plugin-massa": "workspace:*",
@@ -84,6 +84,7 @@
8484
"@elizaos/plugin-twitter": "workspace:*",
8585
"@elizaos/plugin-primus": "workspace:*",
8686
"@elizaos/plugin-cronoszkevm": "workspace:*",
87+
"@elizaos/plugin-cronos": "workspace:*",
8788
"@elizaos/plugin-3d-generation": "workspace:*",
8889
"@elizaos/plugin-fuel": "workspace:*",
8990
"@elizaos/plugin-avalanche": "workspace:*",
@@ -111,6 +112,8 @@
111112
"@elizaos/plugin-devin": "workspace:*",
112113
"@elizaos/plugin-holdstation": "workspace:*",
113114
"@elizaos/plugin-router-nitro": "workspace:*",
115+
"@elizaos/plugin-nvidia-nim": "workspace:*",
116+
114117
"readline": "1.3.0",
115118
"ws": "8.18.0",
116119
"yargs": "17.7.2"

agent/src/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ import { devinPlugin } from '@elizaos/plugin-devin';
116116

117117

118118
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
119+
120+
import { nvidiaNimPlugin } from "@elizaos/plugin-nvidia-nim";
121+
119122
import Database from "better-sqlite3";
120123
import fs from "fs";
121124
import net from "net";
@@ -902,8 +905,7 @@ export async function createAgent(
902905
? elizaCodeinPlugin
903906
: null,
904907
bootstrapPlugin,
905-
getSecret(character, "CDP_API_KEY_NAME") &&
906-
getSecret(character, "CDP_API_KEY_PRIVATE_KEY")
908+
getSecret(character, "CDP_API_KEY_NAME") && getSecret(character, "CDP_API_KEY_PRIVATE_KEY") && getSecret(character, "CDP_AGENT_KIT_NETWORK")
907909
? agentKitPlugin
908910
: null,
909911
getSecret(character, "DEXSCREENER_API_KEY")
@@ -1099,6 +1101,12 @@ export async function createAgent(
10991101
? holdstationPlugin
11001102
: null,
11011103
getSecret(character, "INITIA_PRIVATE_KEY") ? initiaPlugin : null,
1104+
1105+
getSecret(character, "NVIDIA_NIM_API_KEY") ||
1106+
getSecret(character, "NVIDIA_NGC_API_KEY")
1107+
? nvidiaNimPlugin
1108+
: null,
1109+
getSecret(character, "INITIA_PRIVATE_KEY") && getSecret(character, "INITIA_NODE_URL") ? initiaPlugin : null
11021110
].filter(Boolean),
11031111
providers: [],
11041112
actions: [],

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@
6464
"optional": "0.1.4",
6565
"pnpm": "9.14.4",
6666
"sharp": "0.33.5",
67-
"tslog": "4.9.3"
67+
"tslog": "4.9.3",
68+
"bs58": "4.0.0"
6869
},
6970
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee",
7071
"workspaces": [
7172
"packages/*"
7273
]
73-
}
74+
}

packages/plugin-agentkit/src/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ console.log("└═════════════════════
1212

1313
const initializeActions = async () => {
1414
try {
15+
// Validate environment variables
16+
const apiKeyName = process.env.CDP_API_KEY_NAME;
17+
const apiKeyPrivateKey = process.env.CDP_API_KEY_PRIVATE_KEY;
18+
19+
if (!apiKeyName || !apiKeyPrivateKey) {
20+
console.warn("⚠️ Missing CDP API credentials - AgentKit actions will not be available");
21+
return [];
22+
}
23+
1524
const actions = await getAgentKitActions({
1625
getClient,
1726
});
1827
console.log("✔ AgentKit actions initialized successfully.");
1928
return actions;
2029
} catch (error) {
2130
console.error("❌ Failed to initialize AgentKit actions:", error);
22-
return null;
31+
return []; // Return empty array instead of failing
2332
}
2433
};
2534

packages/plugin-agentkit/src/provider.ts

+21-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import * as fs from "fs";
55
const WALLET_DATA_FILE = "wallet_data.txt";
66

77
export async function getClient(): Promise<CdpAgentkit> {
8+
// Validate required environment variables first
9+
const apiKeyName = process.env.CDP_API_KEY_NAME;
10+
const apiKeyPrivateKey = process.env.CDP_API_KEY_PRIVATE_KEY;
11+
12+
if (!apiKeyName || !apiKeyPrivateKey) {
13+
throw new Error("Missing required CDP API credentials. Please set CDP_API_KEY_NAME and CDP_API_KEY_PRIVATE_KEY environment variables.");
14+
}
15+
816
let walletDataStr: string | null = null;
917

1018
// Read existing wallet data if available
@@ -21,14 +29,20 @@ export async function getClient(): Promise<CdpAgentkit> {
2129
const config = {
2230
cdpWalletData: walletDataStr || undefined,
2331
networkId: process.env.CDP_AGENT_KIT_NETWORK || "base-sepolia",
32+
apiKeyName: apiKeyName,
33+
apiKeyPrivateKey: apiKeyPrivateKey
2434
};
2535

26-
const agentkit = await CdpAgentkit.configureWithWallet(config);
27-
// Save wallet data
28-
const exportedWallet = await agentkit.exportWallet();
29-
fs.writeFileSync(WALLET_DATA_FILE, exportedWallet);
30-
31-
return agentkit;
36+
try {
37+
const agentkit = await CdpAgentkit.configureWithWallet(config);
38+
// Save wallet data
39+
const exportedWallet = await agentkit.exportWallet();
40+
fs.writeFileSync(WALLET_DATA_FILE, exportedWallet);
41+
return agentkit;
42+
} catch (error) {
43+
console.error("Failed to initialize CDP AgentKit:", error);
44+
throw new Error(`Failed to initialize CDP AgentKit: ${error.message || 'Unknown error'}`);
45+
}
3246
}
3347

3448
export const walletProvider: Provider = {
@@ -39,7 +53,7 @@ export const walletProvider: Provider = {
3953
return `AgentKit Wallet Address: ${address}`;
4054
} catch (error) {
4155
console.error("Error in AgentKit provider:", error);
42-
return null;
56+
return `Error initializing AgentKit wallet: ${error.message}`;
4357
}
4458
},
4559
};

packages/plugin-cronos/package.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elizaos/plugin-cronos",
3-
"version": "0.0.1",
3+
"version": "0.1.9-alpha.1",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
@@ -18,16 +18,15 @@
1818
"files": [
1919
"dist"
2020
],
21-
"scripts": {
22-
"build": "tsup --format esm --dts"
23-
},
2421
"dependencies": {
2522
"@elizaos/core": "workspace:*",
26-
"node-cache": "^5.1.2",
27-
"viem": "^2.0.0"
23+
"tsup": "^8.3.5",
24+
"viem": "2.22.2"
25+
},
26+
"scripts": {
27+
"build": "tsup --format esm --dts"
2828
},
29-
"devDependencies": {
30-
"tsup": "^8.0.1",
31-
"typescript": "^5.3.3"
29+
"peerDependencies": {
30+
"whatwg-url": "7.1.0"
3231
}
33-
}
32+
}

packages/plugin-cronos/tsconfig.json

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
2-
"extends": "../core/tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "dist",
5-
"rootDir": "src",
6-
"moduleResolution": "Bundler",
7-
"module": "ESNext",
8-
"target": "ESNext",
9-
"declaration": true,
10-
"emitDeclarationOnly": true
11-
},
12-
"include": [
13-
"src/**/*.ts"
14-
]
15-
}
2+
"extends": "../core/tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*.ts"]
8+
}
+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elizaos/plugin-holdstation",
3-
"version": "0.1.1",
3+
"version": "0.1.9-alpha.1",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
@@ -15,18 +15,18 @@
1515
}
1616
}
1717
},
18+
"files": [
19+
"dist"
20+
],
1821
"dependencies": {
1922
"@elizaos/core": "workspace:*",
20-
"node-cache": "5.1.2",
23+
"tsup": "^8.3.5",
2124
"viem": "2.22.2"
2225
},
23-
"devDependencies": {
24-
"tsup": "8.3.5",
25-
"@types/node": "^20.0.0"
26-
},
2726
"scripts": {
28-
"build": "tsup --format esm --dts",
29-
"dev": "tsup --format esm --dts --watch",
30-
"lint": "eslint --fix --cache ."
27+
"build": "tsup --format esm --dts"
28+
},
29+
"peerDependencies": {
30+
"whatwg-url": "7.1.0"
3131
}
3232
}

packages/plugin-holdstation/src/providers/walletProvider.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,38 @@ import { PrivateKeyAccount } from "viem/accounts";
2424
import { useGetAccount, useGetWalletClient } from "../hooks";
2525
import { Item, SendTransactionParams, WalletPortfolio } from "../types";
2626

27-
import NodeCache from "node-cache";
27+
// Add this simple cache class
28+
class SimpleCache {
29+
private cache: Map<string, { value: any; expiry: number }>;
30+
private defaultTTL: number;
31+
32+
constructor(defaultTTL: number = 300) { // 300 seconds = 5 minutes
33+
this.cache = new Map();
34+
this.defaultTTL = defaultTTL;
35+
}
36+
37+
set(key: string, value: any): void {
38+
this.cache.set(key, {
39+
value,
40+
expiry: Date.now() + (this.defaultTTL * 1000)
41+
});
42+
}
43+
44+
get<T>(key: string): T | undefined {
45+
const item = this.cache.get(key);
46+
if (!item) return undefined;
47+
48+
if (Date.now() > item.expiry) {
49+
this.cache.delete(key);
50+
return undefined;
51+
}
52+
53+
return item.value as T;
54+
}
55+
}
2856

2957
export class WalletProvider {
30-
private cache: NodeCache;
58+
private cache: SimpleCache;
3159
account: PrivateKeyAccount;
3260
walletClient: WalletClient;
3361
publicClient: PublicClient<HttpTransport, Chain, Account | undefined>;
@@ -39,7 +67,7 @@ export class WalletProvider {
3967
chain: zksync,
4068
transport: http(),
4169
}) as PublicClient<HttpTransport, Chain, Account | undefined>;
42-
this.cache = new NodeCache({ stdTTL: 300 });
70+
this.cache = new SimpleCache(300); // 5 minutes TTL
4371
}
4472

4573
getAddress() {
+7-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
{
2-
"extends": "../core/tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "dist",
5-
"rootDir": "src",
6-
"types": [
7-
"node"
8-
]
9-
},
10-
"include": [
11-
"src/**/*.ts"
12-
]
13-
}
2+
"extends": "../core/tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*.ts"]
8+
}

0 commit comments

Comments
 (0)