-
Notifications
You must be signed in to change notification settings - Fork 756
feat: npm cli - generate core primitives #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 7de0039
feat: refactored naming from kebbab case to camel case
CarsonRoscoe dc9bfec
feat: added wallet provider generation logic
CarsonRoscoe b033c75
feat: added create agentkit path
CarsonRoscoe 3ed44f9
fix: improve createActionProvider & template
CarsonRoscoe 690724c
feat: generate files in the current folder
CarsonRoscoe f5842a2
feat: implemented createAgent path
CarsonRoscoe e286388
chore: reorganize file structure
CarsonRoscoe b491f85
chore: ran lint/format
CarsonRoscoe 32c0643
chore: changelog
CarsonRoscoe 1dd0e81
fix: package-lock.json
CarsonRoscoe a2dbe0c
fix: imports
CarsonRoscoe 6bbd7bb
fix: cli path to templates
CarsonRoscoe 1faecd5
chore: updated readme
CarsonRoscoe c1b074d
chore: cleaned up messaging
CarsonRoscoe 2cf3060
fix: cli message's generated file name
CarsonRoscoe 501dc80
feat: split generate cli into separate bin export from default create
CarsonRoscoe 9fdca7a
chore: lint/format
CarsonRoscoe a157d2a
chore: fix package-lock.json
CarsonRoscoe b09fea5
feat: improved robustness of arg handling
CarsonRoscoe fc60dac
chore: updated README
CarsonRoscoe 0deed65
chore: renamed prepare agentkit work
CarsonRoscoe a2a4e66
chore: format/lint
CarsonRoscoe f410cf9
chore: pr feedback
CarsonRoscoe 8489c7f
chore: updated README
CarsonRoscoe d5331b9
chore: cleanup cli selection
CarsonRoscoe 75ab0c2
feat: added None option to createActionProvider's walletProvider sele…
CarsonRoscoe e8c3ec0
chore: PR feedback
CarsonRoscoe b63f51d
chore: updated changelog entry
CarsonRoscoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
typescript/create-onchain-agent/src/actions/createActionProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
63
typescript/create-onchain-agent/src/actions/createAgent.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
typescript/create-onchain-agent/src/actions/createWalletProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.