-
Notifications
You must be signed in to change notification settings - Fork 464
feat: add dotenv support and environment validation #23
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: main
Are you sure you want to change the base?
Changes from 2 commits
e339b18
da2ef65
2a07066
463fb5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copy this file to .env and fill in your key | ||
| CURSOR_API_KEY = your_api_key_here | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,32 @@ | ||
| import { Agent } from "@cursor/sdk" | ||
| import { Agent } from "@cursor/sdk"; | ||
| import * as dotenv from "dotenv"; | ||
|
|
||
| const agent = await Agent.create({ | ||
| apiKey: process.env.CURSOR_API_KEY, | ||
| name: "SDK quickstart", | ||
| model: { id: process.env.CURSOR_MODEL ?? "composer-2" }, | ||
| local: { cwd: process.cwd() }, | ||
| }) | ||
| // Load variables from .env into process.env | ||
| dotenv.config(); | ||
|
|
||
| const prompt = "Explain this project in one paragraph." | ||
| const run = await agent.send(prompt) | ||
| async function main() { | ||
| const apiKey = process.env.CURSOR_API_KEY; | ||
|
|
||
| for await (const event of run.stream()) { | ||
| if (event.type !== "assistant") continue | ||
| if (!apiKey) { | ||
| console.error("Error: CURSOR_API_KEY is not set in environment variables."); | ||
| console.log("Please copy .env.example to .env and fill in your API key."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const agent = await Agent.create({ | ||
| apiKey, | ||
| name: "SDK quickstart", | ||
| model: { id: process.env.CURSOR_MODEL ?? "composer-2" }, | ||
| local: { cwd: process.cwd() }, | ||
| }); | ||
|
|
||
| for (const block of event.message.content) { | ||
| if (block.type === "text") { | ||
| process.stdout.write(block.text) | ||
| } | ||
| const run = await agent.send("Summarize what this repository does"); | ||
|
|
||
| for await (const event of run.stream()) { | ||
| console.log(event); | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
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. Stream output regresses from text extraction to raw eventsMedium Severity · Logic Bug The refactored stream loop replaces the previous assistant-text extraction logic ( Reviewed by Cursor Bugbot for commit 2a07066. Configure here. |
||
| } | ||
|
|
||
| await run.wait(); | ||
| } | ||
|
|
||
| await run.wait() | ||
| main().catch(console.error); | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||


Uh oh!
There was an error while loading. Please reload this page.