Skip to content

Commit 4dc95cd

Browse files
committed
feat(sdk): 0.4.0 non-breaking compatibility bridge, Generation proxy, and content accessors
1 parent c301bd3 commit 4dc95cd

46 files changed

Lines changed: 6954 additions & 1362 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/sdk/generated/domain-map.json‎

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,35 @@
4646
},
4747
"Screen": {
4848
"description": "A generated UI screen. Provides access to HTML and screenshots.",
49+
"extensionPath": "../../src/screen-ext.js",
4950
"constructorParams": ["projectId", "screenId"],
5051
"parentField": "projectId",
52+
"sideEffects": [
53+
{
54+
"method": "getHtml",
55+
"reason": "binary_data",
56+
"specPath": "src/spec/content.ts"
57+
},
58+
{
59+
"method": "getImage",
60+
"reason": "binary_data",
61+
"specPath": "src/spec/content.ts"
62+
},
63+
{
64+
"method": "readHtml",
65+
"reason": "binary_data",
66+
"specPath": "src/spec/content.ts"
67+
},
68+
{
69+
"method": "readImage",
70+
"reason": "binary_data",
71+
"specPath": "src/spec/content.ts"
72+
}
73+
],
74+
"publicInterface": {
75+
"name": "ScreenContentSpec",
76+
"importPath": "../../src/spec/content.js"
77+
},
5178
"reference": {
5279
"keys": ["projectId", "screenId"]
5380
}
@@ -115,19 +142,18 @@
115142
},
116143
"returns": {
117144
"class": "Screen",
145+
"kind": "generation",
118146
"projection": [
119147
{
120148
"prop": "outputComponents",
121-
"find": "design.screens",
122-
"acknowledgeSingle": true
149+
"each": true
123150
},
124151
{
125152
"prop": "design"
126153
},
127154
{
128155
"prop": "screens",
129-
"index": 0,
130-
"acknowledgeSingle": true
156+
"each": true
131157
}
132158
]
133159
}
@@ -158,19 +184,18 @@
158184
},
159185
"returns": {
160186
"class": "Screen",
187+
"kind": "generation",
161188
"projection": [
162189
{
163190
"prop": "outputComponents",
164-
"find": "design.screens",
165-
"acknowledgeSingle": true
191+
"each": true
166192
},
167193
{
168194
"prop": "design"
169195
},
170196
{
171197
"prop": "screens",
172-
"index": 0,
173-
"acknowledgeSingle": true
198+
"each": true
174199
}
175200
]
176201
}
@@ -204,6 +229,7 @@
204229
},
205230
"returns": {
206231
"class": "Screen",
232+
"kind": "generation",
207233
"projection": [
208234
{
209235
"prop": "outputComponents",
@@ -216,8 +242,7 @@
216242
"prop": "screens",
217243
"each": true
218244
}
219-
],
220-
"array": true
245+
]
221246
}
222247
},
223248
{
@@ -258,12 +283,13 @@
258283
"returns": {
259284
"class": "Screen",
260285
"projection": []
261-
}
286+
},
287+
"description": "Fetch a screen by ID and return its identity-mapped handle."
262288
},
263289
{
264290
"tool": "get_screen",
265291
"class": "Screen",
266-
"method": "getHtml",
292+
"method": "getHtmlUrl",
267293
"args": {
268294
"projectId": {
269295
"from": "self"
@@ -296,13 +322,15 @@
296322
"prop": "downloadUrl"
297323
}
298324
],
299-
"description": "Use cached HTML download URL from generation response if available"
300-
}
325+
"description": "Use cached HTML download URL from generation response if available",
326+
"writeBack": true
327+
},
328+
"description": "Get the signed download URL for this screen's HTML. Cache-aware: served from generation data when present; responses are written back to the cache."
301329
},
302330
{
303331
"tool": "get_screen",
304332
"class": "Screen",
305-
"method": "getImage",
333+
"method": "getImageUrl",
306334
"args": {
307335
"projectId": {
308336
"from": "self"
@@ -335,8 +363,10 @@
335363
"prop": "downloadUrl"
336364
}
337365
],
338-
"description": "Use cached screenshot URL from generation response"
339-
}
366+
"description": "Use cached screenshot URL from generation response",
367+
"writeBack": true
368+
},
369+
"description": "Get the signed download URL for this screen's screenshot. Cache-aware: served from generation data when present; responses are written back to the cache."
340370
},
341371
{
342372
"tool": "create_design_system",
@@ -412,6 +442,7 @@
412442
},
413443
"returns": {
414444
"class": "Screen",
445+
"kind": "generation",
415446
"projection": [
416447
{
417448
"prop": "outputComponents",
@@ -424,8 +455,7 @@
424455
"prop": "screens",
425456
"each": true
426457
}
427-
],
428-
"array": true
458+
]
429459
}
430460
},
431461
{
@@ -441,6 +471,7 @@
441471
}
442472
},
443473
"returns": {
474+
"type": "UploadDesignMdResponse",
444475
"projection": []
445476
}
446477
},

