Skip to content

Extract shared MeeBot config and unify OpenAI/RPC handling across API endpoints#76

Open
MEECHAIN1 wants to merge 1 commit into
mainfrom
codex/check-for-duplicate-api-function-sets
Open

Extract shared MeeBot config and unify OpenAI/RPC handling across API endpoints#76
MEECHAIN1 wants to merge 1 commit into
mainfrom
codex/check-for-duplicate-api-function-sets

Conversation

@MEECHAIN1

@MEECHAIN1 MEECHAIN1 commented May 4, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Centralize MeeBot system prompt, model name and message-building logic to avoid duplication across endpoints.
  • Make OpenAI base URL and default RPC URL configurable via environment and normalize usage across handlers.
  • Simplify streaming and chat code by reusing shared utilities and reduce hardcoded RPC values.

Description

  • Added a shared module *_shared/meebot.js with MEEBOT_SYSTEM_PROMPT, MEEBOT_MODEL, getOpenAIBaseUrl, getDefaultRpcUrl, and buildChatMessages to encapsulate bot config and helpers.
  • Updated chat endpoints (/api/chat, /api/chat/stream) to import and use MEEBOT_MODEL, buildChatMessages and getOpenAIBaseUrl instead of inline prompt/model/base URL, and removed the unused sessionId parameter.
  • Replaced hardcoded RPC URLs in health.js, network.js, nodecloud/stats.js, and web3/status.js with getDefaultRpcUrl(env) and deduplicated rpcUrls in network.js using Array.from(new Set(...)).
  • Made minor formatting/consistency cleanups (header spacing, JSON whitespace) and preserved existing SSE streaming/parsing logic while sourcing messages from the shared prompt builder.

Testing

  • No automated tests were added or executed for this change.

Codex Task

Summary by CodeRabbit

บันทึกประจำรุ่น

  • Refactor
    • ปรับปรุงการจัดการการกำหนดค่า OpenAI และ RPC URL โดยรวมลอจิกร่วมกันเพื่อเพิ่มความสอดคล้องและลดการซ้ำซ้อน
    • ลดความซับซ้อนของเอนดพอยต์ API โดยแยกการสร้างข้อความแชทและการตั้งค่าโมเดลออกเป็นตัวช่วยที่ใช้ร่วมกัน
    • เพิ่มประสิทธิภาพการจัดการ URL fallback สำหรับการเชื่อมต่อ RPC

@vercel

vercel Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
connect.meechain Error Error May 4, 2026 4:14pm
mee-chain-connect Error Error May 4, 2026 4:14pm
meebot Error Error May 4, 2026 4:14pm
meechain Error Error May 4, 2026 4:14pm
meechain-connect Error Error May 4, 2026 4:14pm

Request Review

@railway-app

railway-app Bot commented May 4, 2026

Copy link
Copy Markdown

🚅 Deployed to the MeeChain-Connect-pr-76 environment in meechain

5 services not affected by this PR
  • Redis-wHAO
  • Postgres-X79I
  • Postgres
  • MeeChain
  • Redis

@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Code Review Analysis


Walkthrough

English:
A new shared meebot.js module is created exporting MeeBot system prompt, model name, and configuration helpers. Multiple API endpoints refactor to import and use these helpers instead of inline configurations, consolidating OpenAI base URL resolution, RPC URL selection, and chat message construction across the codebase.

ไทย:
มีการสร้างโมดูล meebot.js ที่ใช้ร่วมกันโดยส่งออก MeeBot system prompt, ชื่อโมเดล และฟังก์ชันช่วยเหลือสำหรับการตั้งค่า จากนั้น API endpoints หลายตัวจะทำการ refactor เพื่อนำเข้าและใช้ฟังก์ชันเหล่านี้แทนการตั้งค่าแบบ inline ซึ่งรวมการแก้ไข OpenAI base URL, การเลือก RPC URL และการสร้างข้อความแชตทั่วทั้ง codebase


Changes

