Skip to content

Commit 7cce9b6

Browse files
authored
Merge pull request #1597 from opentiny/release/v2.8.x
Release/v2.8.x
2 parents 7f939c1 + e62142a commit 7cce9b6

95 files changed

Lines changed: 919 additions & 300 deletions

File tree

Some content is hidden

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

designer-demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "designer-demo",
33
"private": true,
4-
"version": "2.7.0",
4+
"version": "2.8.0",
55
"type": "module",
66
"scripts": {
77
"dev": "cross-env vite",

designer-demo/src/composable/http/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const preResponse = (res) => {
4646
return Promise.reject(res.data.error)
4747
}
4848

49-
return res.data?.data
49+
return res.data?.data || res.data
5050
}
5151

5252
const openLogin = () => {

mockServer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/tiny-engine-mock",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"publishConfig": {
55
"access": "public"
66
},

packages/block-compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/tiny-engine-block-compiler",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"publishConfig": {
55
"access": "public"
66
},

packages/build/vite-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/tiny-engine-vite-config",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "",
55
"type": "module",
66
"main": "./index.js",

packages/build/vite-plugin-meta-comments/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/tiny-engine-vite-plugin-meta-comments",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "",
55
"type": "module",
66
"main": "dist/index.cjs",

packages/builtinComponent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/tiny-engine-builtin-component",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "",
55
"main": "dist/index.mjs",
66
"module": "dist/index.mjs",

packages/canvas/DesignCanvas/src/mcp/tools/addNode.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
import { z } from 'zod'
2-
import { useCanvas } from '@opentiny/tiny-engine-meta-register'
2+
import { useCanvas, useMaterial } from '@opentiny/tiny-engine-meta-register'
33
import { utils } from '@opentiny/tiny-engine-utils'
44

55
const { validateParams } = utils
66

