You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
831 B

import { requireAdmin } from "#server/utils/admin-guard";
import { createAgentTool } from "#server/service/agent-tool";
export default defineWrappedResponseHandler(async (event) => {
await requireAdmin(event);
const body = await readBody(event);
const { name, slug, description, type, config, enabled, needsApproval, adminOnly, sortOrder } = body;
if (!name || !slug || !type) {
return R.throwError(422, "name、slug、type 不能为空", null);
}
try {
const result = await createAgentTool({
name,
slug,
description: description ?? "",
type,
config: config ?? {},
enabled,
needsApproval,
adminOnly,
sortOrder,
});
return R.success(result);
} catch (e) {
return R.throwError(400, e instanceof Error ? e.message : String(e), null);
}
});