Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion app/api/sandboxes/file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function OPTIONS() {
/**
* GET /api/sandboxes/file
*
* Retrieves the raw contents of a file from the authenticated account's
* Retrieves the raw contents of a file from the authenticated or explicitly authorized account's
* sandbox GitHub repository. Resolves the github_repo from the account's
* snapshot, then fetches the file at the specified path.
*
Expand All @@ -27,6 +27,7 @@ export async function OPTIONS() {
* Query parameters:
* - path: string (required) - The file path within the repository
* - include_revision: "true" (optional) - Read content and blob SHA together from main
* - account_id: UUID (optional) - Target account, checked by the sandbox-list access policy
*
* Paths must be canonical relative paths: dot/traversal, backslashes, malformed Unicode
* and leading/trailing/doubled slashes return 400, including for legacy callers.
Expand All @@ -36,6 +37,7 @@ export async function OPTIONS() {
* - content: string - The raw file content
* - encoding: "base64" - Present for recognized binary extensions; content is base64
* - sha: string - Present for include_revision=true; use as files[].expected_sha
* - account_id: string - Present only when an explicit account_id was authorized
*
* Error (400/401/403/404):
* - status: "error"
Expand Down
2 changes: 2 additions & 0 deletions app/api/sandboxes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export async function POST(request: NextRequest): Promise<Response> {
* Defaults to "false"; repository filetree lookup still runs when available.
* - sandbox_id: (optional) Filter by a specific sandbox ID. Must be a sandbox
* that your account or organization is an admin of.
* - account_id: UUID (optional) - Target account, checked by the existing account-access policy.
* Successful explicit-target reads echo account_id; omitted-target response shape is unchanged.
*
* Response (200):
* - status: "success"
Expand Down
1 change: 1 addition & 0 deletions lib/contracts/__tests__/publishedSandboxFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ vi.mock("@/lib/github/getVersionedFileContent", () => ({ getVersionedFileContent

const ajv = new Ajv({ allErrors: true });
ajv.addKeyword({ keyword: "example", valid: true });
ajv.addFormat("uuid", /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);

function publishedContract(method: string, path: string, status: number) {
expect(
Expand Down
219 changes: 218 additions & 1 deletion lib/contracts/fixtures/published-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@
],
"sourceHashes": {
"content/docs/source/api-reference/openapi/accounts.json": "1a5a04f9ec358a15b8339b7029c9fed5fe69c6f042c8b03b6b4f03f3aafdeeed",
"content/docs/source/api-reference/openapi/content.json": "b89165f9296a1aa98139f64ae095eefd2a5b306950170d3f15a4826de95ed036",
"content/docs/source/api-reference/openapi/content.json": "a59fa965788414731d19e031ec4b44f4a83319bdc651cb0aa49fba5a534317b0",
"content/docs/source/api-reference/openapi/research.json": "053556fdeec5379fbaf6cfdbd37c721cd0793f08fa728b82c281e0c6af249457",
"content/docs/source/api-reference/openapi/releases.json": "7bfbdee327e8b3e27ba39cea3fcfe1fe930997d2ea05cb19a707f926ae3bdba2",
"content/docs/source/api-reference/openapi/social.json": "49c837327886827b5bc33ae4daac76f12473ecf4a6f75cc073656e9247ba73ca",
Expand Down Expand Up @@ -1118,6 +1118,39 @@
"path": "drafts/notes.txt",
"include_revision": "true"
},
"scopedReadQuery": {
"path": "drafts/notes.txt",
"include_revision": "true",
"account_id": "11111111-1111-4111-8111-111111111111"
},
"listQuery": {
"account_id": "11111111-1111-4111-8111-111111111111",
"metadata_only": "true"
},
"accountScopeParameters": {
"list": {
"name": "account_id",
"in": "query",
"description": "Optional target account UUID authorized by the existing account-access policy. Omit for the authenticated account. Successful explicit-target reads echo this value as account_id; this does not grant file-write access.",
"required": false,
"schema": {
"type": "string",
"format": "uuid"
},
"example": "11111111-1111-4111-8111-111111111111"
},
"file": {
"name": "account_id",
"in": "query",
"description": "Optional target account UUID authorized by the existing account-access policy. Omit for the authenticated account. Successful explicit-target reads echo this value as account_id; this does not grant file-write access.",
"required": false,
"schema": {
"type": "string",
"format": "uuid"
},
"example": "11111111-1111-4111-8111-111111111111"
}
},
"upload": {
"path": "drafts",
"message": "Update release notes",
Expand Down Expand Up @@ -1191,6 +1224,156 @@
}
},
"responses": [
{
"method": "GET",
"path": "/api/sandboxes",
"status": 200,
"schema": {
"type": "object",
"required": [
"status",
"sandboxes"
],
"description": "Response containing sandbox information",
"properties": {
"status": {
"type": "string",
"enum": [
"success",
"error"
],
"description": "Status of the request"
},
"sandboxes": {
"type": "array",
"items": {
"type": "object",
"required": [
"sandboxId",
"sandboxStatus",
"timeout",
"createdAt"
],
"description": "A sandbox environment instance",
"properties": {
"sandboxId": {
"type": "string",
"description": "Unique identifier for the sandbox",
"example": "sbx_abc123def456"
},
"sandboxStatus": {
"type": "string",
"enum": [
"pending",
"running",
"stopping",
"stopped",
"failed"
],
"description": "Current lifecycle state of the sandbox",
"example": "running"
},
"timeout": {
"type": "integer",
"description": "Milliseconds remaining before the sandbox stops automatically",
"example": 300000
},
"createdAt": {
"type": "string",
"format": "date-time",
"description": "ISO 8601 timestamp when the sandbox was created",
"example": "2024-01-15T10:30:00.000Z"
},
"runId": {
"type": "string",
"description": "Unique identifier for the command execution run. Only present if a command was provided when creating the sandbox. Use this with [GET /api/tasks/runs](/api-reference/tasks/runs) to check the status and retrieve results.",
"example": "run_xyz789abc123"
}
}
},
"description": "Array of sandbox objects"
},
"snapshot_id": {
"type": "string",
"description": "The account's saved snapshot ID used for creating new sandboxes. Null if no snapshot has been saved.",
"example": "snap_abc123def456",
"nullable": true
},
"github_repo": {
"type": "string",
"description": "The GitHub repository URL associated with the account's sandbox environment. Used as the filesystem source when restoring sandboxes.",
"example": "https://github.com/username/repo",
"nullable": true
},
"filetree": {
"type": "array",
"nullable": true,
"description": "The recursive file tree of the account's GitHub repository. Null if no github_repo is set or if the fetch fails.",
"items": {
"type": "object",
"required": [
"path",
"type",
"sha"
],
"description": "A single entry in a GitHub repository file tree",
"properties": {
"path": {
"type": "string",
"description": "The file or directory path relative to the repository root",
"example": "src/index.ts"
},
"type": {
"type": "string",
"enum": [
"blob",
"tree"
],
"description": "The type of entry: blob for files, tree for directories"
},
"sha": {
"type": "string",
"description": "The SHA hash of the entry",
"example": "abc123def456"
},
"size": {
"type": "integer",
"description": "The size of the file in bytes. Only present for blob entries.",
"example": 1024
}
}
}
},
"error": {
"type": "string",
"description": "Error message (only present if status is error)"
},
"account_id": {
"type": "string",
"format": "uuid",
"description": "On successful GET reads only: the explicitly requested, authorized target account UUID. Present even for an explicit self target; absent when account_id was omitted. This is read scope, not write authorization.",
"example": "11111111-1111-4111-8111-111111111111"
}
}
},
"examples": {
"ownMetadata": {
"status": "success",
"sandboxes": [],
"snapshot_id": null,
"github_repo": null,
"filetree": null
},
"targetMetadata": {
"status": "success",
"sandboxes": [],
"snapshot_id": null,
"github_repo": null,
"filetree": null,
"account_id": "11111111-1111-4111-8111-111111111111"
}
}
},
{
"method": "GET",
"path": "/api/sandboxes/file",
Expand Down Expand Up @@ -1225,8 +1408,42 @@
"pattern": "^[a-f0-9]{40}$",
"description": "Present when include_revision=true; use this reader-observed blob SHA as files[].expected_sha. Absent from legacy reads. It identifies the returned bytes, not an accepted Context source version.",
"example": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
"account_id": {
"type": "string",
"format": "uuid",
"description": "On successful GET reads only: the explicitly requested, authorized target account UUID. Present even for an explicit self target; absent when account_id was omitted. This is read scope, not write authorization.",
"example": "11111111-1111-4111-8111-111111111111"
}
}
},
"examples": {
"legacyText": {
"status": "success",
"content": "Release notes"
},
"versionedText": {
"status": "success",
"content": "Release notes",
"sha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
"versionedBinary": {
"status": "success",
"content": "aGVsbG8=",
"encoding": "base64",
"sha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
"targetText": {
"status": "success",
"content": "Release notes",
"account_id": "11111111-1111-4111-8111-111111111111"
},
"targetVersionedText": {
"status": "success",
"content": "Release notes",
"sha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"account_id": "11111111-1111-4111-8111-111111111111"
}
}
},
{
Expand Down
Loading
Loading