7-
type NodeSchema = z.ZodObject<{
8-
componentName: z.ZodString
9-
props: z.ZodObject<Record<string, z.ZodTypeAny>, 'strip', z.ZodTypeAny>
10-
children: z.ZodArray<z.ZodLazy<any>, 'many'>
11-
}>
12-
13-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
14-
const nodeArraySchema = z.lazy(() => nodeSchema)
15-
16-
const nodeSchema: NodeSchema = z.object({
17-
componentName: z.string().describe('The name of the component.'),
18-
props: z.object({}).describe('The props of the component.'),
19-
children: z.array(z.lazy(() => nodeArraySchema)).describe('The children of the component')
20-
})
21-
227
const inputSchema = z.object({
238
parentId: z
249
.string()
2510
.optional()
2611
.describe(
2712
'The id of the parent node. If not provided, the new node will be added to the root. if you don\'t know the parentId, you can use the tool "get_page_schema" to get the page schema. if you want to add to page root, just don\'t provide the parentId.'
2813
),
29-
newNodeData: z.lazy(() => nodeSchema).describe('The new node data.'),
14+
newNodeData: z.object({
15+
componentName: z.string().describe('The name of the component.'),
16+
props: z.record(z.string(), z.any()).describe('The props of the component.'),
17+
children: z
18+
.array(z.record(z.string(), z.any()))
19+
.describe('Array of child nodes; each child has the same shape as newNodeData (recursive tree).')
20+
}),
3021
position: z
3122
.enum(['before', 'after'])
3223
.optional()
@@ -60,11 +51,6 @@ export const addNode = {
6051
const { props = {}, children = [] } = newNodeData
6152

6253
const validateResult = validateParams(args, {
63-
componentName: {
64-
required: true,
65-
message:
66-
'Component name is required, if you don\'t know the component name, you can use the tool "get_component_list" to get the component detail.'
67-
},
6854
parentId: {
6955
validator: (value: string) => {
7056
const parentNode = useCanvas().getNodeById(value)
@@ -87,27 +73,55 @@ export const addNode = {
8773
return validateResult.error
8874
}
8975

76+
const { getMaterial } = useMaterial()
77+
const material = getMaterial(componentName)
78+
const isEmptyPlainObject =
79+
material &&
80+
typeof material === 'object' &&
81+
!Array.isArray(material) &&
82+
Object.keys(material as Record<string, unknown>).length === 0
83+
84+
if (!newNodeData.componentName || isEmptyPlainObject) {
85+
return {
86+
isError: true,
87+
content: [
88+
{
89+
type: 'text',
90+
text: JSON.stringify({
91+
status: 'error',
92+
errorCode: 'COMPONENT_NAME_REQUIRED',
93+
reason: 'Component name is required',
94+
userMessage: 'Component name is required. Fetch the available component list.',
95+
next_action: {
96+
type: 'tool_call',
97+
name: 'get_component_list',
98+
args: {}
99+
}
100+
})
101+
}
102+
]
103+
}
104+
}
105+
106+
const insertData = {
107+
componentName,
108+
props,
109+
children
110+
}
111+
90112
useCanvas().operateNode({
91113
type: 'insert',
92114
parentId: parentId!,
93115
// @ts-ignore
94-
newNodeData: {
95-
componentName,
96-
props,
97-
children
98-
},
116+
newNodeData: insertData,
99117
position: position!,
100118
referTargetNodeId
101119
})
102120

103121
const res = {
104122
status: 'success',
105123
message: `Node added successfully`,
106-
data: {
107-
componentName,
108-
props,
109-
children
110-
}
124+
data: insertData
111125
}
112126

113127
return {

packages/canvas/DesignCanvas/src/mcp/tools/changeNodeProps.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import { z } from 'zod'
22
import { useCanvas } from '@opentiny/tiny-engine-meta-register'
33

44
const inputSchema = z.object({
5-
id: z.string().describe('The id of the node to change the props of.'),
5+
id: z
6+
.string()
7+
.describe(
8+
'The id of the node to change the props of. if you don\'t know the id, you can use the tool "get_current_selected_node" to get the current selected node. or you can use the tool "get_page_schema" to get the page schema. when get the page schema, you can find the id in the "id" field.'
9+
),
610
props: z
7-
.object({})
11+
.record(z.string(), z.any())
812
.describe(
913
'The props of the component. if you don\'t know available props, you can use the "get_component_detail" tool to get component detail and available props.'
1014
),
@@ -13,6 +17,7 @@ const inputSchema = z.object({
1317

1418
export const changeNodeProps = {
1519
name: 'change_node_props',
20+
title: '修改节点属性',
1621
description:
1722
'Change the props of a node in the current TinyEngine low-code application. Use this when you need to change the props of a node in your application.',
1823
inputSchema: inputSchema.shape,
@@ -32,6 +37,37 @@ export const changeNodeProps = {
3237
props = {}
3338
}
3439

40+
const node = useCanvas().getNodeById(id)
41+
if (!node) {
42+
return {
43+
content: [
44+
{
45+
isError: true,
46+
type: 'text',
47+
text: JSON.stringify({
48+
errorCode: 'NODE_NOT_FOUND',
49+
reason: `Node not found: ${id}`,
50+
userMessage: `Node not found: ${id}. Fetch the available node list.`,
51+
next_action: [
52+
{
53+
type: 'tool_call',
54+
name: 'get_current_selected_node',
55+
args: {},
56+
when: 'you want to change the props of the current selected node'
57+
},
58+
{
59+
type: 'tool_call',
60+
name: 'get_page_schema',
61+
args: {},
62+
when: 'you want to change the props of the node with the specified id'
63+
}
64+
]
65+
})
66+
}
67+
]
68+
}
69+
}
70+
3571
useCanvas().operateNode({
3672
type: 'changeProps',
3773
id,

packages/canvas/DesignCanvas/src/mcp/tools/delNode.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { z } from 'zod'
22
import { useCanvas } from '@opentiny/tiny-engine-meta-register'
33

44
const inputSchema = z.object({
5-
id: z.string().describe('The id of the node to delete.')
5+
id: z
6+
.string()
7+
.describe(
8+
'The id of the node to delete. if you don\'t know the id, you can use the tool "get_current_selected_node" to get the current selected node. or you can use the tool "get_page_schema" to get the page schema. when get the page schema, you can find the id in the "id" field.'
9+
)
610
})
711

812
export const delNode = {
913
name: 'del_node',
14+
title: '删除节点',
1015
description:
1116
'Delete a node from the current TinyEngine low-code application. Use this when you need to delete a node from your application.',
1217
inputSchema: inputSchema.shape,

0 commit comments

Comments
 (0)