Skip to content

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

fix(playground): save to prompt list (#3384)

Hassieb Pakzadeb40659e441c
diff --git a/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx b/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx
index a2f27ca10b..d1fa2159cc 100644
--- a/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx
+++ b/web/src/ee/features/playground/page/components/SaveToPromptButton.tsx
@@ -37,21 +37,18 @@ export const SaveToPromptButton: React.FC = () => {
const projectId = useProjectIdFromURL();
const { setPlaygroundCache } = usePlaygroundCache();
- const allPromptNames =
- api.prompts.all
+ const allChatPromptNamesWithIds =
+ api.prompts.allNames
.useQuery(
{
projectId: projectId as string, // Typecast as query is enabled only when projectId is present
- filter: [],
- orderBy: { column: "name", order: "ASC" },
- page: 0,
+ type: PromptType.Chat,
},
{ enabled: Boolean(projectId) },
)
- .data?.prompts.filter((prompt) => prompt.type === PromptType.Chat)
- .map((prompt) => ({
- label: prompt.name,
- value: prompt.id,
+ .data?.map((prompt) => ({
+ name: prompt.name,
+ id: prompt.id,
})) ?? [];
const handleNewPrompt = async () => {
@@ -109,16 +106,16 @@ export const SaveToPromptButton: React.FC = () => {
</CommandEmpty>
<CommandGroup className="mt-2">
<CommandList>
- {allPromptNames.map((promptName) => (
+ {allChatPromptNamesWithIds.map((chatPrompt) => (
<CommandItem
- key={promptName.value}
- title={promptName.label}
- value={promptName.label}
+ key={chatPrompt.id}
+ title={chatPrompt.name}
+ value={chatPrompt.name}
onSelect={(currentValue) => {
const promptId =
- allPromptNames.find(
- (prompt) => prompt.label === currentValue,
- )?.value ?? "";
+ allChatPromptNamesWithIds.find(
+ (prompt) => prompt.name === currentValue,
+ )?.id ?? "";
setSelectedPromptId(
promptId === selectedPromptId ? "" : promptId,
@@ -128,13 +125,13 @@ export const SaveToPromptButton: React.FC = () => {
<Check
className={cn(
"mr-2 h-4 w-4",
- selectedPromptId === promptName.value
+ selectedPromptId === chatPrompt.id
? "opacity-100"
: "opacity-0",
)}
/>
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
- {promptName.label}
+ {chatPrompt.name}
</span>
</CommandItem>
))}
diff --git a/web/src/features/prompts/server/routers/promptRouter.ts b/web/src/features/prompts/server/routers/promptRouter.ts
index 6a7d9b3029..dbcaf2df01 100644
--- a/web/src/features/prompts/server/routers/promptRouter.ts
+++ b/web/src/features/prompts/server/routers/promptRouter.ts
@@ -1,7 +1,10 @@
import { z } from "zod";
import { auditLog } from "@/src/features/audit-logs/auditLog";
-import { CreatePromptTRPCSchema } from "@/src/features/prompts/server/utils/validation";
+import {
+ CreatePromptTRPCSchema,
+ PromptType,
+} from "@/src/features/prompts/server/utils/validation";
import { throwIfNoProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import {
createTRPCRouter,
@@ -502,6 +505,34 @@ export const promptRouter = createTRPCRouter({
return labels.map((l) => l.label);
}),
+ allNames: protectedProjectProcedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ type: z.nativeEnum(PromptType).optional(),
+ }),
+ )
+ .query(async ({ input, ctx }) => {
+ const { session } = ctx;
+ const { projectId, type } = input;
+
+ throwIfNoProjectAccess({
+ session,
+ projectId,
+ scope: "prompts:read",
+ });
+
+ return await ctx.prisma.prompt.findMany({
+ where: {
+ projectId,
+ type,
+ },
+ select: {
+ id: true,
+ name: true,
+ },
+ });
+ }),
updateTags: protectedProjectProcedure
.input(
z.object({