diff --git a/.agents/skills/stitch-sdk-usage/SKILL.md b/.agents/skills/stitch-sdk-usage/SKILL.md index 823f5c9..8855320 100644 --- a/.agents/skills/stitch-sdk-usage/SKILL.md +++ b/.agents/skills/stitch-sdk-usage/SKILL.md @@ -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). diff --git a/packages/sdk/src/spec/upload.ts b/packages/sdk/src/spec/upload.ts index f73bc7b..ec7b632 100644 --- a/packages/sdk/src/spec/upload.ts +++ b/packages/sdk/src/spec/upload.ts @@ -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; diff --git a/packages/sdk/src/upload-handler.ts b/packages/sdk/src/upload-handler.ts index 8ca1bd3..4131ba0 100644 --- a/packages/sdk/src/upload-handler.ts +++ b/packages/sdk/src/upload-handler.ts @@ -78,6 +78,10 @@ function buildBatchCreateScreensBody( screen["title"] = input.title; } + if (input.deviceType) { + screen["deviceType"] = input.deviceType; + } + return { parent: `projects/${projectId}`, requests: [{ screen }], diff --git a/packages/sdk/test/unit/upload.test.ts b/packages/sdk/test/unit/upload.test.ts index 73393a6..c0d37f3 100644 --- a/packages/sdk/test/unit/upload.test.ts +++ b/packages/sdk/test/unit/upload.test.ts @@ -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 ─────────────────────────────────────────────────── @@ -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"); + }); });