Skip to content

Commit e29f1d4

Browse files
committed
Fixes
1 parent 0ad83fd commit e29f1d4

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

cursor-cli-demo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Type a prompt, pick a model, and watch the agent create files and write code fro
1212
4. NDJSON output from stdout is parsed and piped to a Realtime Stream
1313
5. `useRealtimeRunWithStreams` renders each event live in a terminal panel
1414

15-
```
15+
```text
1616
[Browser] <-- Realtime Streams v2 --> [Trigger.dev Cloud]
1717
| |
1818
| POST /api/trigger | task.trigger()
@@ -70,7 +70,7 @@ The build extension in `trigger.config.ts` installs `cursor-agent` into the cont
7070

7171
## Project structure
7272

73-
```
73+
```text
7474
├── app/
7575
│ ├── layout.tsx # Root layout with Geist fonts
7676
│ ├── page.tsx # Main UI: control bar + terminal

cursor-cli-demo/app/api/trigger/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import { tasks } from "@trigger.dev/sdk";
22
import type { cursorAgentTask } from "@/trigger/cursor-agent";
33

44
export async function POST(req: Request) {
5-
const body = await req.json();
6-
const prompt = typeof body.prompt === "string" ? body.prompt.trim() : "";
7-
const model = typeof body.model === "string" ? body.model : undefined;
5+
let body: unknown;
6+
try {
7+
body = await req.json();
8+
} catch {
9+
return Response.json({ error: "invalid JSON" }, { status: 400 });
10+
}
11+
12+
const parsed = body as Record<string, unknown>;
13+
const prompt = typeof parsed.prompt === "string" ? parsed.prompt.trim() : "";
14+
const model = typeof parsed.model === "string" ? parsed.model : undefined;
815

916
if (!prompt) {
1017
return Response.json({ error: "prompt is required" }, { status: 400 });

cursor-cli-demo/components/terminal.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ export function Terminal({
3636
userScrolledUp.current = !atBottom;
3737
}, []);
3838

39+
const status = run?.status;
40+
const isRunning = status === "EXECUTING";
41+
const isQueued = status === "PENDING_VERSION" || status === "DELAYED" || !status;
42+
const isFailed = status === "FAILED" || status === "CRASHED" || status === "SYSTEM_FAILURE";
43+
const isComplete = status === "COMPLETED";
44+
45+
// Notify parent when run finishes
46+
const notified = useRef(false);
47+
useEffect(() => {
48+
if ((isComplete || isFailed) && !notified.current) {
49+
notified.current = true;
50+
onComplete?.();
51+
}
52+
}, [isComplete, isFailed, onComplete]);
53+
3954
// Auto-scroll when new events arrive (unless user scrolled up)
4055
useEffect(() => {
4156
if (events.length > 0 && !userScrolledUp.current) {
@@ -53,21 +68,6 @@ export function Terminal({
5368
);
5469
}
5570

56-
const status = run?.status;
57-
const isRunning = status === "EXECUTING";
58-
const isQueued = status === "PENDING_VERSION" || status === "DELAYED" || !status;
59-
const isFailed = status === "FAILED" || status === "CRASHED" || status === "SYSTEM_FAILURE";
60-
const isComplete = status === "COMPLETED";
61-
62-
// Notify parent when run finishes
63-
const notified = useRef(false);
64-
useEffect(() => {
65-
if ((isComplete || isFailed) && !notified.current) {
66-
notified.current = true;
67-
onComplete?.();
68-
}
69-
}, [isComplete, isFailed, onComplete]);
70-
7171
return (
7272
<div
7373
ref={scrollRef}

0 commit comments

Comments
 (0)