-
Notifications
You must be signed in to change notification settings - Fork 41
X402 Credit Spend with Echo Balance #614
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
base: master
Are you sure you want to change the base?
Conversation
|
🚅 Deployed to the echo-pr-614 environment in echo
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
| getGloriaNews({ feed_categories: 'base' }, ECHO_API_KEY); | ||
| postTrueCastRequest( | ||
| 'Was donald trump the first president of the united states?', | ||
| ECHO_API_KEY | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| getGloriaNews({ feed_categories: 'base' }, ECHO_API_KEY); | |
| postTrueCastRequest( | |
| 'Was donald trump the first president of the united states?', | |
| ECHO_API_KEY | |
| ); | |
| getGloriaNews({ feed_categories: 'base' }, ECHO_API_KEY).then(() => { | |
| console.log('done'); | |
| }).catch((error) => { | |
| console.error('Error making getGloriaNews request:', error); | |
| }); | |
| postTrueCastRequest( | |
| 'Was donald trump the first president of the united states?', | |
| ECHO_API_KEY | |
| ).then(() => { | |
| console.log('done'); | |
| }).catch((error) => { | |
| console.error('Error making postTrueCastRequest:', error); | |
| }); |
The module-level code at the end of the file executes async functions without awaiting them, which will cause unhandled promise rejections if these functions fail and cannot be debugged properly.
View Details
Analysis
Unhandled promise rejections in echo-credit-client.ts module-level code
What fails: Module-level async function calls getGloriaNews() and postTrueCastRequest() at lines 75-79 in packages/app/server/src/clients/echo-credit-client.ts cause unhandled promise rejections when ECHO_API_KEY environment variable is missing
How to reproduce:
# Import module without ECHO_API_KEY set:
cd packages/app/server && pnpm exec tsx -e "import('./src/clients/echo-credit-client.ts')"Result: Process crashes with "UNHANDLED PROMISE REJECTION DETECTED: Error: ECHO_API_KEY is required" - both functions throw but have no .catch() handlers
Expected: Errors should be caught and handled gracefully like all other client files in the same directory, which use .then().catch() patterns for module-level async calls
| export async function postTrueCastRequest( | ||
| prompt: string, | ||
| apiKey?: string | ||
| ): Promise<string> { | ||
| const key = apiKey || ECHO_API_KEY; | ||
|
|
||
| if (!key) { | ||
| throw new Error('ECHO_API_KEY is required'); | ||
| } | ||
|
|
||
| const trueCastBody: TrueCastRequest = { prompt }; | ||
|
|
||
| const response = await fetch( | ||
| `${ECHO_ROUTER_BASE_URL}/x402?proxy=${encodeURIComponent(TRUECAST_URL)}`, | ||
| { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${key}`, | ||
| }, | ||
| body: JSON.stringify(trueCastBody), | ||
| } | ||
| ); | ||
| console.log('response', response.status); | ||
| const data = await response.json(); | ||
| console.log('data', data); | ||
| return data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The postTrueCastRequest function is declared to return Promise<string> but actually returns the parsed JSON response object, not a string. The same issue exists in getGloriaNews on line 45.
View Details
📝 Patch Details
diff --git a/packages/app/server/src/clients/echo-credit-client.ts b/packages/app/server/src/clients/echo-credit-client.ts
index aeb674ae..c55a261e 100644
--- a/packages/app/server/src/clients/echo-credit-client.ts
+++ b/packages/app/server/src/clients/echo-credit-client.ts
@@ -16,7 +16,7 @@ interface GloriaNewsParams {
export async function postTrueCastRequest(
prompt: string,
apiKey?: string
-): Promise<string> {
+): Promise<any> {
const key = apiKey || ECHO_API_KEY;
if (!key) {
@@ -45,7 +45,7 @@ export async function postTrueCastRequest(
export async function getGloriaNews(
params: GloriaNewsParams = { feed_categories: 'base' },
apiKey?: string
-): Promise<string> {
+): Promise<any> {
const key = apiKey || ECHO_API_KEY;
if (!key) {
Analysis
Type mismatch in postTrueCastRequest() and getGloriaNews() return types
What fails: Functions postTrueCastRequest() and getGloriaNews() in packages/app/server/src/clients/echo-credit-client.ts declare return type Promise<string> but actually return Promise<any> (parsed JSON objects)
How to reproduce:
// Functions call response.json() which returns Promise<any>, not Promise<string>
const data = await response.json(); // Returns object, not string
return data; // Type mismatch: returning object where Promise<string> expectedResult: TypeScript type checker allows incorrect type assumptions. Calling code expecting strings would receive objects at runtime.
Expected: Return type should be Promise<any> to match actual behavior per TypeScript fetch documentation - response.json() returns Promise<any>
Echo Balance can act as a creditor for x402 resources. This PR will enable you to spend your echo balance on x402 resources.