{"id":50342520,"url":"https://github.com/BitteProtocol/chat-boilerplate-next-pages","last_synced_at":"2026-06-15T09:01:04.974Z","repository":{"id":283117667,"uuid":"926683155","full_name":"BitteProtocol/chat-boilerplate-next-pages","owner":"BitteProtocol","description":"Next Pages Chat Example","archived":false,"fork":false,"pushed_at":"2025-05-21T08:03:29.000Z","size":662,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-04-26T18:25:49.996Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://chat-boilerplate-next-pages.vercel.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BitteProtocol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-03T17:26:15.000Z","updated_at":"2025-05-21T08:03:32.000Z","dependencies_parsed_at":"2025-05-20T12:38:32.381Z","dependency_job_id":"ad068eac-0341-440f-bfc7-d0f43ad1d089","html_url":"https://github.com/BitteProtocol/chat-boilerplate-next-pages","commit_stats":null,"previous_names":["bitteprotocol/chat-boilerplate-next-pages"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BitteProtocol/chat-boilerplate-next-pages","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitteProtocol%2Fchat-boilerplate-next-pages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitteProtocol%2Fchat-boilerplate-next-pages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitteProtocol%2Fchat-boilerplate-next-pages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitteProtocol%2Fchat-boilerplate-next-pages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BitteProtocol","download_url":"https://codeload.github.com/BitteProtocol/chat-boilerplate-next-pages/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitteProtocol%2Fchat-boilerplate-next-pages/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34355156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-29T18:00:25.258Z","updated_at":"2026-06-15T09:01:04.968Z","avatar_url":"https://github.com/BitteProtocol.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Chat Boilerplate for Next.js Pages Router\n\n## Overview\n\nThis repository provides a working example of a Next.js 15 Pages Router implementation with [@bitte-ai/chat](https://github.com/BitteProtocol/chat).\n\n## Key Considerations\n\n⚠️ **Implementation Notes**\n\nWhile the App Router implementation in [chat-boilerplate](https://github.com/BitteProtocol/chat-boilerplate/blob/main/src/app/api/chat/route.ts) uses a different approach due to architectural differences, **the proxy implementation in this repository works correctly with Pages Router**.\n\nOur implementation leverages the getReader() method and async recursion to handle streaming responses despite Pages Router's lack of native `ReadableStream` support.\n\n([See Next.js discussion](https://github.com/vercel/next.js/discussions/67026#discussioncomment-9819996) for more details on architectural differences)\n\n## Usage Notes\n\n✅ **Compatible With**\n- Your own external API endpoints (for custom agent implementations)\n- EVM blockchain connections\n- SUI blockchain connections\n- NEAR Protocol connections\n\n## Using the BitteAiChat Component\n\nThe `BitteAiChat` component can be integrated into your application with multiple blockchain connections:\n\n```tsx\nimport { BitteAiChat } from '@bitte-ai/chat';\nimport { useBitteWallet } from '@bitte-ai/react';\nimport { useAccount, useSendTransaction, useSwitchChain } from 'wagmi';\n\nconst YourChatComponent = () =\u003e {\n  // For NEAR connections\n  const { selector } = useBitteWallet();\n  const [wallet, setWallet] = useState\u003cWallet\u003e();\n\n  // For EVM connections via wagmi\n  const { address, chainId } = useAccount();\n  const { sendTransaction } = useSendTransaction();\n  const { switchChain } = useSwitchChain();\n\n  // EVM adapter\n  const evmAdapter = {\n    sendTransaction,\n    switchChain,\n    address,\n    chainId,\n  };\n\n  return (\n    \u003cBitteAiChat\n      options={{\n        agentName: \"Your Agent Name\",\n        agentImage: \"/your-agent-image.svg\",\n        colors: {\n          generalBackground: '#18181A',\n          messageBackground: '#000000',\n          textColor: '#FFFFFF',\n          buttonColor: '#0F172A',\n          borderColor: '#18181A',\n        },\n      }}\n      wallet={{\n        near: {\n          wallet: wallet, // Your NEAR wallet instance\n        },\n        evm: evmAdapter, // Your EVM adapter\n        // sui: { /* SUI wallet configuration */ }\n      }}\n      agentId=\"your-agent-id\"\n      apiUrl=\"/api/chat\"\n      historyApiUrl=\"/api/history\"\n    /\u003e\n  );\n};\n```\n\n## API Proxy Implementation\n\nCreate an API route at `pages/api/chat.ts` to proxy requests to the Bitte AI backend:\n\n```typescript\n// pages/api/chat.ts\nimport type { NextApiRequest, NextApiResponse } from 'next';\n\nconst {\n  BITTE_API_KEY,\n  BITTE_API_URL = 'https://ai-runtime-446257178793.europe-west1.run.app/chat',\n} = process.env;\n\nexport default async function handler(\n  req: NextApiRequest,\n  res: NextApiResponse\n) {\n  // Only allow POST requests\n  if (req.method !== 'POST') {\n    return res.status(405).json({ error: 'Method not allowed' });\n  }\n\n  try {\n    const data = req.body;\n\n    const requestInit: RequestInit = {\n      method: 'POST',\n      body: JSON.stringify(data),\n      headers: {\n        'Content-Type': 'application/json',\n        Authorization: `Bearer ${BITTE_API_KEY}`,\n      },\n    };\n\n    // Make the upstream request\n    const upstreamResponse = await fetch(`${BITTE_API_URL}`, requestInit);\n\n    // Set status code from upstream\n    res.statusCode = upstreamResponse.status;\n\n    // Copy relevant headers\n    for (const [key, value] of Object.entries(upstreamResponse.headers)) {\n      if (key.toLowerCase() !== 'content-encoding') {\n        res.setHeader(key, value as string);\n      }\n    }\n\n    // Handle streaming response\n    if (!upstreamResponse.body) {\n      return res.end();\n    }\n\n    // Stream the response\n    const reader = upstreamResponse.body.getReader();\n\n    async function readChunk() {\n      const { done, value } = await reader.read();\n      if (done) {\n        return res.end();\n      }\n      res.write(value);\n      await readChunk();\n    }\n\n    await readChunk();\n\n  } catch (error) {\n    console.error('Error in chat API route:', error);\n    res.status(500).json({ error: 'Internal Server Error' });\n  }\n}\n```\n\n## Environment Setup\n\nCreate a `.env.local` file with your Bitte API key:\n\n```\nBITTE_API_KEY=your-api-key-here\n```\n\n⚠️ **Official Recommendation**\n\nThe Vercel team explicitly [recommends using App Router](https://nextjs.org/docs/pages) for new projects. We strongly suggest using the [chat-boilerplate](https://github.com/BitteProtocol/chat-boilerplate) with App Router support instead of this implementation unless you have specific legacy requirements.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBitteProtocol%2Fchat-boilerplate-next-pages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBitteProtocol%2Fchat-boilerplate-next-pages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBitteProtocol%2Fchat-boilerplate-next-pages/lists"}