Skip to content

Commit

Permalink
Merge pull request #3 from coinbase/initial-commit
Browse files Browse the repository at this point in the history
feat: Initial Commit
  • Loading branch information
John-peterson-coinbase authored Dec 3, 2024
2 parents 21bb498 + e9759db commit 53c5db1
Show file tree
Hide file tree
Showing 62 changed files with 12,827 additions and 1 deletion.
51 changes: 51 additions & 0 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:jsdoc/recommended"
],
"plugins": ["@typescript-eslint", "prettier"],
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"multiline-comment-style": ["error", "starred-block"],
"prettier/prettier": "error",
"@typescript-eslint/member-ordering": "error",
"jsdoc/tag-lines": ["error", "any", { "startLines": 1 }],
"jsdoc/check-alignment": "error",
"jsdoc/no-undefined-types": "off",
"jsdoc/check-param-names": "error",
"jsdoc/check-tag-names": "error",
"jsdoc/check-types": "error",
"jsdoc/implements-on-classes": "error",
"jsdoc/require-description": "error",
"jsdoc/require-jsdoc": [
"error",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}
],
"jsdoc/require-param": "error",
"jsdoc/require-param-description": "error",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns": "error",
"jsdoc/require-returns-description": "error",
"jsdoc/require-returns-type": "off",
"jsdoc/require-hyphen-before-param-description": ["error", "always"]
},
"ignorePatterns": ["src/**/tests/**", "src/**/*.test.ts"]
}
7 changes: 7 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### What changed? Why?


#### Qualified Impact
<!-- Please evaluate what components could be affected and what the impact would be if there was an
error. How would this error be resolved, e.g. rollback a deploy, push a new fix, disable a feature
flag, etc... -->
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
**/.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# IDE
.idea/*
.vscode/*

## Emacs
*~
\#*\#
.\#*
**/.projectile

# Build outputs
dist
out
.next
.nuxt
build/Release
.turbo/

# Coverage
coverage
*.lcov
.nyc_output
lib-cov

# Dependencies
node_modules/
jspm_packages/
bower_components
web_modules/
.pnp.*

# Cache
.npm
.eslintcache
.stylelintcache
.parcel-cache
.cache
.temp
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# IDE
.vscode
.vscode-test
.idea
.tern-port

# Environment Configurations
**/env/
**/.env/
**/.env
**/.env.local/
**/.env.test/

# Runtime data
pids
*.pid
*.seed
*.pid.lock
*.tsbuildinfo
.node_repl_history

# Yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz

# Wallet data
**/wallet_data.txt

# Misc
.DS_Store
**/*_local*
api.json

# JSDoc
docs/
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docs/
coverage/
.github/
src/client
**/**/*.json
*.md
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid",
"printWidth": 100,
"proseWrap": "never"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CDP Node.js AgentKit Changelog

## Unreleased

## [0.0.5] - 2024-11-29

### Added

- Initial release of the CDP Node.js AgentKit.
210 changes: 210 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# CDP Agentkit Contributing Guide

Thank you for your interest in contributing to CDP Agentkit! We welcome all contributions, no matter how big or small. Some of the ways you can contribute include:
- Adding new actions to the core package
- Creating new AI framework extensions
- Adding tests and improving documentation

## Development

### Prerequisites
- Node.js 18 or higher
- npm for package management

### Set-up

Clone the repo by running:

```bash
git clone [email protected]:coinbase/cdp-agentkit-nodejs.git
cd cdp-agentkit-nodejs
```

Install dependencies:

```bash
npm install
```

### Building

To build all packages:

```bash
npm run build
```

### Linting & Formatting

To check for lint errors:

```bash
npm run lint
```

To automatically fix lint errors:

```bash
npm run lint-fix
```

To format code:

```bash
npm run format
```

### Testing

To run all tests:

```bash
npm test
```

### Documentation

To generate documentation:

```bash
npm run docs
```

## Adding an Action to Agentkit Core

Actions are defined in `cdp-agentkit-core/src/actions` module. See `cdp-agentkit-core/src/actions/mint_nft.ts` for an example.

Actions are created by implementing the `CdpAction` interface:

```typescript
import { CdpAction } from "./cdp_action";
import { Wallet } from "@coinbase/coinbase-sdk";
import { z } from "zod";

const MINT_NFT_PROMPT = `
This tool will mint an NFT (ERC-721) to a specified destination address onchain via a contract invocation. It takes the contract address of the NFT onchain and the destination address onchain that will receive the NFT as inputs. Do not use the contract address as the destination address. If you are unsure of the destination address, please ask the user before proceeding.`;

/**
* Input schema for mint NFT action.
*/
const MintNftInput = z
.object({
contractAddress: z.string().describe("The contract address of the NFT to mint"),
destination: z.string().describe("The destination address that will receive the NFT"),
})
.strip()
.describe("Instructions for minting an NFT");

