import { z } from 'zod'
import { useCanvas } from '@opentiny/tiny-engine-meta-register'
const inputSchema = z.object({})
export const getCurrentSelectedNode = {
name: 'get_current_selected_node',
title: '获取当前选中节点',
description:
'Get the current selected node from the current TinyEngine low-code application. Use this when you need to get the current selected node from your application.',
inputSchema: inputSchema.shape,
annotations: {
title: '获取当前选中节点',
readOnlyHint: true,
openWorldHint: false
},
callback: async (_args: z.infer<typeof inputSchema>) => {
const currentSelectedNode = useCanvas().canvasApi.value?.getCurrent?.()
if (!currentSelectedNode) {
return {
content: [
{
isError: true,
type: 'text',
text: JSON.stringify({
status: 'error',
message: 'No node is currently selected'
})
}
]
}
}
const { schema, parent } = currentSelectedNode
const res = {
status: 'success',
message: `Current selected node retrieved successfully`,
data: {
currentSelectedNode: schema,
parent
}
}
return {
content: [
{
type: 'text',
text: JSON.stringify(res)
}
]
}
}
}