Shared Configuration Extraction

Layer / File(s) Summary
Shared Constants & Helpers
cf-deploy/functions/api/_shared/meebot.js, functions/api/_shared/meebot.js
MEEBOT_SYSTEM_PROMPT (Thai-language bot persona) and MEEBOT_MODEL ('gpt-5-mini') constants are defined. getOpenAIBaseUrl(env) normalizes the OpenAI base URL with trailing-slash removal. getDefaultRpcUrl(env) resolves RPC URL from environment with fallback chain. buildChatMessages(userMessage) constructs a two-message array (system + user) for OpenAI chat completions.
Chat Endpoint Integration
cf-deploy/functions/api/chat.js, functions/api/chat.js
/api/chat handler imports shared helpers and replaces inline system prompt and hardcoded 'gpt-5-mini' with MEEBOT_MODEL and buildChatMessages(). Base URL is now derived via getOpenAIBaseUrl(env). Request parsing simplified to accept only { message } (dropping prior sessionId).
Streaming Chat Integration
cf-deploy/functions/api/chat/stream.js, functions/api/chat/stream.js
Streaming endpoint imports shared helpers, removes in-file SYSTEM_PROMPT constant, and updates upstream /chat/completions request to use MEEBOT_MODEL, buildChatMessages(), and getOpenAIBaseUrl(env)-derived baseURL. SSE transformation logic unchanged.
Health & Network RPC Integration
cf-deploy/functions/api/health.js, cf-deploy/functions/api/network.js, cf-deploy/functions/api/nodecloud/stats.js, cf-deploy/functions/api/web3/status.js
Health, network, nodecloud/stats, and web3/status endpoints import getDefaultRpcUrl() and replace inline RPC fallback logic (env.DRPC_RPC_URL || 'http://rpc.meechain.run.place') with centralized resolution. Network endpoint additionally builds deduplicated rpcUrls array from primary and fallback RPC values.

Estimated Code Review Effort

English:
🎯 2 (Simple) | ⏱️ ~12 minutes

Consistent refactoring pattern applied across multiple files: import shared helpers and replace inline configuration with function calls. Low logic density, straightforward extraction, and homogeneous repetitive changes across endpoints.

ไทย:
🎯 2 (Simple) | ⏱️ ~12 นาที

รูปแบบ refactoring ที่สอดคล้องกันถูกนำไปใช้ในหลายไฟล์: นำเข้า shared helpers และแทนที่การตั้งค่าแบบ inline ด้วยการเรียกฟังก์ชัน ความหนาแน่นของลอจิกต่ำ การแยกไฟล์ตรงไปตรงมา และการเปลี่ยนแปลงแบบทำซ้ำที่เป็นเนื้อเดียวกันในทั่วทั้ง endpoints


Possibly Related PRs

  • PR #57: Introduces centralized OpenAI configuration normalization (base URL trimming, defaults), directly related to this PR's getOpenAIBaseUrl() helper consolidation.
  • PR #7: Modifies MeeBot AI chat integration including system prompt, chat endpoints, and streaming—shares the same refactoring target of consolidating bot and OpenAI configuration.

Poem

English:

🤖 Meebot's wisdom now lives as one,
From scattered configs to helpers spun,
Thai whispers flow through shared domain,
RPC URLs dance without refrain—
No more repeats, one source of truth!

ไทย:

🤖 ปัญญา Meebot อยู่ในที่เดียว,
จากการตั้งค่าที่กระจายมารวมกัน,
เสียงไทยไหลผ่านที่ใช้ร่วมกัน,
URL ของ RPC เต้นรำโดยไม่มีท้ายขัด—
ไม่มีการซ้ำซากอีกต่อไป, แหล่งความจริงเพียงแหล่งเดียว!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objectives of the PR: extracting shared MeeBot configuration and unifying OpenAI/RPC handling across multiple API endpoints.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/check-for-duplicate-api-function-sets
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch codex/check-for-duplicate-api-function-sets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
meechain-connect d40b804 May 04 2026, 04:14 PM

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
cf-deploy/functions/api/health.js (1)

