import { z } from 'zod'
import useTranslate from '../useTranslate'
import { createOutputSchema, createSuccessResponse, createErrorResponse } from './commonSchema'
const inputSchema = z.object({
key: z.string().describe('The unique key for the i18n entry to delete')
})
const delI18nDataSchema = z.object({
key: z.string().describe('The unique key of the deleted entry'),
deletedEntry: z.record(z.any()).describe('The deleted i18n entry data')
})
const outputSchema = createOutputSchema(delI18nDataSchema)
export const delI18n = {
name: 'delete_i18n',
title: '删除 I18n 词条',
description:
'Delete an existing i18n entry from the current TinyEngine low-code application. Use this when you need to remove internationalization translations.',
inputSchema: inputSchema.shape,
outputSchema: outputSchema.shape,
annotations: {
title: 'Delete I18n Entry',
readOnlyHint: false,
destructiveHint: true,
idempotentHint: true,
openWorldHint: false
},
callback: async (args: z.infer<typeof inputSchema>) => {
const { key } = args
const { getLangs, removeI18n } = useTranslate()
const langs = getLangs() as Record<string, any>
if (!langs[key]) {
return createErrorResponse('I18n key not found', `Key "${key}" does not exist in the i18n dictionary`)
}
try {
const deletedEntry = langs[key]
;(removeI18n as (keys: string[]) => void)([key])
return createSuccessResponse('I18n entry deleted successfully', {
key,
deletedEntry
})
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'
return createErrorResponse('Failed to delete i18n entry', errorMessage)
}
}
}