Skip to content

Commit

Permalink
fix: docs, export, packages
Browse files Browse the repository at this point in the history
  • Loading branch information
azf20 committed Feb 12, 2025
1 parent 6d6eb39 commit 73a8080
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 2,342 deletions.
159 changes: 38 additions & 121 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"typescript/framework-extensions/langchain",
"typescript/examples/langchain-cdp-chatbot",
"typescript/examples/langchain-twitter-chatbot",
"typescript/examples/langchain-farcaster-chatbot"
"typescript/examples/langchain-farcaster-chatbot",
"typescript/examples/langchain-privy-chatbot"
],
"packageManager": "[email protected]",
"scripts": {
Expand Down Expand Up @@ -54,4 +55,4 @@
"typedoc": "^0.27.2",
"typescript": "^5.4.5"
}
}
}
28 changes: 26 additions & 2 deletions typescript/agentkit/src/wallet-providers/privyWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ interface PrivyWalletConfig {
* while maintaining compatibility with the base wallet provider interface.
*/
export class PrivyWalletProvider extends ViemWalletProvider {
#appId: string;
#appSecret: string;
#walletId: string;
#authorizationKey: string | undefined;

/**
* Private constructor to enforce use of factory method.
*
* @param walletClient - The Viem wallet client instance
* @param config - The configuration options for the Privy wallet
*/
private constructor(walletClient: WalletClient) {
private constructor(walletClient: WalletClient, config: PrivyWalletConfig) {
super(walletClient);
this.#appId = config.appId;
this.#appSecret = config.appSecret;
this.#walletId = config.walletId;
this.#authorizationKey = config.authorizationKey;
}

/**
Expand Down Expand Up @@ -82,7 +92,7 @@ export class PrivyWalletProvider extends ViemWalletProvider {
chain,
transport: http(),
});
return new PrivyWalletProvider(walletClient);
return new PrivyWalletProvider(walletClient, config);
}

/**
Expand All @@ -93,4 +103,18 @@ export class PrivyWalletProvider extends ViemWalletProvider {
getName(): string {
return "privy_wallet_provider";
}

/**
* Exports the wallet data.
*
* @returns The wallet data
*/
exportWallet(): PrivyWalletConfig {
return {
appId: this.#appId,
appSecret: this.#appSecret,
walletId: this.#walletId,
authorizationKey: this.#authorizationKey,
};
}
}
5 changes: 3 additions & 2 deletions typescript/examples/langchain-privy-chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This example demonstrates an agent setup as a self-aware terminal style chatbot with a [Privy server wallet](https://docs.privy.io/guide/server-wallets/).

Privy wallets are embedded wallets - learn more at https://docs.privy.io/guide/server-wallets/. The Agentkit integration assumes you have a Privy server wallet ID which you want to use for your agent - creation and management of Privy wallets can be done via the Privy dashboard or API.

## Ask the chatbot to engage in the Web3 ecosystem!

- "Transfer a portion of your ETH to a random address"
Expand All @@ -11,8 +13,7 @@ This example demonstrates an agent setup as a self-aware terminal style chatbot
## Requirements

- Node.js 18+
- [CDP API Key](https://portal.cdp.coinbase.com/access/api)
- [OpenAI API Key](https://platform.openai.com/docs/quickstart#create-and-export-an-api-key)
- [Privy](https://dashboard.privy.io/apps) (see ENV Vars below for details)

### Checking Node Version

Expand Down
17 changes: 9 additions & 8 deletions typescript/examples/langchain-privy-chatbot/chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatOpenAI } from "@langchain/openai";
import * as dotenv from "dotenv";
import * as readline from "readline";
import fs from "fs";

dotenv.config();

const WALLET_DATA_FILE = "wallet_data.txt";

/**
* Validates that required environment variables are set
*
Expand Down Expand Up @@ -52,7 +55,7 @@ function validateEnvironment(): void {
validateEnvironment();

/**
* Initialize the agent with CDP Agentkit
* Initialize the agent with Privy Agentkit
*
* @returns Agent executor and config
*/
Expand All @@ -63,7 +66,7 @@ async function initializeAgent() {
model: "gpt-4o-mini",
});

// Configure CDP Wallet Provider
// Configure Wallet Provider
const config = {
appId: process.env.PRIVY_APP_ID as string,
appSecret: process.env.PRIVY_APP_SECRET as string,
Expand Down Expand Up @@ -93,7 +96,7 @@ async function initializeAgent() {
const memory = new MemorySaver();
const agentConfig = { configurable: { thread_id: "Privy AgentKit Chatbot Example!" } };

// Create React Agent using the LLM and CDP AgentKit tools
// Create React Agent using the LLM and Privy AgentKit tools
const agent = createReactAgent({
llm,
tools,
Expand All @@ -111,11 +114,9 @@ async function initializeAgent() {
`,
});

/*
* Save wallet data
* Privy wallets are embedded wallets, manageable via the Privy dashboard or API
* Learn more: https://docs.privy.io/guide/server-wallets/
*/
// Save wallet data
const exportedWallet = walletProvider.exportWallet();
fs.writeFileSync(WALLET_DATA_FILE, JSON.stringify(exportedWallet));

return { agent, config: agentConfig };
} catch (error) {
Expand Down
Loading

0 comments on commit 73a8080

Please sign in to comment.