import { z } from 'zod'
import { useCanvas } from '@opentiny/tiny-engine-meta-register'
const inputSchema = z.object({
id: z
.string()
.describe(
'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.'
)
})
export const delNode = {
name: 'del_node',
title: '删除节点',
description:
'Delete a node from the current TinyEngine low-code application. Use this when you need to delete a node from your application.',
inputSchema: inputSchema.shape,
annotations: {
title: '删除节点',
readOnlyHint: false,
destructiveHint: true,
idempotentHint: true,
openWorldHint: false
},
callback: async (args: z.infer<typeof inputSchema>) => {
const { id } = args
const node = useCanvas().getNodeById(id)
if (!node) {
return {
content: [
{
type: 'json',
value: {
status: 'error',
message: 'Node not found, please check the id is correct.'
}
}
]
}
}
useCanvas().operateNode({
type: 'delete',
id
})
const res = {
status: 'success',
message: `Node deleted successfully`,
data: {
id
}
}
return {
content: [
{
type: 'text',
text: JSON.stringify(res)
}
]
}
}
}