Skip to content
Open
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
1 change: 1 addition & 0 deletions .agents/skills/stitch-sdk-usage/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The method reads the file from disk and posts it directly to the Stitch REST API
|---|---|---|---|
| `title` | `string` | — | Display title for the created screen |
| `createScreenInstances` | `boolean` | `true` | Whether to add the screen to the canvas |
| `deviceType` | `"MOBILE"` \| `"DESKTOP"` \| `"TABLET"` \| `"AGNOSTIC"` | — | Device the uploaded page or screenshot represents |

**Throws** `StitchError` with codes: `NOT_FOUND` (file not found), `UNKNOWN_ERROR` (unsupported format or upload failure), `AUTH_FAILED` (invalid API key).

Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/spec/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const UploadInputSchema = z.object({
title: z.string().optional(),
/** If true (default), creates screen instances on the project canvas. */
createScreenInstances: z.boolean().default(true),
/** Optional device the uploaded page or screenshot represents. */
deviceType: z.enum(["MOBILE", "DESKTOP", "TABLET", "AGNOSTIC"]).optional(),
});

export type UploadInput = z.infer<typeof UploadInputSchema>;
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/upload-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function buildBatchCreateScreensBody(
screen["title"] = input.title;
}

if (input.deviceType) {
screen["deviceType"] = input.deviceType;
}

return {
parent: `projects/${projectId}`,
requests: [{ screen }],
Expand Down
24 changes: 24 additions & 0 deletions packages/sdk/test/unit/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ describe("UploadInputSchema", () => {
expect(result.data.createScreenInstances).toBe(false);
}
});

it("rejects a deviceType outside MOBILE, DESKTOP, TABLET and AGNOSTIC", () => {
const result = UploadInputSchema.safeParse({
filePath: "/pages/home.html",
deviceType: "PHONE",
});
expect(result.success).toBe(false);
});
});

// ─── Slice 2: Handler Tests ───────────────────────────────────────────────────
Expand Down Expand Up @@ -263,4 +271,20 @@ describe("Project.upload (generic integration)", () => {
expect(screens[0].projectId).toBe("test-project-id");
expect(screens[0].id).toBe("s-abc");
});

it("sends the deviceType option on the uploaded screen", async () => {
const httpPost = vi.fn().mockResolvedValue({ results: [] });
const proj = createProjectWithMockedClient(httpPost);
await proj.upload("/fake/document.html", { deviceType: "DESKTOP" });
const [, body] = httpPost.mock.calls[0];
expect(body.requests[0].screen.deviceType).toBe("DESKTOP");
});

it("omits deviceType from the uploaded screen when the option is unset", async () => {
const httpPost = vi.fn().mockResolvedValue({ results: [] });
const proj = createProjectWithMockedClient(httpPost);
await proj.upload("/fake/document.html");
const [, body] = httpPost.mock.calls[0];
expect(body.requests[0].screen).not.toHaveProperty("deviceType");
});
});
Loading