Skip to content
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

Add Mastra ai adapter #394

Merged
merged 8 commits into from
Mar 24, 2025
Merged
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion typescript/examples/by-framework/eleven-labs/package.json
Original file line number Diff line number Diff line change
@@ -35,4 +35,4 @@
"postcss": "^8",
"tailwindcss": "^3.4.1"
}
}
}
2 changes: 1 addition & 1 deletion typescript/examples/by-framework/langchain/package.json
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@
"langchain": "^0.3.6",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@
"test": "vitest run --passWithNoTests",
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\""
},
"files": [
"build"
],
"files": ["build"],
"author": "",
"license": "MIT",
"dependencies": {
@@ -31,4 +29,4 @@
"devDependencies": {
"@types/node": "22.7.4"
}
}
}
2 changes: 1 addition & 1 deletion typescript/examples/by-framework/vercel-ai/package.json
Original file line number Diff line number Diff line change
@@ -20,4 +20,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@
"postchain-client": "1.20.1",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@
"langchain": "^0.3.2",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
2 changes: 1 addition & 1 deletion typescript/examples/by-use-case/evm-mint-nft/package.json
Original file line number Diff line number Diff line change
@@ -20,4 +20,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -20,4 +20,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -19,4 +19,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -17,4 +17,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -23,4 +23,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -19,4 +19,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
"dotenv": "^16.4.5",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
2 changes: 1 addition & 1 deletion typescript/examples/by-wallet/lit/package.json
Original file line number Diff line number Diff line change
@@ -25,4 +25,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
2 changes: 1 addition & 1 deletion typescript/examples/by-wallet/safe/package.json
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
"viem": "2.23.4",
"zod": "3.23.8"
}
}
}
5 changes: 5 additions & 0 deletions typescript/packages/adapters/mastra-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @goat-sdk/adapter-mastra-ai

## 0.1.0

Initial release of the Mastra AI adapter
46 changes: 46 additions & 0 deletions typescript/packages/adapters/mastra-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div align="center">
<a href="https://github.com/goat-sdk/goat">

<img src="https://github.com/user-attachments/assets/5fc7f121-259c-492c-8bca-f15fe7eb830c" alt="GOAT" width="100px" height="auto" style="object-fit: contain;">
</a>
</div>

# Mastra AI SDK Adapter for GOAT

Integrate the more than +200 onchain tools of GOAT with Mastra AI SDK.

## Installation
```
npm install @goat-sdk/adapter-mastra-ai
yarn add @goat-sdk/adapter-mastra-ai
pnpm add @goat-sdk/adapter-mastra-ai
```

## Usage

See a full working example [here](https://github.com/goat-sdk/goat/tree/main/typescript/examples/by-framework/mastra-ai).

```ts
import { getOnChainTools } from "@goat-sdk/adapter-mastra-ai";

const tools = await getOnChainTools({
wallet: // your wallet
plugins: // your plugins
});

const result = await generateText({
model: openai("gpt-4o-mini"),
tools: tools,
prompt: "Your prompt here",
});
```

<footer>
<br/>
<br/>
<div>
<a href="https://github.com/goat-sdk/goat">
<img src="https://github.com/user-attachments/assets/4821833e-52e5-4126-a2a1-59e9fa9bebd7" alt="GOAT" width="100%" height="auto" style="object-fit: contain; max-width: 800px;">
</a>
<div>
</footer>
36 changes: 36 additions & 0 deletions typescript/packages/adapters/mastra-ai/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@goat-sdk/adapter-mastra-ai",
"version": "0.1.0",
"sideEffects": false,
"files": ["dist/**/*", "README.md", "package.json"],
"scripts": {
"build": "tsup",
"clean": "rm -rf dist",
"test": "vitest run --passWithNoTests"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"dependencies": {
"@goat-sdk/core": "workspace:*",
"ai": "catalog:"
},
"peerDependencies": {
"@goat-sdk/core": "workspace:*",
"ai": "catalog:",
"zod": "^3.0.0"
},
"devDependencies": {
"zod": "catalog:"
},
"homepage": "https://ohmygoat.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/goat-sdk/goat.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/goat-sdk/goat/issues"
},
"keywords": ["ai", "agents", "web3"]
}
33 changes: 33 additions & 0 deletions typescript/packages/adapters/mastra-ai/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { type GetToolsParams, type ToolBase, type WalletClientBase, getTools } from "@goat-sdk/core";
import type { Tool } from "@mastra/core";
import { createTool } from "@mastra/core";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail to build since it's not declared on the package.json


export type GetOnChainToolsParams<TWalletClient extends WalletClientBase> = GetToolsParams<TWalletClient>;

export async function getOnChainTools<TWalletClient extends WalletClientBase>({
wallet,
plugins,
}: GetOnChainToolsParams<TWalletClient>) {
const tools: ToolBase[] = await getTools<TWalletClient>({
wallet,
plugins,
});

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const mastraTools: { [key: string]: Tool<string, any, any> } = {};

for (const t of tools) {
mastraTools[t.name] = createTool({
id: t.name,
description: t.description,
inputSchema: t.parameters,
execute: async ({ context }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter will complain here too

// Validate input against original schema
const validatedInput = await t.parameters.parseAsync(context);
return await t.execute(validatedInput);
},
});
}

return mastraTools;
}
9 changes: 9 additions & 0 deletions typescript/packages/adapters/mastra-ai/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../../tsconfig.base.json",
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"moduleResolution": "bundler"
}
}
6 changes: 6 additions & 0 deletions typescript/packages/adapters/mastra-ai/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "tsup";
import { treeShakableConfig } from "../../../tsup.config.base";

export default defineConfig({
...treeShakableConfig,
});
11 changes: 11 additions & 0 deletions typescript/packages/adapters/mastra-ai/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"tasks": {
"build": {
"inputs": ["src/**", "tsup.config.ts", "!./**/*.test.{ts,tsx}", "tsconfig.json"],
"dependsOn": ["^build"],
"outputs": ["dist/**"]
}
}
}
Loading