‎packages/sdk/generated/src/designsystem.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
* AUTO-GENERATED by scripts/generate-sdk.ts
33
DO NOT EDIT — changes will be overwritten.
44
5-
Source: tools-manifest.json (sha256:f20f91d571a1...)
6-
domain-map.json (sha256:a90931b3b207...)
5+
Source: tools-manifest.json (sha256:88ec3dfa066c...)
6+
domain-map.json (sha256:a6177cc7e2f4...)
77
*/
88
import { type StitchToolClientSpec } from "../../src/spec/client.js";
99
import { StitchError } from "../../src/spec/errors.js";
10+
import { Generation } from "../../src/generation.js";
1011
import {
1112
ComponentTokens,
1213
DesignTheme,
@@ -42,7 +43,7 @@ import {
4243
UpdateDesignSystemResponse,
4344
ApplyDesignSystemResponse,
4445
} from "./responses.generated.js";
45-
import { Screen } from "./screen.js";
46+
import { Screen } from "../../src/screen-ext.js";
4647

4748
/** Represents a visual theme or branding applied to projects and screens. */
4849
export class DesignSystem {
@@ -130,7 +131,7 @@ export class DesignSystem {
130131
*/
131132
async apply(
132133
selectedScreenInstances: SelectedScreenInstance[],
133-
): Promise<Screen[]> {
134+
): Promise<Generation<Screen, ApplyDesignSystemResponse>> {
134135
try {
135136
const raw = await this.client.callTool<ApplyDesignSystemResponse>(
136137
"apply_design_system",
@@ -140,7 +141,7 @@ export class DesignSystem {
140141
selectedScreenInstances,
141142
},
142143
);
143-
return (
144+
const _screens = (
144145
(raw.outputComponents || []).flatMap(
145146
(a: any) => a?.design?.screens || [],
146147
) || []
@@ -150,6 +151,14 @@ export class DesignSystem {
150151
projectId: this.projectId,
151152
}),
152153
);
154+
if (_screens.length === 0)
155+
throw new StitchError({
156+
code: "UNKNOWN_ERROR",
157+
message:
158+
"Incomplete API response from apply_design_system: no screens in response",
159+
recoverable: false,
160+
});
161+
return new Generation(_screens, raw);
153162
} catch (error) {
154163
throw StitchError.fromUnknown(error);
155164
}

‎packages/sdk/generated/src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* AUTO-GENERATED by scripts/generate-sdk.ts
33
DO NOT EDIT — changes will be overwritten.
44
5-
Source: tools-manifest.json (sha256:f20f91d571a1...)
6-
domain-map.json (sha256:a90931b3b207...)
5+
Source: tools-manifest.json (sha256:88ec3dfa066c...)
6+
domain-map.json (sha256:a6177cc7e2f4...)
77
*/
88
export { Stitch } from "./stitch.js";
99
export { Project } from "./project.js";

‎packages/sdk/generated/src/project.ts‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
* AUTO-GENERATED by scripts/generate-sdk.ts
33
DO NOT EDIT — changes will be overwritten.
44
5-
Source: tools-manifest.json (sha256:f20f91d571a1...)
6-
domain-map.json (sha256:a90931b3b207...)
5+
Source: tools-manifest.json (sha256:88ec3dfa066c...)
6+
domain-map.json (sha256:a6177cc7e2f4...)
77
*/
88
import { type StitchToolClientSpec } from "../../src/spec/client.js";
99
import { StitchError } from "../../src/spec/errors.js";
10+
import { Generation } from "../../src/generation.js";
1011
import {
1112
ComponentTokens,
1213
DesignTheme,
@@ -47,7 +48,7 @@ import {
4748
UploadDesignMdResponse,
4849
CreateDesignSystemFromDesignMdResponse,
4950
} from "./responses.generated.js";
50-
import { Screen } from "./screen.js";
51+
import { Screen } from "../../src/screen-ext.js";
5152
import { DesignSystem } from "./designsystem.js";
5253

5354
/** A Stitch project containing screens. */
@@ -126,16 +127,14 @@ export class Project {
126127
| "AGNOSTIC";
127128
modelId?:
128129
| "MODEL_ID_UNSPECIFIED"
129-
| "GEMINI_3_PRO"
130-
| "GEMINI_3_FLASH"
131-
| "GEMINI_3_1_PRO";
130+
| "GEMINI_3_8_FLASH"
131+
| "GEMINI_3_5_FLASH_LITE";
132132
},
133133
modelId?:
134134
| "MODEL_ID_UNSPECIFIED"
135-
| "GEMINI_3_PRO"
136-
| "GEMINI_3_FLASH"
137-
| "GEMINI_3_1_PRO",
138-
): Promise<Screen> {
135+
| "GEMINI_3_8_FLASH"
136+
| "GEMINI_3_5_FLASH_LITE",
137+
): Promise<Generation<Screen, GenerateScreenFromTextResponse>> {
139138
const options =
140139
typeof deviceTypeOrOptions === "object" &&
141140
deviceTypeOrOptions !== null &&
@@ -152,20 +151,24 @@ export class Project {
152151
modelId: options?.modelId,
153152
},
154153
);
155-
const _projected = (raw?.outputComponents ?? []).find(
156-
(c: any) => c?.design?.screens != null,
157-
)?.design?.screens?.[0];
158-
if (!_projected)
154+
const _screens = (
155+
(raw.outputComponents || []).flatMap(
156+
(a: any) => a?.design?.screens || [],
157+
) || []
158+
).map((item) =>
159+
this.client.entities.resolve(Screen, ["projectId", "screenId"], {
160+
...item,
161+
projectId: this.projectId,
162+
}),
163+
);
164+
if (_screens.length === 0)
159165
throw new StitchError({
160166
code: "UNKNOWN_ERROR",
161167
message:
162-
"Incomplete API response from generate_screen_from_text: expected object at projection path",
168+
"Incomplete API response from generate_screen_from_text: no screens in response",
163169
recoverable: false,
164170
});
165-
return this.client.entities.resolve(Screen, ["projectId", "screenId"], {
166-
..._projected,
167-
projectId: this.projectId,
168-
});
171+
return new Generation(_screens, raw);
169172
} catch (error) {
170173
throw StitchError.fromUnknown(error);
171174
}
@@ -193,7 +196,7 @@ export class Project {
193196
}
194197

195198
/**
196-
* Retrieves the details of a specific screen within a project.
199+
* Fetch a screen by ID and return its identity-mapped handle.
197200
* Tool: get_screen
198201
*/
199202
async getScreen(screenId: string): Promise<Screen> {
@@ -259,7 +262,9 @@ export class Project {
259262
* Uploads DESIGN.md to a Stitch project. Use this tool when the user wants to create a design system from a DESIGN.md file.
260263
* Tool: upload_design_md
261264
*/
262-
async uploadDesignMd(designMdBase64: string): Promise<any> {
265+
async uploadDesignMd(
266+
designMdBase64: string,
267+
): Promise<UploadDesignMdResponse> {
263268
try {
264269
const raw = await this.client.callTool<UploadDesignMdResponse>(
265270
"upload_design_md",

‎packages/sdk/generated/src/responses.generated.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import {
3232
* AUTO-GENERATED by scripts/generate-sdk.ts
3333
DO NOT EDIT — changes will be overwritten.
3434
35-
Source: tools-manifest.json (sha256:f20f91d571a1...)
36-
domain-map.json (sha256:a90931b3b207...)
35+
Source: tools-manifest.json (sha256:88ec3dfa066c...)
36+
domain-map.json (sha256:a6177cc7e2f4...)
3737
*/
3838

3939
/** Response message for create_project. */
@@ -57,7 +57,8 @@ export interface CreateProjectResponse {
5757
| "TEXT_TO_UI_PRO_IMAGE_SPACE"
5858
| "IMAGE_TO_UI"
5959
| "IMAGE_TO_UI_PRO"
60-
| "PROJECT_DESIGN";
60+
| "PROJECT_DESIGN"
61+
| "DESIGN_V2";
6162
readTime?: string;
6263
screenInstances?: ScreenInstance[];
6364
thumbnailScreenshot?: File;
@@ -87,7 +88,8 @@ export interface GetProjectResponse {
8788
| "TEXT_TO_UI_PRO_IMAGE_SPACE"
8889
| "IMAGE_TO_UI"
8990
| "IMAGE_TO_UI_PRO"
90-
| "PROJECT_DESIGN";
91+
| "PROJECT_DESIGN"
92+
| "DESIGN_V2";
9193
readTime?: string;
9294
screenInstances?: ScreenInstance[];
9395
thumbnailScreenshot?: File;
@@ -96,6 +98,9 @@ export interface GetProjectResponse {
9698
visibility?: "VISIBILITY_UNSPECIFIED" | "PUBLIC" | "PRIVATE";
9799
}
98100

101+
/** Response message for delete_project. */
102+
export interface DeleteProjectResponse {}
103+
99104
/** Response message for list_projects. */
100105
export interface ListProjectsResponse {
101106
projects?: ProjectInput[];
@@ -153,6 +158,7 @@ export interface UploadDesignMdResponse {
153158
isFavourite?: boolean;
154159
isResized?: boolean;
155160
label?: string;
161+
needsLayout?: boolean;
156162
sourceAsset?: string;
157163
sourceScreen?: string;
158164
textContent?: string;

0 commit comments

Comments
 (0)