Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(api-prompts): use middleware to send response when updating labels (#6611)

Hassieb Pakzad6e5d0cee7b8e
diff --git a/web/src/features/prompts/server/handlers/promptVersionHandler.ts b/web/src/features/prompts/server/handlers/promptVersionHandler.ts
index 816d7547a4..884fc4f612 100644
--- a/web/src/features/prompts/server/handlers/promptVersionHandler.ts
+++ b/web/src/features/prompts/server/handlers/promptVersionHandler.ts
@@ -4,7 +4,6 @@ import { z } from "zod";
import { withMiddlewares } from "@/src/features/public-api/server/withMiddlewares";
import { createAuthedProjectAPIRoute } from "@/src/features/public-api/server/createAuthedProjectAPIRoute";
import { updatePrompt } from "@/src/features/prompts/server/actions/updatePrompts";
-import { LangfuseNotFoundError } from "@langfuse/shared";
import { auditLog } from "@/src/features/audit-logs/auditLog";
const UpdatePromptBodySchema = z.object({
@@ -20,37 +19,29 @@ export const promptVersionHandler = withMiddlewares({
name: "Update Prompt",
bodySchema: UpdatePromptBodySchema,
responseSchema: z.any(),
- fn: async ({ body, res, req, auth }) => {
- try {
- const { newLabels } = UpdatePromptBodySchema.parse(body);
- const { promptName, promptVersion } = req.query;
+ fn: async ({ body, req, auth }) => {
+ const { newLabels } = UpdatePromptBodySchema.parse(body);
+ const { promptName, promptVersion } = req.query;
- const prompt = await updatePrompt({
- promptName: promptName as string,
- projectId: auth.scope.projectId,
- promptVersion: Number(promptVersion),
- newLabels,
- });
+ const prompt = await updatePrompt({
+ promptName: promptName as string,
+ projectId: auth.scope.projectId,
+ promptVersion: Number(promptVersion),
+ newLabels,
+ });
- await auditLog({
- action: "update",
- resourceType: "prompt",
- resourceId: prompt.id,
- projectId: auth.scope.projectId,
- orgId: auth.scope.orgId,
- apiKeyId: auth.scope.apiKeyId,
- });
+ await auditLog({
+ action: "update",
+ resourceType: "prompt",
+ resourceId: prompt.id,
+ projectId: auth.scope.projectId,
+ orgId: auth.scope.orgId,
+ apiKeyId: auth.scope.apiKeyId,
+ });
- logger.info(`Prompt updated ${JSON.stringify(prompt)}`);
+ logger.info(`Prompt updated ${JSON.stringify(prompt)}`);
- return res.status(200).json(prompt);
- } catch (e) {
- logger.error(e);
- if (e instanceof LangfuseNotFoundError) {
- return res.status(404).json({ message: e.message });
- }
- return res.status(500).json({ message: "Internal server error" });
- }
+ return prompt;
},
}),
});