-
Notifications
You must be signed in to change notification settings - Fork 31
fix(exo): allow viewport-free tool payloads [SPA-5371] #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,10 @@ import { | |
| TreeNodeSchema, | ||
| ExoMetadataSchema, | ||
| } from '../../../types/exoSchemas.js'; | ||
| import { | ||
| asViewportOptionalCmaPayload, | ||
| type ViewportOptionalPayload, | ||
| } from '../../../types/cmaViewportCompatibility.js'; | ||
| import type { ContentfulConfig } from '../../../config/types.js'; | ||
|
|
||
| export const CreateComponentToolParams = BaseToolSchema.extend({ | ||
|
|
@@ -29,6 +33,7 @@ export const CreateComponentToolParams = BaseToolSchema.extend({ | |
| description: z.string().describe('Description of the component'), | ||
| viewports: z | ||
| .array(ViewportSchema) | ||
| .optional() | ||
| .describe('Viewport definitions for the component (may be empty)'), | ||
| contentProperties: z | ||
| .array(ContentPropertySchema) | ||
|
|
@@ -63,13 +68,15 @@ export function createComponentTool(config: ContentfulConfig) { | |
| const componentData = { | ||
| name: args.name, | ||
| description: args.description, | ||
| viewports: args.viewports, | ||
| ...(args.viewports !== undefined && { viewports: args.viewports }), | ||
| contentProperties: args.contentProperties, | ||
| designProperties: args.designProperties, | ||
| ...(args.componentTree && { componentTree: args.componentTree }), | ||
| ...(args.slots && { slots: args.slots }), | ||
| ...(args.metadata && { metadata: args.metadata }), | ||
| }; | ||
| } satisfies ViewportOptionalPayload< | ||
| Parameters<typeof contentfulClient.component.create>[1] | ||
| >; | ||
|
|
||
| // Create the component with or without an explicit ID. Providing an ID | ||
| // uses upsert (PUT) with no sys.version, which the CMA treats as a create. | ||
|
|
@@ -80,14 +87,16 @@ export function createComponentTool(config: ContentfulConfig) { | |
| environmentId: args.environmentId, | ||
| componentId: args.componentId, | ||
| }, | ||
| { | ||
| asViewportOptionalCmaPayload< | ||
|
Comment on lines
90
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant generic, duplicated conversion
The upsert branch re-wraps the already-validated Code Review Run #609b4f Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||
| Parameters<typeof contentfulClient.component.upsert>[1] | ||
| >({ | ||
| sys: { id: args.componentId, type: 'Component' }, | ||
| ...componentData, | ||
| }, | ||
| }), | ||
| ) | ||
| : await contentfulClient.component.create( | ||
| { spaceId: args.spaceId, environmentId: args.environmentId }, | ||
| componentData, | ||
| asViewportOptionalCmaPayload(componentData), | ||
| ); | ||
|
|
||
| return createSuccessResponse('Component created successfully', { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.