-
Notifications
You must be signed in to change notification settings - Fork 66
Add .cursor/rules/echo_rules.mdc to echo-start templates #766
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
Open
Halo11112222
wants to merge
3
commits into
Merit-Systems:master
Choose a base branch
from
Halo11112222:feat/add-cursor-rules-echo-template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| description: Echo SDK guidelines for CLI tools — user-pays AI infrastructure | ||
| globs: **/*.ts,**/*.js | ||
| --- | ||
|
|
||
| # Echo SDK Guidelines (CLI) | ||
|
|
||
| Echo lets CLI tools authenticate users and let them pay for their own AI usage. | ||
|
|
||
| ## Authentication | ||
|
|
||
| Use Echo's auth functions for CLI login flow: | ||
|
|
||
| ```typescript | ||
| import { loginWithEcho, logout, isAuthenticated } from '@/auth'; | ||
|
|
||
| // Login | ||
| await loginWithEcho(); | ||
|
|
||
| // Check auth | ||
| if (await isAuthenticated()) { | ||
| // proceed | ||
| } | ||
|
|
||
| // Logout | ||
| await logout(); | ||
| ``` | ||
|
|
||
| ## Wallet management | ||
|
|
||
| ```typescript | ||
| import { | ||
| initLocalWallet, | ||
| loginWithWallet, | ||
|
Comment on lines
+32
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| showLocalWalletBalance, | ||
| showLocalWalletAddress, | ||
| exportPrivateKey, | ||
| fundWallet | ||
| } from '@/core'; | ||
| ``` | ||
|
|
||
| ## Key rules | ||
|
|
||
| - Use `@merit-systems/echo-sdk` for CLI applications | ||
| - Use `commander` for CLI argument parsing | ||
| - Use `@clack/prompts` for interactive prompts | ||
| - Handle `isCancel` from prompts to allow graceful exit | ||
| - Store auth tokens securely, never log them | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| description: Echo SDK guidelines for Next.js — user-pays AI infrastructure | ||
| globs: **/*.ts,**/*.tsx,**/*.js,**/*.jsx | ||
| --- | ||
|
|
||
| # Echo SDK Guidelines (Next.js) | ||
|
|
||
| Echo lets users pay for their own AI usage — you never front API costs. Replace standard AI SDK imports with Echo and earn revenue via markup. | ||
|
|
||
| ## Setup | ||
|
|
||
| ### Server-side configuration | ||
| Create `src/echo/index.ts` and initialize Echo: | ||
|
|
||
| ```typescript | ||
| import Echo from '@merit-systems/echo-next-sdk'; | ||
|
|
||
| export const { handlers, isSignedIn, openai, anthropic } = Echo({ | ||
| appId: process.env.ECHO_APP_ID!, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Client-side provider | ||
| Wrap your app in `EchoProvider` in your layout or providers file: | ||
|
|
||
| ```typescript | ||
| 'use client'; | ||
| import { EchoProvider } from '@merit-systems/echo-next-sdk/client'; | ||
|
|
||
| export function Providers({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <EchoProvider config={{ appId: process.env.NEXT_PUBLIC_ECHO_APP_ID! }}> | ||
| {children} | ||
| </EchoProvider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### Environment variables | ||
| - `ECHO_APP_ID` — Server-side app ID (from echo.merit.systems) | ||
| - `NEXT_PUBLIC_ECHO_APP_ID` — Client-side app ID (same value, must be prefixed with NEXT_PUBLIC_) | ||
|
|
||
| ## Using Echo model providers | ||
|
|
||
| Import model providers from your Echo config instead of directly from the AI SDK: | ||
|
|
||
| ```typescript | ||
| import { openai, anthropic } from '@/echo'; | ||
| import { generateText } from 'ai'; | ||
|
|
||
| const response = await generateText({ | ||
| model: openai('gpt-4o'), | ||
| prompt: '...', | ||
| }); | ||
| ``` | ||
|
|
||
| Do NOT hardcode API keys — Echo handles authentication and billing. | ||
|
|
||
| ## UI components | ||
|
|
||
| ### Token balance display | ||
| Use `EchoTokens` to show user balance and login: | ||
|
|
||
| ```typescript | ||
| 'use client'; | ||
| import { EchoTokens } from '@merit-systems/echo-next-sdk/client'; | ||
|
|
||
| export function EchoButton() { | ||
| return <EchoTokens />; | ||
| } | ||
| ``` | ||
|
|
||
| ## API routes | ||
|
|
||
| Register the Echo auth handler in `src/app/api/echo/[...echo]/route.ts`: | ||
|
|
||
| ```typescript | ||
| import { handlers } from '@/echo'; | ||
| export const { GET, POST } = handlers; | ||
| ``` | ||
|
|
||
| ## Key rules | ||
|
|
||
| - ALWAYS use `@merit-systems/echo-next-sdk` for Next.js apps (not the React or plain SDK) | ||
| - ALWAYS wrap the app in `EchoProvider` on the client side | ||
| - ALWAYS use the server-side Echo config for AI model providers | ||
| - NEVER hardcode API keys — Echo manages authentication | ||
| - Use `'use client'` directive for components importing from `echo-next-sdk/client` | ||
| - The `EchoTokens` component handles OAuth login flow and balance display |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| description: Echo SDK guidelines for React — user-pays AI infrastructure | ||
| globs: **/*.ts,**/*.tsx,**/*.js,**/*.jsx | ||
| --- | ||
|
|
||
| # Echo SDK Guidelines (React) | ||
|
|
||
| Echo lets users pay for their own AI usage — you never front API costs. Replace standard AI SDK imports with Echo and earn revenue via markup. | ||
|
|
||
| ## Setup | ||
|
|
||
| ### Provider setup | ||
| Wrap your app in `EchoProvider` in `main.tsx`: | ||
|
|
||
| ```typescript | ||
| import { EchoProvider } from '@merit-systems/echo-react-sdk'; | ||
|
|
||
| createRoot(document.getElementById('root')!).render( | ||
| <StrictMode> | ||
| <EchoProvider config={{ appId: import.meta.env.VITE_ECHO_APP_ID! }}> | ||
| <App /> | ||
| </EchoProvider> | ||
| </StrictMode> | ||
| ); | ||
| ``` | ||
|
|
||
| ### Environment variables | ||
| - `VITE_ECHO_APP_ID` — App ID from echo.merit.systems (Vite requires VITE_ prefix) | ||
|
|
||
| ## Using Echo model providers | ||
|
|
||
| ```typescript | ||
| import { useEchoModelProviders } from '@merit-systems/echo-react-sdk'; | ||
| import { generateText } from 'ai'; | ||
|
|
||
| function MyComponent() { | ||
| const { openai } = useEchoModelProviders(); | ||
|
|
||
| const handleGenerate = async () => { | ||
| const response = await generateText({ | ||
| model: openai('gpt-4o'), | ||
| prompt: '...', | ||
| }); | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| ## UI components | ||
|
|
||
| ```typescript | ||
| import { EchoTokens } from '@merit-systems/echo-react-sdk'; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <> | ||
| <h1>My App</h1> | ||
| <EchoTokens /> | ||
| </> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Key rules | ||
|
|
||
| - ALWAYS use `@merit-systems/echo-react-sdk` for React apps (not the Next.js SDK) | ||
| - ALWAYS wrap the app in `EchoProvider` at the root | ||
| - Use `useEchoModelProviders()` hook to get AI model providers | ||
| - NEVER hardcode API keys — Echo manages authentication | ||
| - Use `EchoTokens` component for user balance and login UI |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Cursor rules documentation shows incorrect import path for
isAuthenticated- it should be from@/utils, not@/auth.