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

next.js #39

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Binary file removed bun.lockb
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/commands/dev.ts → commands/dev-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Command } from "commander";
import { TunnelService } from "../services/tunnel";
import { detectPort } from "../utils/port-detector";

export const devCommand = new Command()
.name("dev")
export const devDeprecatedCommand = new Command()
.name("dev-deprecated")
.description("Make your AI agent discoverable and register the plugin")
.option("-p, --port <number>", "Local port to expose", parseInt)
.option("-s, --serveo", "Use Serveo instead of Localtunnel", false)
Expand Down
145 changes: 145 additions & 0 deletions commands/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { exec } from "child_process";
import { Command } from "commander";
import dotenv from "dotenv";
import isPortReachable from "is-port-reachable";

import { getDeployedUrl } from "../utils/deployed-url";
import { validateEnv } from "../utils/env";
import { validateAndParseOpenApiSpec } from "../utils/openapi";
import { detectPort } from "../utils/port-detector";
import { getHostname, getSpecUrl } from "../utils/url-utils";

dotenv.config();
validateEnv();

interface ApiConfig {
key: string;
url: string;
serverPort: number;
}

interface PortConfig {
port: number;
serverPort: number;
}

interface ValidationResult {
pluginId: string;
accountId: string;
spec: unknown;
}

const DEFAULT_PORTS = {
SERVER: 3010,
UI: 5000
} as const;

async function findAvailablePort(startPort: number): Promise<number> {
let port = startPort;
while (await isPortReachable(port, {host: "localhost"})) {
port++;
}
return port;
}

// const API_CONFIG: ApiConfig = {
// key: process.env.BITTE_API_KEY!,
// url: process.env.BITTE_API_URL!,
// serverPort: DEFAULT_PORTS.SERVER
// };

async function fetchAndValidateSpec(url: string): Promise<ValidationResult> {
const pluginId = getHostname(url);
const specUrl = getSpecUrl(url);

const validation = await validateAndParseOpenApiSpec(specUrl);
const { isValid, accountId } = validation;

const specContent = await fetch(specUrl).then(res => res.text());
let spec = JSON.parse(specContent);

if (!isValid) {
spec = {
...spec,
servers: [{ url }],
"x-mb": {
...spec["x-mb"],
"account-id": accountId || "anon",
}
};
}

return {
pluginId,
accountId: accountId || "anon",
spec
};
}

async function setupPorts(options: { port?: string }): Promise<PortConfig> {
let port = parseInt(options.port || "") || 0;

if (port === 0) {
const detectedPort = await detectPort();
if (detectedPort) {
port = detectedPort;
} else {
port = await findAvailablePort(3000);
}
}

const serverPort = await findAvailablePort(DEFAULT_PORTS.SERVER);

return { port, serverPort };
}

export const devCommand = new Command()
.name("dev")
.description("Start a local playground for your AI agent")
.option("-p, --port <port>", "Port to run playground on", "3000")
.option("-t, --testnet", "Use Testnet instead of Mainnet", false)
.action(async (options) => {
try {
// Setup ports for the server
const { port } = await setupPorts(options);

// Get and validate the deployed URL
const deployedUrl = getDeployedUrl(port);
if (!deployedUrl) {
throw new Error("Deployed URL could not be determined.");
}

// Fetch and validate the spec
const localAgent = await fetchAndValidateSpec(deployedUrl);

exec(`cd playground && next dev -p ${port}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error starting Next.js server: ${error.message}`);
return;
}
if (stderr) {
console.error(`Next.js server stderr: ${stderr}`);
return;
}
console.log(`Next.js server stdout: ${stdout}`);
});

// Handle cleanup
const cleanup = async (): Promise<void> => {
process.exit(0);
};

process.on("SIGINT", cleanup);
process.on("SIGTERM", cleanup);