/**
* Mints an NFT (ERC-721) to a specified destination address onchain.
*
* @param wallet - The wallet to mint the NFT from.
* @param args - The input arguments for the action.
* @returns A message containing the NFT mint details.
*/
async function mintNft(wallet: Wallet, args: z.infer<typeof MintNftInput>): Promise<string> {
const mintArgs = {
to: args.destination,
quantity: "1",
};

try {
const mintInvocation = await wallet.invokeContract({
contractAddress: args.contractAddress,
method: "mint",
args: mintArgs,
});

const result = await mintInvocation.wait();

return `Minted NFT from contract ${args.contractAddress} to address ${args.destination} on network ${wallet.getNetworkId()}.\nTransaction hash for the mint: ${result.getTransaction().getTransactionHash()}\nTransaction link for the mint: ${result.getTransaction().getTransactionLink()}`;
} catch (error) {
return `Error minting NFT: ${error}`;
}
}

/**
* Mint NFT action.
*/
export class MintNftAction implements CdpAction<typeof MintNftInput> {
public name = "mint_nft";
public description = MINT_NFT_PROMPT;
public argsSchema = MintNftInput;
public func = mintNft;
}
```

### Components of an Agentic Action

1. **Input Schema**: Define the input parameters using Zod schemas
2. **Prompt**: A description that helps the AI understand when and how to use the action
3. **Action Class**: Implements the `CdpAction` interface with:
- `name`: Unique identifier for the action
- `description`: The prompt text
- `argsSchema`: The Zod schema for validating inputs
- `func`: The implementation function
4. **Implementation Function**: The actual logic that executes the action

## Adding an Agentic Action to the Langchain Toolkit

1. Ensure the action is implemented in `cdp-agentkit-core` and in a released version
2. Update the `cdp-agentkit-core` dependency to the latest version
3. Add the action to the list of tools in `CdpToolkit`

## Development Tools

### Formatting
```bash
npm run format
```

### Linting
```bash
# Check for lint errors
npm run lint

# Fix lint errors
npm run lint-fix
```

### Testing
```bash
npm test
```

### Documentation
```bash
npm run docs
```

## Changelog

For new features and bug fixes, please add a new changelog entry to the `CHANGELOG.md` file in the appropriate packages and include that in your Pull Request.

## Pull Request Process

1. Create a new branch for your changes
2. Make your changes following the coding standards
3. Add tests for any new functionality
4. Update documentation as needed
5. Update the CHANGELOG.md
6. Submit a pull request

## Code Style

All code must follow the project's ESLint and Prettier configurations. The key rules are:
- Use TypeScript
- Follow JSDoc documentation standards
- Use 2 spaces for indentation
- Maximum line length of 100 characters
- Double quotes for strings
- Semicolons required

## Getting Help

If you have questions or need help, please:
1. Check the existing documentation
2. Search through existing issues
3. Create a new issue with your question

Thank you for contributing to CDP Agentkit!
Loading

0 comments on commit 53c5db1

Please sign in to comment.