1-1: ⚡ Quick win

🔧 model ยังคง hardcode ไว้ — ควรใช้ MEEBOT_MODEL จาก shared module

English: The PR centralises MEEBOT_MODEL in the shared module, but line 12 still holds a raw string 'gpt-5-mini'. If the model is bumped in meebot.js, this response field will silently drift out of sync. Import and reuse the constant.

ภาษาไทย: PR นี้มีเป้าหมายรวมชื่อ model ไว้ที่เดียว แต่บรรทัด 12 ยังใช้ string ตรงๆ 'gpt-5-mini' หาก model ถูกเปลี่ยนใน meebot.js ค่า response ของ health endpoint จะเก่าโดยไม่มีการเตือน ควร import และใช้ constant แทน

🛠️ Proposed fix
-import { getDefaultRpcUrl } from './_shared/meebot.js';
+import { getDefaultRpcUrl, MEEBOT_MODEL } from './_shared/meebot.js';
 
 // ...
   const data = {
     status:    'ok',
-    model:     'gpt-5-mini',
+    model:     MEEBOT_MODEL,

Also applies to: 12-12

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cf-deploy/functions/api/health.js` at line 1, The health endpoint currently
hardcodes the model string instead of using the shared constant; import
MEEBOT_MODEL from the same module where getDefaultRpcUrl is imported
(./_shared/meebot.js) and replace the raw 'gpt-5-mini' value in the health
response with MEEBOT_MODEL so the endpoint stays in sync with the centralized
model constant.
cf-deploy/functions/api/_shared/meebot.js (1)

8-8: 💤 Low value

💡 (Optional) RPC URL ใน system prompt ไม่ตรงกับ runtime config ที่อาจเปลี่ยนได้

English: The RPC URL https://rpc.meechain.live is hardcoded inside the prompt string itself (line 8), while getDefaultRpcUrl(env) allows it to be overridden via DRPC_RPC_URL. If the runtime RPC differs from the one in the prompt, MeeBot's self-described knowledge will be stale. Consider injecting the live URL at build/render time, or note in comments that this string must be kept in sync manually.

ภาษาไทย: URL ของ RPC ในบรรทัดที่ 8 ถูก hardcode ไว้ใน string ของ prompt โดยตรง ในขณะที่ getDefaultRpcUrl(env) ช่วยให้เปลี่ยนได้ผ่าน env var DRPC_RPC_URL หาก RPC จริงในตอน runtime ต่างจากที่อยู่ใน prompt MeeBot จะให้ข้อมูลที่ล้าสมัย ควรพิจารณาใส่ค่านี้แบบ dynamic หรืออย่างน้อยเพิ่ม comment เตือนให้ sync ด้วยตัวเอง

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cf-deploy/functions/api/_shared/meebot.js` at line 8, The system prompt in
meebot.js hardcodes "https://rpc.meechain.live" which can diverge from the
runtime value returned by getDefaultRpcUrl(env); update the prompt construction
to use the live RPC URL from getDefaultRpcUrl(env) (or DRPC_RPC_URL) instead of
the hardcoded string so the prompt reflects the actual runtime RPC, e.g.,
replace the static RPC text in the prompt string with the variable returned by
getDefaultRpcUrl(env) at build/render time; if you can't make it dynamic, add a
clear comment next to the prompt string reminding maintainers to keep it synced
with getDefaultRpcUrl(env)/DRPC_RPC_URL.
cf-deploy/functions/api/chat/stream.js (1)

88-107: ⚡ Quick win

💡 (Pre-existing) done: true ถูกส่งซ้ำสองครั้งต่อ stream

English: This is pre-existing behaviour, not introduced by this PR, but worth noting: when the upstream sends [DONE], line 91 writes { done: true } and then continues the loop. The finally block at line 104 unconditionally writes another { done: true }. Every stream ends with two consecutive done events. Clients that guard against duplicate done signals are unaffected, but this could cause a double-close attempt or unexpected state in more strict consumers.

ภาษาไทย: นี่เป็น behavior ที่มีอยู่เดิมก่อน PR นี้ แต่ควรทราบไว้: เมื่อ upstream ส่ง [DONE] บรรทัดที่ 91 จะส่ง { done: true } และ continue ต่อไป จากนั้น finally block ที่บรรทัด 104 จะส่ง { done: true } อีกครั้งโดยไม่มีเงื่อนไข ทุก stream จึงจบด้วย done event สองครั้งติดกัน

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cf-deploy/functions/api/chat/stream.js` around lines 88 - 107, The stream
currently emits { done: true } twice: once when seeing raw === '[DONE]' inside
the data parsing loop and again unconditionally in the finally block; fix this
by ensuring only one done is sent—either remove the write when handling raw ===
'[DONE]' and break/return to let the finally block emit the single done, or add
a boolean flag (e.g., sentDone) checked/updated in the data handling code and in
the finally block so the writer.write(encoder.encode(JSON.stringify({ done: true
}))) runs only once; update the code paths around the data parsing loop and the
finally block (references: the data parsing loop that checks
line.startsWith('data: ') and raw === '[DONE]', the writer and encoder usages,
and the finally block that writes done and closes the writer).
functions/api/_shared/meebot.js (1)

1-34: ⚖️ Poor tradeoff

🔧 ไฟล์นี้ซ้ำกับ cf-deploy/functions/api/_shared/meebot.js แต่ขาด getDefaultRpcUrl

English: functions/api/_shared/meebot.js and cf-deploy/functions/api/_shared/meebot.js are nearly identical, but this file omits getDefaultRpcUrl. While neither handler under functions/api/ currently needs it, the two files will silently diverge as the codebase evolves. Consider whether both deployment targets (functions/ and cf-deploy/) can share a single source file (e.g., via a symlink or a workspace-level module), or at minimum add a comment noting that both files must be kept in sync.

ภาษาไทย: ไฟล์ functions/api/_shared/meebot.js และ cf-deploy/functions/api/_shared/meebot.js มีเนื้อหาเกือบเหมือนกัน แต่ไฟล์นี้ไม่มี getDefaultRpcUrl แม้ handler ปัจจุบันภายใต้ functions/api/ จะยังไม่ต้องการฟังก์ชันนี้ แต่ทั้งสองไฟล์จะค่อยๆ แตกต่างกันโดยไม่ได้ตั้งใจ ควรพิจารณาใช้ไฟล์ source เดียวกัน (เช่น symlink หรือ workspace module) หรืออย่างน้อยเพิ่ม comment เตือนให้ sync ทั้งสองไฟล์เสมอ

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/api/_shared/meebot.js` around lines 1 - 34, This file duplicates
cf-deploy/functions/api/_shared/meebot.js but omits getDefaultRpcUrl, which will
cause silent drift; either (A) restore/add the missing getDefaultRpcUrl function
to this file (matching the implementation in cf-deploy), or (B) consolidate both
locations into a single shared module (or symlink) so MEEBOT_SYSTEM_PROMPT,
MEEBOT_MODEL, getOpenAIBaseUrl, buildChatMessages and the missing
getDefaultRpcUrl live in one source; if you choose to keep two copies, add a
clear top-of-file comment referencing the sibling file and reminding maintainers
to keep them in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cf-deploy/functions/api/network.js`:
- Around line 11-17: The rpcUrls can collapse to a single entry because
fallbackRpc is computed as env.VITE_RPC_URL || primaryRpc; update the fallback
computation in getDefaultRpcUrl usage so it prefers a distinct configured
fallback (e.g. env.DRPC_RPC_URL) before falling back to primary: set fallbackRpc
= env.VITE_RPC_URL || env.DRPC_RPC_URL || primaryRpc, then build rpcUrls from
[primaryRpc, fallbackRpc] and if they are identical, ensure you still supply two
entries (for example by using the configured fallback if present or appending a
no-op query param to the second URL) so wallet_addEthereumChain consumers always
receive two URLs; adjust the code around primaryRpc, fallbackRpc and rpcUrls
accordingly.

In `@functions/api/chat.js`:
- Line 3: Update the stale header comment that hardcodes "powered by OpenAI
GPT-5-mini": change the banner in functions/api/chat.js to not hardcode the
model name and instead state that the model is configurable/comes from
MEEBOT_MODEL (shared module) or leave a neutral phrase like "model determined by
MEEBOT_MODEL"; search for the header comment text "// ║  MeeBot AI — powered by
OpenAI GPT-5-mini           ║" and replace it with a generic, accurate line that
references MEEBOT_MODEL or "environment-configured model" so the comment remains
correct when the environment variable changes.

---

Nitpick comments:
In `@cf-deploy/functions/api/_shared/meebot.js`:
- Line 8: The system prompt in meebot.js hardcodes "https://rpc.meechain.live"
which can diverge from the runtime value returned by getDefaultRpcUrl(env);
update the prompt construction to use the live RPC URL from
getDefaultRpcUrl(env) (or DRPC_RPC_URL) instead of the hardcoded string so the
prompt reflects the actual runtime RPC, e.g., replace the static RPC text in the
prompt string with the variable returned by getDefaultRpcUrl(env) at
build/render time; if you can't make it dynamic, add a clear comment next to the
prompt string reminding maintainers to keep it synced with
getDefaultRpcUrl(env)/DRPC_RPC_URL.

In `@cf-deploy/functions/api/chat/stream.js`:
- Around line 88-107: The stream currently emits { done: true } twice: once when
seeing raw === '[DONE]' inside the data parsing loop and again unconditionally
in the finally block; fix this by ensuring only one done is sent—either remove
the write when handling raw === '[DONE]' and break/return to let the finally
block emit the single done, or add a boolean flag (e.g., sentDone)
checked/updated in the data handling code and in the finally block so the
writer.write(encoder.encode(JSON.stringify({ done: true }))) runs only once;
update the code paths around the data parsing loop and the finally block
(references: the data parsing loop that checks line.startsWith('data: ') and raw
=== '[DONE]', the writer and encoder usages, and the finally block that writes
done and closes the writer).

In `@cf-deploy/functions/api/health.js`:
- Line 1: The health endpoint currently hardcodes the model string instead of
using the shared constant; import MEEBOT_MODEL from the same module where
getDefaultRpcUrl is imported (./_shared/meebot.js) and replace the raw
'gpt-5-mini' value in the health response with MEEBOT_MODEL so the endpoint
stays in sync with the centralized model constant.

In `@functions/api/_shared/meebot.js`:
- Around line 1-34: This file duplicates
cf-deploy/functions/api/_shared/meebot.js but omits getDefaultRpcUrl, which will
cause silent drift; either (A) restore/add the missing getDefaultRpcUrl function
to this file (matching the implementation in cf-deploy), or (B) consolidate both
locations into a single shared module (or symlink) so MEEBOT_SYSTEM_PROMPT,
MEEBOT_MODEL, getOpenAIBaseUrl, buildChatMessages and the missing
getDefaultRpcUrl live in one source; if you choose to keep two copies, add a
clear top-of-file comment referencing the sibling file and reminding maintainers
to keep them in sync.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8b192753-646b-4ac2-a6eb-4dfe1152abd5

📥 Commits

Reviewing files that changed from the base of the PR and between eab378a and d40b804.

📒 Files selected for processing (10)
  • cf-deploy/functions/api/_shared/meebot.js
  • cf-deploy/functions/api/chat.js
  • cf-deploy/functions/api/chat/stream.js
  • cf-deploy/functions/api/health.js
  • cf-deploy/functions/api/network.js
  • cf-deploy/functions/api/nodecloud/stats.js
  • cf-deploy/functions/api/web3/status.js
  • functions/api/_shared/meebot.js
  • functions/api/chat.js
  • functions/api/chat/stream.js

Comment on lines +11 to +17
const primaryRpc = getDefaultRpcUrl(env);
const fallbackRpc = env.VITE_RPC_URL || primaryRpc;

const data = {
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: [
env.DRPC_RPC_URL || 'http://rpc.meechain.run.place',
env.VITE_RPC_URL || 'https://ritual-chain--pouaun2499.replit.app',
],
nativeCurrency: { name: 'MEE Token', symbol: 'MEE', decimals: 18 },
blockExplorerUrls:['http://explorer.meechain.run.place'],
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: Array.from(new Set([primaryRpc, fallbackRpc])),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

⚠️ rpcUrls อาจมีแค่รายการเดียวเมื่อ VITE_RPC_URL ไม่ได้ถูกกำหนด

English: fallbackRpc is derived as env.VITE_RPC_URL || primaryRpc. When only DRPC_RPC_URL is set (the typical production configuration per server.js), env.VITE_RPC_URL is undefined, so fallbackRpc === primaryRpc. The Set deduplication then produces a single-entry rpcUrls array instead of two. This is a behaviour regression — clients relying on this endpoint for wallet_addEthereumChain (MetaMask) or multi-RPC fallover lose their backup endpoint.

ภาษาไทย: fallbackRpc ถูกคำนวณจาก env.VITE_RPC_URL || primaryRpc เมื่อตั้งค่าแค่ DRPC_RPC_URL (กรณี production ทั่วไปตาม server.js) ตัวแปร env.VITE_RPC_URL จะเป็น undefined ทำให้ fallbackRpc === primaryRpc และหลังจาก dedup ด้วย Set แล้ว rpcUrls จะมีแค่รายการเดียว ส่งผลให้ client ที่ใช้ endpoint นี้สำหรับ wallet_addEthereumChain (MetaMask) หรือ multi-RPC fallover สูญเสีย backup endpoint ไป

ตัวอย่างการแก้ไขที่ให้ fallback URL ที่แตกต่างเสมอ:

🛠️ Proposed fix
  const primaryRpc = getDefaultRpcUrl(env);
- const fallbackRpc = env.VITE_RPC_URL || primaryRpc;
+ // Use a dedicated fallback that is distinct from primaryRpc; only deduplicate
+ // if both happen to resolve to the same string.
+ const fallbackRpc = env.VITE_RPC_URL
+   || env.DRPC_RPC_URL
+   || 'https://rpc.meechain.run.place';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cf-deploy/functions/api/network.js` around lines 11 - 17, The rpcUrls can
collapse to a single entry because fallbackRpc is computed as env.VITE_RPC_URL
|| primaryRpc; update the fallback computation in getDefaultRpcUrl usage so it
prefers a distinct configured fallback (e.g. env.DRPC_RPC_URL) before falling
back to primary: set fallbackRpc = env.VITE_RPC_URL || env.DRPC_RPC_URL ||
primaryRpc, then build rpcUrls from [primaryRpc, fallbackRpc] and if they are
identical, ensure you still supply two entries (for example by using the
configured fallback if present or appending a no-op query param to the second
URL) so wallet_addEthereumChain consumers always receive two URLs; adjust the
code around primaryRpc, fallbackRpc and rpcUrls accordingly.

Comment thread functions/api/chat.js
@@ -3,56 +3,22 @@
// ║ MeeBot AI — powered by OpenAI GPT-5-mini ║

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

แก้ไข comment ส่วนหัวที่ล้าสมัย / Fix stale banner comment

ภาษาไทย: บรรทัดที่ 3 ยังระบุ "powered by OpenAI GPT-5-mini" แบบ hardcode ในขณะที่โมเดลที่ใช้จริงตอนนี้มาจาก MEEBOT_MODEL ใน shared module ซึ่งสามารถเปลี่ยนแปลงได้ผ่าน environment โดยที่ comment นี้จะยังคงแสดงชื่อโมเดลผิดอยู่

English: Line 3 still hardcodes "GPT-5-mini" in the banner, but the actual model is now driven by MEEBOT_MODEL from the shared module, which is configurable. This comment will mislead anyone reading the file header after an environment-driven model change.

✏️ Proposed fix
-// ║  MeeBot AI — powered by OpenAI GPT-5-mini           ║
+// ║  MeeBot AI — model configured via MEEBOT_MODEL      ║
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// ║ MeeBot AI — powered by OpenAI GPT-5-mini
// ║ MeeBot AI — model configured via MEEBOT_MODEL
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/api/chat.js` at line 3, Update the stale header comment that
hardcodes "powered by OpenAI GPT-5-mini": change the banner in
functions/api/chat.js to not hardcode the model name and instead state that the
model is configurable/comes from MEEBOT_MODEL (shared module) or leave a neutral
phrase like "model determined by MEEBOT_MODEL"; search for the header comment
text "// ║  MeeBot AI — powered by OpenAI GPT-5-mini           ║" and replace it
with a generic, accurate line that references MEEBOT_MODEL or
"environment-configured model" so the comment remains correct when the
environment variable changes.

@@ -0,0 +1,33 @@
export const MEEBOT_SYSTEM_PROMPT = `คุณคือ "MeeBot" — AI Assistant ผู้ช่วยอัจฉริยะของแพลตฟอร์ม MeeChain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The functions/api/_shared/meebot.js file is missing the getDefaultRpcUrl function that exists in cf-deploy/functions/api/_shared/meebot.js, creating an inconsistency between versions

Fix on Vercel

Comment on lines +12 to +17
const fallbackRpc = env.VITE_RPC_URL || primaryRpc;

const data = {
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: [
env.DRPC_RPC_URL || 'http://rpc.meechain.run.place',
env.VITE_RPC_URL || 'https://ritual-chain--pouaun2499.replit.app',
],
nativeCurrency: { name: 'MEE Token', symbol: 'MEE', decimals: 18 },
blockExplorerUrls:['http://explorer.meechain.run.place'],
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: Array.from(new Set([primaryRpc, fallbackRpc])),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const fallbackRpc = env.VITE_RPC_URL || primaryRpc;
const data = {
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: [
env.DRPC_RPC_URL || 'http://rpc.meechain.run.place',
env.VITE_RPC_URL || 'https://ritual-chain--pouaun2499.replit.app',
],
nativeCurrency: { name: 'MEE Token', symbol: 'MEE', decimals: 18 },
blockExplorerUrls:['http://explorer.meechain.run.place'],
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: Array.from(new Set([primaryRpc, fallbackRpc])),
// Ensure fallback is different from primary to maintain redundancy
// Priority: DRPC_RPC_URL → VITE_RPC_URL → default fallback
let fallbackRpc;
if (env.DRPC_RPC_URL && env.VITE_RPC_URL && env.DRPC_RPC_URL !== env.VITE_RPC_URL) {
// Both are set and different, use the one not in primaryRpc
fallbackRpc = primaryRpc === env.DRPC_RPC_URL ? env.VITE_RPC_URL : env.DRPC_RPC_URL;
} else if (env.VITE_RPC_URL && primaryRpc !== env.VITE_RPC_URL) {
// Use VITE_RPC_URL if it's different from primary
fallbackRpc = env.VITE_RPC_URL;
} else if (primaryRpc !== 'https://rpc.meechain.live') {
// Default fallback is different from primary
fallbackRpc = 'https://rpc.meechain.live';
} else {
// Fallback to historical URL when primary is the default
fallbackRpc = 'https://ritual-chain--pouaun2499.replit.app';
}
const data = {
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: [primaryRpc, fallbackRpc],

Refactored rpcUrls array logic can result in duplicate URLs, reducing failover capability to a single RPC endpoint

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant