Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ccf62fd
feat: refactor CLI, stub out generates, and implement createActionPro…
CarsonRoscoe Mar 17, 2025
7de0039
feat: refactored naming from kebbab case to camel case
CarsonRoscoe Mar 17, 2025
dc9bfec
feat: added wallet provider generation logic
CarsonRoscoe Mar 17, 2025
b033c75
feat: added create agentkit path
CarsonRoscoe Mar 17, 2025
3ed44f9
fix: improve createActionProvider & template
CarsonRoscoe Mar 17, 2025
690724c
feat: generate files in the current folder
CarsonRoscoe Mar 17, 2025
f5842a2
feat: implemented createAgent path
CarsonRoscoe Mar 18, 2025
e286388
chore: reorganize file structure
CarsonRoscoe Mar 19, 2025
b491f85
chore: ran lint/format
CarsonRoscoe Mar 19, 2025
32c0643
chore: changelog
CarsonRoscoe Mar 19, 2025
1dd0e81
fix: package-lock.json
CarsonRoscoe Mar 19, 2025
a2dbe0c
fix: imports
CarsonRoscoe Mar 19, 2025
6bbd7bb
fix: cli path to templates
CarsonRoscoe Mar 19, 2025
1faecd5
chore: updated readme
CarsonRoscoe Mar 19, 2025
c1b074d
chore: cleaned up messaging
CarsonRoscoe Mar 19, 2025
2cf3060
fix: cli message's generated file name
CarsonRoscoe Mar 19, 2025
501dc80
feat: split generate cli into separate bin export from default create
CarsonRoscoe Mar 21, 2025
9fdca7a
chore: lint/format
CarsonRoscoe Mar 21, 2025
a157d2a
chore: fix package-lock.json
CarsonRoscoe Mar 21, 2025
b09fea5
feat: improved robustness of arg handling
CarsonRoscoe Mar 21, 2025
fc60dac
chore: updated README
CarsonRoscoe Mar 21, 2025
0deed65
chore: renamed prepare agentkit work
CarsonRoscoe Mar 21, 2025
a2a4e66
chore: format/lint
CarsonRoscoe Mar 21, 2025
f410cf9
chore: pr feedback
CarsonRoscoe Mar 24, 2025
8489c7f
chore: updated README
CarsonRoscoe Mar 24, 2025
d5331b9
chore: cleanup cli selection
CarsonRoscoe Mar 24, 2025
75ab0c2
feat: added None option to createActionProvider's walletProvider sele…
CarsonRoscoe Mar 24, 2025
e8c3ec0
chore: PR feedback
CarsonRoscoe Mar 25, 2025
b63f51d
chore: updated changelog entry
CarsonRoscoe Mar 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions typescript/.changeset/wide-lions-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"create-onchain-agent": minor
---

Added code generation for individual building blocks
Comment thread
CarsonRoscoe marked this conversation as resolved.

Projects bootstrapped with the `create-onchain-agent` CLI will also have the `agenkit` CLI installed.
- `agentkit generate wallet-provider`: Generate a custom wallet provider
- `agentkit generate action-provider`: Generate a custom action provider
- `agentkit generate prepare`: Generate framework-agnostic AgentKit setup
- `agentkit generate create-agent`: Generate framework-specific agent creation
70 changes: 28 additions & 42 deletions typescript/create-onchain-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

`create-onchain-agent` is a CLI tool powered by [AgentKit](https://github.com/coinbase/agentkit) that allows developers to quickly scaffold an **onchain agent** project. This tool simplifies the setup process by generating a project with predefined configurations, including blockchain network selection, wallet providers, and framework setup.
`create-onchain-agent` is a CLI tool powered by [AgentKit](https://github.com/coinbase/agentkit) that provides multiple utilities for creating and integrating onchain agents into your projects. Whether you're starting a new project or adding AgentKit to an existing application, this tool offers flexible options to meet your needs.

## Prerequisites

Expand All @@ -13,61 +13,47 @@ Before using `create-onchain-agent`, ensure you have the following installed:

## Usage

To use `create-onchain-agent`, simply run:
### Quickstart Templates

To create a new project from scratch:

```sh
npm create onchain-agent@latest
```

This command will guide you through setting up an onchain agent project by prompting for necessary configuration options.

## Features

- **Guided setup**: Interactive prompts help configure the project.
- **Supports multiple AI frameworks**.
- **Supports multiple blockchain networks**.
- **Select your preferred wallet provider**.
- **Supports a preconfigured Next.js project with React, Tailwind CSS, and ESLint**.
- **Supports a preconfigured Model Context Protocol Server project**.
- **Automates environment setup**.

### **Setup Process**
The CLI will prompt you for the following details:

1. **Project Name**: The name of your new onchain agent project.
2. **Package Name**: The npm package name (auto-formatted if needed).
3. **Framework**: Choose from available AI frameworks.
4. **Network**: Choose from available blockchain networks.
5. **Chain ID**: Specify if using a custom network.
6. **Wallet Provider**: Select a preferred method for wallet management.

After answering the prompts, the CLI will:
This command lets you choose between two project templates:
- **Next.js Template**: A full-stack web application with React, Tailwind CSS, and ESLint
- **MCP Template**: A Model Context Protocol server project

- Generate the project structure.
- Copy necessary template files.
- Configure the selected settings.
- Display next steps to get started.
### Component Generation

## Getting Started

Once your project is created, navigate into the directory and install dependencies:
After installing the `create-onchain-agent` CLI, you will also have the `agenkit` CLI installed. This allows you to generate components for your project.

```sh
cd my-project
npm install
```
# Generate a custom wallet provider
agentkit generate wallet-provider

Then, configure your environment variables:
# Generate a custom action provider
agentkit generate action-provider

```sh
mv .env.local .env
# Generate framework-agnostic AgentKit setup.
agentkit generate prepare

# Generate framework-specific agent creation
agentkit generate create-agent
```

Run the development server:
## Features

```sh
npm run dev
```
- **Multiple project templates**:
- Next.js template for web applications
- MCP template for Model Context Protocol servers
- **Component generators** for existing projects
- **Guided setup** with interactive prompts
- **Support for multiple AI frameworks**
- **Support for multiple blockchain networks**
- **Flexible wallet provider options**
- **Automated environment setup**

## Documentation & Support

Expand Down
5 changes: 4 additions & 1 deletion typescript/create-onchain-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@
"templates/**"
],
"bin": {
"create-onchain-agent": "./dist/esm/cli.js"
"create-onchain-agent": "./dist/esm/create.js",
"agentkit": "./dist/esm/generate.js"
},
"sideEffects": false,
"type": "module",
"exports": {
"./package.json": "./package.json"
},
"dependencies": {
"@types/nunjucks": "^3.2.6",
"cac": "^6.7.14",
"cross-spawn": "^7.0.3",
"nunjucks": "^3.2.4",
"ora": "^8.1.0",
"picocolors": "^1.1.0",
"prompts": "^2.4.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import fs from "fs/promises";
import nunjucks from "nunjucks";
import path from "path";
import pc from "picocolors";
import prompts from "prompts";
import { fileURLToPath } from "url";
import { toCamelCase, toClassName, toSnakeCase } from "../common/utils.js";

// Get current file's directory in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
* Creates a new action provider
*/
export async function createActionProvider() {
// Configure nunjucks with the correct path
nunjucks.configure(path.join(__dirname, "../../../templates"), {
autoescape: false,
trimBlocks: true,
lstripBlocks: true,
});

// Get user input
const answers = await prompts([
{
type: "text",
name: "name",
message: "What is the name of your action provider?",
validate: (value: string) => (value.length > 0 ? true : "Name is required"),
},
{
type: "select",
name: "walletProvider",
message: "Which wallet provider is expected?",
choices: [
{ title: "None (No wallet/network required)", value: "none" },
{ title: "WalletProvider (Any network)", value: "WalletProvider" },
{ title: "EvmWalletProvider (EVM networks)", value: "EvmWalletProvider" },
{ title: "SvmWalletProvider (Solana networks)", value: "SvmWalletProvider" },
],
},
]);

// Process the name variations
const baseName = toClassName(answers.name);
const className = `${baseName}ActionProvider`;
const fileName = `${toCamelCase(baseName)}ActionProvider`;
const snakeName = toSnakeCase(answers.name);
const exportName = `${toCamelCase(baseName)}ActionProvider`;

const walletProvider = answers.walletProvider;

// Generate code using nunjucks
const generatedCode = nunjucks.render("actionProvider/actionProvider.njk", {
name: exportName,
className,
walletProvider,
actionName: `${snakeName}_action`,
schemaName: `${baseName}ActionSchema`,
});

// Write files directly to current directory
await fs.writeFile(`./${fileName}.ts`, generatedCode);

// Generate schema file using nunjucks with updated schema name
const schemaCode = nunjucks.render("actionProvider/schema.njk", {
className: `${baseName}Action`,
actionName: `${snakeName}_action`,
});

await fs.writeFile(`./schemas.ts`, schemaCode);

console.log(pc.green(`Successfully created ${className}.ts and schemas.ts`));
}
63 changes: 63 additions & 0 deletions typescript/create-onchain-agent/src/actions/createAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import fs from "fs/promises";
import path from "path";
import pc from "picocolors";
import prompts from "prompts";
import { copyTemplate } from "../common/fileSystem.js";

type AgentFramework = "langchain" | "vercelAISDK";

/**
* Creates an agent by selecting a framework and copying the appropriate template.
*
* - Prompts user to select between LangChain and Vercel AI SDK frameworks
* - Copies the selected framework's agent implementation
* - Cleans up unused framework files
*/
export async function createAgent() {
let result: prompts.Answers<"framework">;

try {
result = await prompts(
[
{
type: "select",
name: "framework",
message: pc.reset("Choose a framework:"),
choices: [
{ title: "LangChain", value: "langchain" },
{ title: "Vercel AI SDK", value: "vercelAISDK" },
] as { title: string; value: AgentFramework }[],
},
],
{
onCancel: () => {
console.log("\nAgent creation cancelled.");
process.exit(0);
},
},
);
} catch (error) {
console.error("An error occurred during agent creation", error);
process.exit(1);
}

const { framework } = result;

try {
const root = await copyTemplate("createAgent", "createAgent");

// Copy the selected framework's implementation to the destination
const selectedRoutePath = path.join(root, "framework", framework, "createAgent.ts");
const newRoutePath = path.join(process.cwd(), "createAgent.ts");

await fs.copyFile(selectedRoutePath, newRoutePath);

// Clean up the temporary directory
await fs.rm(root, { recursive: true, force: true });

console.log(pc.green("Successfully created createAgent.ts"));
} catch (error) {
console.error("Error setting up createAgent:", error);
process.exit(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import fs from "fs/promises";
import nunjucks from "nunjucks";
import path from "path";
import pc from "picocolors";
import prompts from "prompts";
import { fileURLToPath } from "url";
import { toCamelCase, toClassName, toSnakeCase } from "../common/utils.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
* Creates a new wallet provider
*/
export async function createWalletProvider() {
nunjucks.configure(path.join(__dirname, "../../../templates"), {
autoescape: false,
trimBlocks: true,
lstripBlocks: true,
});

const answers = await prompts([
{
type: "text",
name: "name",
message: "What is the name of your wallet provider?",
validate: (value: string) => (value.length > 0 ? true : "Name is required"),
},
{
type: "select",
name: "protocolFamily",
message: "Which protocol family will this support?",
choices: [
{ title: "EVM", value: "EVM" },
{ title: "SVM", value: "SVM" },
],
},
]);

const className = `${toClassName(answers.name)}WalletProvider`;
const fileName = `${toCamelCase(answers.name)}WalletProvider`;
const snakeName = toSnakeCase(answers.name);

const baseClass = answers.protocolFamily === "EVM" ? "EvmWalletProvider" : "SvmWalletProvider";

const generatedCode = nunjucks.render("walletProvider/walletProvider.njk", {
name: snakeName,
className,
protocolFamily: answers.protocolFamily,
baseClass,
});

// Write file directly to current directory
await fs.writeFile(`./${fileName}.ts`, generatedCode);

console.log(pc.green(`Successfully created ${fileName}.ts`));
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/usr/bin/env node
import fs from "fs";
import ora from "ora";
import path from "path";
import pc from "picocolors";
import prompts from "prompts";
import { EVM_NETWORKS, NetworkToWalletProviders, SVM_NETWORKS } from "./constants.js";
import { Network, WalletProviderChoice, Framework } from "./types.js";
import { copyTemplate } from "./fileSystem.js";
import {
EVM_NETWORKS,
Frameworks,
FrameworkToTemplates,
NetworkToWalletProviders,
SVM_NETWORKS,
} from "../common/constants.js";
import { copyTemplate } from "../common/fileSystem.js";
import { Framework, Network, WalletProviderChoice } from "../common/types.js";
import {
getWalletProviders,
handleMcpSelection,
handleNextSelection,
isValidPackageName,
toValidPackageName,
getWalletProviders,
handleMcpSelection,
} from "./utils.js";
import { Frameworks, FrameworkToTemplates } from "./constants.js";
} from "../common/utils.js";

/**
* Initializes the project creation process.
Expand All @@ -25,7 +29,7 @@ import { Frameworks, FrameworkToTemplates } from "./constants.js";
* - Handles network and wallet provider selection logic.
* - Displays a summary of the created project along with next steps.
*/
async function init() {
export async function initProject() {
console.log(
`${pc.blue(`
█████ ██████ ███████ ███ ██ ████████ ██ ██ ██ ████████
Expand Down Expand Up @@ -240,7 +244,7 @@ async function init() {
const spinner = ora(`Creating ${projectName}...`).start();

// Copy template over to new project
const root = await copyTemplate(projectName, packageName, template);
const root = await copyTemplate(projectName, template, packageName);

// Handle selection-specific logic over copied-template
switch (template) {
Expand Down Expand Up @@ -314,7 +318,3 @@ async function init() {
console.log(" - Join the community");
console.log(pc.blueBright(" - https://discord.gg/CDP\n"));
}

init().catch(e => {
console.error(e);
});
Loading