POST /api/apply/stream
Applies generated files to a sandbox and installs required npm packages. Returns a server-sent events (SSE) stream with progress updates.
Request body
The target sandbox ID. If not provided, operations apply to the active sandbox
Array of files to apply to the sandbox
File path relative to the sandbox root (e.g., “src/App.tsx”)
Complete file contents as a string
Array of npm package names to install (e.g., ["react-router-dom", "axios"])
Response
Returns a server-sent events (SSE) stream with Content-Type: text/event-stream. Events are sent as JSON objects prefixed with data: .
Stream event types
Progress updates during the apply operation
Human-readable status message (e.g., “Installing packages…”, “Applying 3/5: Button.tsx”)
Emitted for each successfully installed package
The installed package name
Emitted for each successfully applied file
The file path that was applied
Final event indicating the operation is complete
Array of file paths that were successfully applied
Array of package names that were installed
Whether the entire operation succeeded
Error event if the operation fails
Error description (e.g., “Failed to install packages: Network timeout”)
Error codes
Invalid JSON body or missing/empty files array
Example request
curl -X POST https://your-domain.com/api/apply/stream \
-H "Content-Type: application/json" \
-d '{
"sandboxId": "sb_abc123",
"files": [
{
"path": "src/components/Button.tsx",
"content": "export default function Button() { return <button>Click me</button>; }"
},
{
"path": "src/App.tsx",
"content": "import Button from './components/Button';\n\nexport default function App() { return <Button />; }"
}
],
"packages": ["react", "react-dom"]
}'
Example SSE response
data: {"type":"status","message":"Installing packages..."}
data: {"type":"status","message":"Installing 2 package(s)..."}
data: {"type":"package","data":{"name":"react"}}
data: {"type":"package","data":{"name":"react-dom"}}
data: {"type":"status","message":"Applying 2 file(s)..."}
data: {"type":"status","message":"Applying 1/2: Button.tsx"}
data: {"type":"file","data":{"path":"src/components/Button.tsx","status":"applied"}}
data: {"type":"status","message":"Applying 2/2: App.tsx"}
data: {"type":"file","data":{"path":"src/App.tsx","status":"applied"}}
data: {"type":"complete","data":{"appliedFiles":["src/components/Button.tsx","src/App.tsx"],"installedPackages":["react","react-dom"],"success":true}}
Operation order
The apply endpoint executes operations in this order:
- Install packages (if provided)
- Apply files to the sandbox with progress callbacks
- Emit completion event with summary
Package installation failures are reported but do not halt file application.