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
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@google/stitch-sdk",
"version": "0.3.0",
"version": "0.3.3",
"type": "module",
"private": false,
"description": "Generate UI screens from text prompts and extract their HTML and screenshots programmatically.",
Expand Down
59 changes: 58 additions & 1 deletion packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,71 @@ export class StitchToolClient implements StitchToolClientSpec {
async listTools() {
if (!this.isConnected) await this.connect();
const remoteTools = await this.client.listTools();

const tools = remoteTools.tools || [];

// Resilient Schema Repair: Dynamically patch broken $ref schemas from the Stitch backend
for (const tool of tools) {
const schema = tool.inputSchema as any;
if (schema && typeof schema === 'object') {
schema.$defs = schema.$defs || {};

// Inject the missing ScreenInstance definition if referenced
if (!schema.$defs.ScreenInstance) {
schema.$defs.ScreenInstance = {
type: 'object',
description: 'An instance of a screen on the project.',
properties: {
groupId: { type: 'string' },
groupName: { type: 'string' },
height: { type: 'integer', format: 'int32' },
hidden: { type: 'boolean' },
id: { type: 'string' },
isFavourite: { type: 'boolean' },
label: { type: 'string' },
sourceAsset: { type: 'string' },
sourceScreen: { type: 'string' },
type: {
type: 'string',
enum: [
'SCREEN_INSTANCE_TYPE_UNSPECIFIED',
'SCREEN_INSTANCE',
'DESIGN_SYSTEM_INSTANCE',
'GROUP_INSTANCE'
]
},
width: { type: 'integer', format: 'int32' },
x: { type: 'integer', format: 'int32' },
y: { type: 'integer', format: 'int32' }
}
};
}

// Inject the missing File definition if referenced
if (!schema.$defs.File) {
schema.$defs.File = {
type: 'object',
description: 'A File resource.',
properties: {
downloadUrl: { type: 'string' },
fileContentBase64: { type: 'string', writeOnly: true },
mimeType: { type: 'string' },
name: { type: 'string' },
uploadBlobId: { type: 'string' }
}
};
}
}
}

const localTools = this.localVirtualTools.map(t => ({
name: t.name,
description: t.description,
inputSchema: t.inputSchema,
source: t.source
}));
return {
tools: [...(remoteTools.tools || []), ...localTools]
tools: [...tools, ...localTools]
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Auto-generated by scripts/inject-version.ts — do not edit.
export const SDK_VERSION = '0.3.0';
export const SDK_VERSION = '0.3.3';
Loading