-
Notifications
You must be signed in to change notification settings - Fork 2
SS-9745: Add web mcp #334
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
Merged
Merged
SS-9745: Add web mcp #334
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ff1e2d0
SS-9745: Add web mcp hooks
LemToUp 6caf3dd
SS-9745: Improve saved state error message
LemToUp e205e2b
SS-9745: Review fixes
LemToUp dd7c239
SS-9745: Add descriptions
LemToUp d598db5
SS-9745: Add widget type guard protection
LemToUp 7103379
SS-9745: Make widget types as constants
LemToUp e4ee72d
SS-9745: Improve mcp parameters validation
LemToUp 4cbd6c4
SS-9745: Simplify schema generation for WebMCP
LemToUp 9e018bb
SS-9745: Optimize mcp tools registration
LemToUp 0aa75df
SS-9745: PR review fixes
LemToUp 9734beb
SS-9745: PR review fixes
LemToUp 78adc2e
SS-9745: Optimize getUiParameterRefs
LemToUp dc725d4
SS-9745: Remove excess function
LemToUp 779be53
SS-9745: Canonical createModelState Zod in model-state
LemToUp d8c3afd
SS-9745: Fix types duplicate
LemToUp 82f3c6d
SS-9745: Oprimize types
LemToUp 9f9d04c
SS-9745: Rollback excess changes
LemToUp 00a25ac
SS-9745: Get rid the code
LemToUp 614db05
SS-9745: Get rid excess mapping
LemToUp 05c4c97
SS-9745: Add evals test
LemToUp af547d1
Merge branch 'development' into task/SS-9745
LemToUp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
entities/parameter/lib/__tests__/parametersFilter.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import {IShapeDiverParameter} from "@AppBuilderLib/entities/parameter/config/parameter"; | ||
| import {NotificationAction} from "@AppBuilderLib/features/notifications/config/notificationcontext"; | ||
| import {ResParameterType} from "@shapediver/sdk.geometry-api-sdk-v2"; | ||
| import { | ||
| filterAndValidateParameters, | ||
| generateParameterFeedback, | ||
| } from "../parametersFilter"; | ||
| function createMockParameter( | ||
| overrides: Partial<IShapeDiverParameter<any>> & { | ||
| definition: IShapeDiverParameter<any>["definition"]; | ||
| }, | ||
| ): IShapeDiverParameter<any> { | ||
| return { | ||
| state: { | ||
| uiValue: overrides.state?.uiValue, | ||
| execValue: overrides.state?.execValue, | ||
| dirty: false, | ||
| disableOtherParameters: false, | ||
| stringExecValue: () => "", | ||
| }, | ||
| actions: { | ||
| setUiValue: () => true, | ||
| setUiAndExecValue: () => true, | ||
| execute: async () => "", | ||
| isValid: overrides.actions?.isValid ?? (() => true), | ||
| isUiValueDifferent: () => false, | ||
| resetToDefaultValue: () => undefined, | ||
| resetToExecValue: () => undefined, | ||
| }, | ||
| acceptRejectMode: false, | ||
| ...overrides, | ||
| } as IShapeDiverParameter<any>; | ||
| } | ||
|
|
||
| describe("filterAndValidateParameters", () => { | ||
| const widthParam = createMockParameter({ | ||
| definition: { | ||
| id: "width", | ||
| name: "Width", | ||
| type: ResParameterType.FLOAT, | ||
| min: 0, | ||
| max: 100, | ||
| defval: 10, | ||
| } as IShapeDiverParameter<any>["definition"], | ||
| }); | ||
|
|
||
| it("reports unknown parameter in invalidParameters", () => { | ||
| const result = filterAndValidateParameters( | ||
| [widthParam], | ||
| [{id: "missing", value: 1}], | ||
| ); | ||
|
|
||
| expect(result.hasValidParameters).toBe(false); | ||
| expect(result.skippedParameters).toEqual(["missing"]); | ||
| expect(result.invalidParameters).toEqual([ | ||
| { | ||
| name: "missing", | ||
| message: | ||
| 'Parameter "missing" does not exist in the current model session.', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("reports invalid value in invalidParameters", () => { | ||
| const result = filterAndValidateParameters( | ||
| [ | ||
| createMockParameter({ | ||
| definition: widthParam.definition, | ||
| actions: {isValid: () => false}, | ||
| }), | ||
| ], | ||
| [{id: "width", value: 999}], | ||
| ); | ||
|
|
||
| expect(result.hasValidParameters).toBe(false); | ||
| expect(result.skippedParameters).toEqual(["width"]); | ||
| expect(result.invalidParameters).toEqual([ | ||
| { | ||
| name: "width", | ||
| message: 'Value is not valid for parameter "width"', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("keeps valid parameters and reports only failures", () => { | ||
| const result = filterAndValidateParameters( | ||
| [widthParam], | ||
| [ | ||
| {id: "width", value: 42}, | ||
| {id: "unknown", value: 1}, | ||
| ], | ||
| ); | ||
|
|
||
| expect(result.hasValidParameters).toBe(true); | ||
| expect(result.validParameters).toEqual({width: 42}); | ||
| expect(result.invalidParameters).toEqual([ | ||
| { | ||
| name: "unknown", | ||
| message: | ||
| 'Parameter "unknown" does not exist in the current model session.', | ||
| }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("generateParameterFeedback", () => { | ||
| it("uses invalidParameters messages for partial success warnings", () => { | ||
| const feedback = generateParameterFeedback({ | ||
| validParameters: {width: 42}, | ||
| skippedParameters: ["unknown"], | ||
| invalidParameters: [ | ||
| { | ||
| name: "unknown", | ||
| message: | ||
| 'Parameter "unknown" does not exist in the current model session.', | ||
| }, | ||
| ], | ||
| hasValidParameters: true, | ||
| }); | ||
|
|
||
| expect(feedback.type).toBe(NotificationAction.WARNING); | ||
| expect(feedback.message).toBe( | ||
| 'Parameter "unknown" does not exist in the current model session.', | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back to skipped parameter names when invalidParameters is empty", () => { | ||
| const feedback = generateParameterFeedback({ | ||
| validParameters: {width: 42}, | ||
| skippedParameters: ["foo", "bar"], | ||
| invalidParameters: [], | ||
| hasValidParameters: true, | ||
| }); | ||
|
|
||
| expect(feedback.type).toBe(NotificationAction.WARNING); | ||
| expect(feedback.message).toBe( | ||
| "The following parameters could not be matched or ar invalid: foo, bar", | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import {z} from "zod"; | ||
|
|
||
| export const createModelStateImageRefSchema = z.strictObject({ | ||
| export: z | ||
| .strictObject({ | ||
| name: z.string(), | ||
| sessionId: z.string().optional(), | ||
| }) | ||
| .optional(), | ||
| href: z.string().optional(), | ||
| }); | ||
|
|
||
| export const createModelStateCoreSchema = z.strictObject({ | ||
| parameterNamesToInclude: z | ||
| .array(z.string()) | ||
| .optional() | ||
| .describe("Only include these parameters in the saved state."), | ||
| parameterNamesToExclude: z | ||
| .array(z.string()) | ||
| .optional() | ||
| .describe("Exclude these parameters from the saved state."), | ||
| includeImage: z | ||
| .boolean() | ||
| .optional() | ||
| .describe( | ||
| "Whether to include a preview image. Use false when not needed.", | ||
| ), | ||
| includeGltf: z | ||
| .boolean() | ||
| .optional() | ||
| .describe("Whether to include an exported GLTF asset."), | ||
| }); | ||
|
|
||
| export const createModelStateDataSchema = createModelStateCoreSchema.extend({ | ||
| image: createModelStateImageRefSchema.optional(), | ||
| data: z | ||
| .record(z.string(), z.any()) | ||
| .optional() | ||
| .describe("Optional custom metadata to store with the state."), | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.