Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/quickstart/.env.example
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
Comment thread
cursor[bot] marked this conversation as resolved.
2 changes: 2 additions & 0 deletions sdk/quickstart/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
.env
*.log
5 changes: 3 additions & 2 deletions sdk/quickstart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"typescript": "^6.0.3"
},
"dependencies": {
"@cursor/sdk": "^1.0.7"
"@cursor/sdk": "^1.0.7",
"dotenv": "^17.4.2"
}
}
}
19 changes: 19 additions & 0 deletions sdk/quickstart/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 28 additions & 16 deletions sdk/quickstart/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
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);
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stream output regresses from text extraction to raw events

Medium Severity · Logic Bug

The refactored stream loop replaces the previous assistant-text extraction logic (event.type === "assistant"block.type === "text"process.stdout.write(block.text)) with a bare console.log(event). This dumps raw event objects for all event types instead of streaming clean assistant text. Every other SDK example in the repo (coding-agent-cli, app-builder, dag-task-runner) filters for assistant text blocks. The README still describes this quickstart as one that "streams assistant text to stdout," which no longer matches the actual behavior.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2a07066. Configure here.

}

await run.wait();
}

await run.wait()
main().catch((err) => {
console.error("An error occurred:", err);
process.exit(1);
});