console.log(`
Development server is running:
- Main UI & API: http://localhost:${port}
Press Ctrl+C to stop
`);

} catch (error) {
console.error("Failed to start development server:", error);
process.exit(1);
}
});
File renamed without changes.
File renamed without changes.
24 changes: 1 addition & 23 deletions src/commands/verify.ts → commands/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,9 @@ export const verifyCommand = new Command()
"To verify a plugin we need the url for a public repository containing the plugin's code",
)
.option(
"-v, --version [versionNumber]",
"-v, --version <versionNumber>",
"Specify the version of the plugin in case of an update",
)
.option(
"-c, --categories [categories]",
"List some categories that describe the type of plugin you're verifying. Example: -c DeFi,Investing",
(categories) =>
categories && typeof categories === "string" && categories.length > 0
? categories.split(",")
: null,
)
.option(
"-x, --chains [chainIds]",
"If your plugin works on specific evm chains, you can specify them so your plugin is easier to find. If your plugin does not work on evm you can ignore this flag. Example: -x 1,8453",
(str) => {
// convert comma separated numbers on a string to an int array
if (!str || typeof str !== "string" || str.length === 0) {
return null;
}
const strArray = str.split(",");
return strArray.map((num) => parseInt(num));
},
)
.action(async (options) => {
const url = options.url || deployedUrl;

Expand Down Expand Up @@ -69,7 +49,5 @@ export const verifyCommand = new Command()
email: options.email,
repo: options.repo,
version: options.version,
categories: options.categories,
chains: options.chains,
});
});
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion src/index.ts → index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import { program } from "commander";
import dotenv from "dotenv";

import packageJson from "../package.json";
import { contractCommand } from "./commands/contract";
import { deleteCommand } from "./commands/delete";
import { deployCommand } from "./commands/deploy";
import { devCommand } from "./commands/dev";
import { registerCommand } from "./commands/register";
import { updateCommand } from "./commands/update";
import { verifyCommand } from "./commands/verify";
import packageJson from "./package.json";


dotenv.config();

Expand Down
58 changes: 32 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"description": "Bitte AI Agent Builder and Playground",
"bin": {
"make-agent": "./dist/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mintbase/make-agent"
},
"repository": "git+https://github.com/BitteProtocol/make-agent",
"bugs": {
"url": "https://github.com/mintbase/make-agent/issues"
"url": "https://github.com/BitteProtocol/make-agent/issues"
},
"homepage": "https://github.com/mintbase/make-agent/repo#readme",
"homepage": "https://github.com/BitteProtocol/make-agent/repo#readme",

"scripts": {
"typecheck": "tsc --noEmit",
"dev": "bun run ./src/index.ts dev --port 3000",
"build": "bun run typecheck && bun build ./src/index.ts --outdir ./dist --target node",
"prepublishOnly": "bun run build",
"build-binary": "bun run typecheck && bun build ./src/index.ts --compile --outfile make-agent",
"dev": "tsup src/index.ts --watch --onSuccess 'node dist/index.js'",
"build": "tsup --config tsup.config.ts",
"prepublishOnly": "yarn build",
"lint": "prettier --check '{src,tests}/**/*.{js,ts}' && eslint . --ignore-pattern dist/",
"fmt": "prettier --write '{src,tests}/**/*.{js,ts}' && yarn lint --fix"
},
Expand All @@ -30,10 +28,31 @@
"agent",
"cli"
],
"author": "Micro",
"author": "Bitte Team",
"license": "MIT",
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"borsh": "^0.7.0",
"commander": "^12.1.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.2",
"hono": "^4.5.11",
"http-proxy-middleware": "^3.0.3",
"inquirer": "^12.0.0",
"is-port-reachable": "^4.0.0",
"js-sha256": "^0.11.0",
"localtunnel": "^2.0.2",
"near-api-js": "^4.0.3",
"near-ca": "^0.8.1",
"near-safe": "^0.9.6",
"open": "^10.1.0",
"tsup": "^8.3.5",
"vercel-url": "^0.2.1"
},
"devDependencies": {
"@types/bun": "latest",
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/inquirer": "^9.0.7",
"@types/localtunnel": "^2.0.4",
"@types/node": "^22.7.2",
Expand All @@ -47,18 +66,5 @@
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"borsh": "^0.7.0",
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"hono": "^4.5.11",
"inquirer": "^12.0.0",
"js-sha256": "^0.11.0",
"localtunnel": "^2.0.2",
"near-api-js": "^4.0.3",
"open": "^10.1.0",
"vercel-url": "^0.2.1"
}
}
}
41 changes: 41 additions & 0 deletions playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
16 changes: 16 additions & 0 deletions playground/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

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

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
Loading
Loading