-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add prompt param to POST /api/sandboxes #231
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
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,17 @@ import { validateAuthContext, type AuthContext } from "@/lib/auth/validateAuthCo | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { safeParseJson } from "@/lib/networking/safeParseJson"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { z } from "zod"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const sandboxBodySchema = z.object({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command: z.string().min(1, "command cannot be empty").optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: z.array(z.string()).optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: z.string().optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const sandboxBodySchema = z | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .object({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command: z.string().min(1, "command cannot be empty").optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: z.array(z.string()).optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: z.string().optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prompt: z.string().min(1, "prompt cannot be empty").optional(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .refine(data => !(data.command && data.prompt), { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: "Cannot specify both command and prompt", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: ["prompt"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+18
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.
The refinement only guards against Extend the refinement to also reject 🛡️ Proposed fix — also block args + prompt together .refine(data => !(data.command && data.prompt), {
message: "Cannot specify both command and prompt",
path: ["prompt"],
- });
+ })
+ .refine(data => !(data.args && data.prompt), {
+ message: "Cannot specify both args and prompt",
+ path: ["args"],
+ });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type SandboxBody = z.infer<typeof sandboxBodySchema> & AuthContext; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
missing_fieldsis semantically incorrect for this refinement error path.When this refinement fires, line 44 responds with
{ missing_fields: ["prompt"], error: "Cannot specify both command and prompt" }. Thepromptfield is not missing — it's conflicting. API consumers receivingmissing_fields: ["prompt"]will be misled into thinking they need to addprompt, not remove one of the two conflicting params.This is a pre-existing naming issue in the error response shape, but the new refinement makes it actively user-hostile because the field literally is present.
💡 Suggested fix — differentiate conflict errors from missing-field errors
if (!result.success) { const firstError = result.error.issues[0]; + const isConflict = firstError.code === "custom"; return NextResponse.json( { status: "error", - missing_fields: firstError.path, + ...(isConflict + ? { conflicting_fields: firstError.path } + : { missing_fields: firstError.path }), error: firstError.message, }, { status: 400, headers: getCorsHeaders(), }, ); }🤖 Prompt for AI Agents