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.
41 lines
1.2 KiB
41 lines
1.2 KiB
import { defineWrappedResponseHandler } from "#server/utils/handler";
|
|
import { R } from "#server/utils/response";
|
|
import { getCurrentUser } from "#server/utils/context";
|
|
import { createAgent, type CreateAgentInput } from "#server/service/agent/agent";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await getCurrentUser(event);
|
|
if (!user || user.role !== "admin") {
|
|
return R.error("仅管理员可创建 agent", null);
|
|
}
|
|
|
|
const body = await readBody(event);
|
|
const { slug, name, description, systemPrompt, defaultModelId, titleModelId, titleStrategy, enableThinking, enableTools, maxStepCount, isDefault, isCallable, sortOrder, enabled, toolIds } = body as CreateAgentInput;
|
|
|
|
if (!slug || !name || !systemPrompt) {
|
|
return R.error("slug、name、systemPrompt 为必填", null);
|
|
}
|
|
|
|
try {
|
|
const agent = await createAgent({
|
|
slug,
|
|
name,
|
|
description,
|
|
systemPrompt,
|
|
defaultModelId,
|
|
titleModelId,
|
|
titleStrategy,
|
|
enableThinking,
|
|
enableTools,
|
|
maxStepCount,
|
|
isDefault,
|
|
isCallable,
|
|
sortOrder,
|
|
enabled,
|
|
toolIds,
|
|
});
|
|
return R.success(agent);
|
|
} catch (e) {
|
|
return R.error(e instanceof Error ? e.message : String(e), null);
|
|
}
|
|
});
|
|
|