Skip to content

Commit 5fbf1a4

Browse files
committed
push
1 parent 7fb2bc0 commit 5fbf1a4

File tree

8 files changed

+201
-5
lines changed

8 files changed

+201
-5
lines changed

bitte.dev.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"pluginId": "",
3+
"url": "",
4+
"receivedId": ""
5+
}

bun.lockb

139 KB
Binary file not shown.

next.config.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
const nextConfig = {
3+
async rewrites(){
4+
return [
5+
{
6+
source: "/.well-known/ai-plugin.json",
7+
destination: "/api/ai-plugin"
8+
}
9+
]
10+
}
11+
};
312

413
export default nextConfig;

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
7-
"build": "next build",
6+
"dev": "next dev & make-agent dev --port 3000",
7+
"build": "next build & make-agent build",
88
"start": "next start",
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@mintbase-js/data": "^0.6.4",
13+
"@mintbase-js/sdk": "^0.6.4",
14+
"@scalar/api-reference": "^1.25.10",
15+
"@scalar/nextjs-api-reference": "^0.4.85",
16+
"make-agent": "^0.0.8",
17+
"next": "14.2.9",
1218
"react": "^18",
1319
"react-dom": "^18",
14-
"next": "14.2.9"
20+
"vercel-url": "^0.2.1"
1521
},
1622
"devDependencies": {
1723
"typescript": "^5",

src/app/api/ai-plugin/route.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { NextResponse } from "next/server";
2+
import bitteDevJson from "@/bitte.dev.json";
3+
import { DEPLOYMENT_URL } from "vercel-url";
4+
5+
export async function GET() {
6+
const pluginData = {
7+
openapi: "3.0.0",
8+
info: {
9+
title: "Simple Weather API",
10+
description: "API for retrieving basic weather information for a given city.",
11+
version: "1.0.0",
12+
},
13+
servers: [
14+
{
15+
url: bitteDevJson.url || DEPLOYMENT_URL,
16+
},
17+
],
18+
"x-mb": {
19+
"account-id": "microchipgnu.mintbase.near",
20+
assistant: {
21+
name: "Weather Informer",
22+
description: "An assistant that provides weather information",
23+
instructions: "Get weather information for a given city and ALWAYS generate an image if successful retrieval from the API. If not, ask the user to claim a token.",
24+
"tools": [{ type: "generate-image" }]
25+
},
26+
},
27+
paths: {
28+
"/api/weather": {
29+
get: {
30+
tags: ["Weather"],
31+
summary: "Get weather information",
32+
description: "This endpoint returns basic weather information for a specified city.",
33+
operationId: "get-weather",
34+
parameters: [
35+
{
36+
name: "city",
37+
in: "query",
38+
description: "The name of the city to get weather information for.",
39+
required: true,
40+
schema: {
41+
type: "string",
42+
},
43+
example: "London",
44+
},
45+
],
46+
responses: {
47+
"200": {
48+
description: "Successful response",
49+
content: {
50+
"application/json": {
51+
schema: {
52+
type: "object",
53+
properties: {
54+
city: {
55+
type: "string",
56+
},
57+
temperature: {
58+
type: "number",
59+
},
60+
description: {
61+
type: "string",
62+
},
63+
},
64+
},
65+
},
66+
},
67+
},
68+
"400": {
69+
description: "Bad request",
70+
content: {
71+
"application/json": {
72+
schema: {
73+
type: "object",
74+
properties: {
75+
error: {
76+
type: "string",
77+
},
78+
},
79+
},
80+
},
81+
},
82+
},
83+
},
84+
},
85+
},
86+
"/api/time": {
87+
get: {
88+
tags: ["Time"],
89+
summary: "Get current time",
90+
description: "This endpoint returns the current time.",
91+
operationId: "get-time",
92+
responses: {
93+
"200": {
94+
description: "Successful response",
95+
content: {
96+
"application/json": {
97+
schema: {
98+
type: "object",
99+
properties: {
100+
currentTime: {
101+
type: "string",
102+
format: "date-time",
103+
},
104+
},
105+
},
106+
},
107+
},
108+
},
109+
},
110+
},
111+
},
112+
},
113+
};
114+
115+
return NextResponse.json(pluginData);
116+
}

src/app/api/time/route.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NextResponse } from "next/server";
2+
3+
export async function GET() {
4+
const currentTime = new Date().toISOString();
5+
6+
return NextResponse.json({
7+
currentTime: currentTime
8+
});
9+
}

src/app/api/weather/route.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { NextResponse } from "next/server";
2+
import { tokensByStatus } from '@mintbase-js/data'
3+
import { NEAR_NETWORKS } from '@mintbase-js/sdk';
4+
import { headers } from "next/headers";
5+
6+
const NFT_METADATA_ID = "drops.mintbase1.near:220a9aef89d8f60a1793ef404bdd4d71"
7+
const DROP_URL = "https://wallet.bitte.ai/claim/weatherai"
8+
9+
export async function GET(request: Request) {
10+
11+
const { searchParams } = new URL(request.url);
12+
const city = searchParams.get('city');
13+
14+
if (!city) {
15+
return NextResponse.json({ error: "City parameter is required" }, { status: 400 });
16+
}
17+
18+
const headersList = headers();
19+
const mbHeader = headersList.get("mb-metadata")
20+
const mbMetadata = JSON.parse(mbHeader || "{}")
21+
22+
const userAccountId = mbMetadata?.accountData?.accountId || "near"
23+
24+
const { data } = await tokensByStatus({
25+
metadataId: NFT_METADATA_ID,
26+
ownedBy: userAccountId,
27+
network: NEAR_NETWORKS.MAINNET
28+
})
29+
30+
// Check if user owns a token
31+
const ownsUnlistedToken = data?.unlistedTokens && data?.unlistedTokens.length > 0
32+
const ownsListedToken = data?.listedTokens && data?.listedTokens.length > 0
33+
34+
const userOwnsToken = ownsListedToken || ownsUnlistedToken
35+
36+
if (!userOwnsToken) {
37+
return NextResponse.json({
38+
message: `Please claim a drop first to get Weather API data. Here's the claiming link: ${DROP_URL}`
39+
})
40+
}
41+
42+
// In a real application, you would fetch this data from a weather API
43+
// For this example, we'll return mock data
44+
const weatherData = {
45+
city: city,
46+
temperature: Math.round(Math.random() * 30), // Random temperature between 0 and 30
47+
description: ["Sunny", "Cloudy", "Rainy", "Windy"][Math.floor(Math.random() * 4)], // Random weather description
48+
};
49+
50+
return NextResponse.json(weatherData);
51+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"paths": {
21-
"@/*": ["./src/*"]
21+
"@/*": ["./*"]
2222
}
2323
},
2424
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],

0 commit comments

Comments
 (0)