🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(annotation): add POST queue API (#8478)
marliessophiebc2dc4d89ce7
diff --git a/fern/apis/server/definition/annotation-queues.yml b/fern/apis/server/definition/annotation-queues.ymlindex 31e06fcf98..8c26b7bcff 100644--- a/fern/apis/server/definition/annotation-queues.yml+++ b/fern/apis/server/definition/annotation-queues.yml@@ -22,6 +22,13 @@ service:docs: limit of items per pageresponse: PaginatedAnnotationQueues+ createQueue:+ docs: Create an annotation queue+ method: POST+ path: /annotation-queues+ request: CreateAnnotationQueueRequest+ response: AnnotationQueue+getQueue:docs: Get an annotation queue by IDmethod: GET@@ -168,6 +175,12 @@ types:data: list<AnnotationQueueItem>meta: pagination.MetaResponse+ CreateAnnotationQueueRequest:+ properties:+ name: string+ description: optional<string>+ scoreConfigIds: list<string>+CreateAnnotationQueueItemRequest:properties:objectId: stringdiff --git a/packages/shared/src/server/test-utils/org-factory.ts b/packages/shared/src/server/test-utils/org-factory.tsindex a9c0306f81..b728f2fab2 100644--- a/packages/shared/src/server/test-utils/org-factory.ts+++ b/packages/shared/src/server/test-utils/org-factory.ts@@ -15,6 +15,7 @@ export function createBasicAuthHeader(export type CreateOrgProjectAndApiKeyOptions = {projectId?: string;+ plan?: "Team" | "Hobby" | "Core" | "Pro" | "Enterprise";};export const createOrgProjectAndApiKey = async (props?: CreateOrgProjectAndApiKeyOptions,@@ -25,7 +26,7 @@ export const createOrgProjectAndApiKey = async (id: v4(),name: v4(),cloudConfig: CloudConfigSchema.parse({- plan: "Team",+ plan: props?.plan ?? "Team",}),},});diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex 000870ecc6..cbc6b3df1a 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -79,6 +79,52 @@ paths:schema: {}security:- BasicAuth: []+ post:+ description: Create an annotation queue+ operationId: annotationQueues_createQueue+ tags:+ - AnnotationQueues+ parameters: []+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/AnnotationQueue'+ '400':+ description: ''+ content:+ application/json:+ schema: {}+ '401':+ description: ''+ content:+ application/json:+ schema: {}+ '403':+ description: ''+ content:+ application/json:+ schema: {}+ '404':+ description: ''+ content:+ application/json:+ schema: {}+ '405':+ description: ''+ content:+ application/json:+ schema: {}+ security:+ - BasicAuth: []+ requestBody:+ required: true+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/CreateAnnotationQueueRequest'/api/public/annotation-queues/{queueId}:get:description: Get an annotation queue by ID@@ -3254,7 +3300,7 @@ paths:parameters:- name: filterin: query- description: Filter expression (e.g. userName eq 'value')+ description: Filter expression (e.g. userName eq "value")required: falseschema:type: string@@ -4459,6 +4505,22 @@ components:required:- data- meta+ CreateAnnotationQueueRequest:+ title: CreateAnnotationQueueRequest+ type: object+ properties:+ name:+ type: string+ description:+ type: string+ nullable: true+ scoreConfigIds:+ type: array+ items:+ type: string+ required:+ - name+ - scoreConfigIdsCreateAnnotationQueueItemRequest:title: CreateAnnotationQueueItemRequesttype: objectdiff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.jsonindex 2c944a6841..7768de2e51 100644--- a/web/public/generated/postman/collection.json+++ b/web/public/generated/postman/collection.json@@ -78,6 +78,39 @@},"response": []},+ {+ "_type": "endpoint",+ "name": "Create Queue",+ "request": {+ "description": "Create an annotation queue",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues"+ ],+ "query": [],+ "variable": []+ },+ "header": [],+ "method": "POST",+ "auth": null,+ "body": {+ "mode": "raw",+ "raw": "{\n \"name\": \"example\",\n \"description\": \"example\",\n \"scoreConfigIds\": [\n \"example\"\n ]\n}",+ "options": {+ "raw": {+ "language": "json"+ }+ }+ }+ },+ "response": []+ },{"_type": "endpoint","name": "Get Queue",diff --git a/web/src/__tests__/annotation-queues-api.servertest.ts b/web/src/__tests__/annotation-queues-api.servertest.tsindex e980cf7e68..3a154c4632 100644--- a/web/src/__tests__/annotation-queues-api.servertest.ts+++ b/web/src/__tests__/annotation-queues-api.servertest.ts@@ -14,6 +14,7 @@ import {CreateAnnotationQueueItemResponse,UpdateAnnotationQueueItemResponse,DeleteAnnotationQueueItemResponse,+ CreateAnnotationQueueResponse,} from "@/src/features/public-api/types/annotation-queues";import {AnnotationQueueObjectType,@@ -173,6 +174,120 @@ describe("Annotation Queues API Endpoints", () => {});});+ describe("POST /annotation-queues", () => {+ it("should create a new annotation queue", async () => {+ const scoreConfig = await prisma.scoreConfig.create({+ data: {+ name: "Test Score Config",+ description: "Test Score Config Description",+ projectId,+ dataType: "NUMERIC",+ },+ });++ const response = await makeZodVerifiedAPICall(+ CreateAnnotationQueueResponse,+ "POST",+ "/api/public/annotation-queues",+ {+ name: "Test Queue",+ description: "Test Queue Description",+ scoreConfigIds: [scoreConfig.id],+ },+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.id).toBeDefined();+ expect(response.body.name).toBe("Test Queue");+ expect(response.body.description).toBe("Test Queue Description");+ expect(response.body.scoreConfigIds).toEqual([scoreConfig.id]);+ });++ it("should return 400 if the queue name already exists", async () => {+ const response = await makeAPICall(+ "POST",+ "/api/public/annotation-queues",+ {+ name: "Test Queue",+ description: "Test Queue Description",+ scoreConfigIds: [],+ },+ auth,+ );++ expect(response.status).toBe(400);+ });++ it("should return 400 if no score config IDs are provided", async () => {+ const response = await makeAPICall(+ "POST",+ "/api/public/annotation-queues",+ {+ name: "No configs queue",+ description: "Test Queue Description",+ scoreConfigIds: [],+ },+ auth,+ );++ expect(response.status).toBe(400);+ });++ it("should return 400 if the score config IDs are invalid", async () => {+ const response = await makeAPICall(+ "POST",+ "/api/public/annotation-queues",+ {+ name: "Invalid configs queue",+ description: "Test Queue Description",+ scoreConfigIds: ["invalid-score-config-id"],+ },+ auth,+ );++ expect(response.status).toBe(400);+ });++ it("should return 405 if the user is on the Hobby plan and has reached the maximum number of annotation queues", async () => {+ const { auth: hobbyPlanAuth, projectId: hobbyProjectId } =+ await createOrgProjectAndApiKey({+ plan: "Hobby",+ });++ const config = await prisma.scoreConfig.create({+ data: {+ name: "Test Score Config",+ description: "Test Score Config Description",+ projectId: hobbyProjectId,+ dataType: "NUMERIC",+ },+ });++ await prisma.annotationQueue.create({+ data: {+ name: "First queue",+ description: "First queue description",+ scoreConfigIds: [config.id],+ projectId: hobbyProjectId,+ },+ });++ const response = await makeAPICall(+ "POST",+ "/api/public/annotation-queues",+ {+ name: "Hobby plan queue",+ description: "Test Queue Description",+ scoreConfigIds: [config.id],+ },+ hobbyPlanAuth,+ );++ expect(response.status).toBe(405);+ });+ });+describe("GET /annotation-queues/:queueId", () => {it("should get a specific annotation queue", async () => {const response = await makeZodVerifiedAPICall(diff --git a/web/src/features/public-api/types/annotation-queues.ts b/web/src/features/public-api/types/annotation-queues.tsindex 3a5b7b5151..80dfe23651 100644--- a/web/src/features/public-api/types/annotation-queues.ts+++ b/web/src/features/public-api/types/annotation-queues.ts@@ -57,6 +57,17 @@ export const GetAnnotationQueuesResponse = z}).strict();+// POST /annotation-queues+export const CreateAnnotationQueueBody = z+ .object({+ name: z.string(),+ description: z.string().nullable(),+ scoreConfigIds: z.array(z.string()).min(1),+ })+ .strict();++export const CreateAnnotationQueueResponse = AnnotationQueueSchema;+// GET /annotation-queues/:queueIdexport const GetAnnotationQueueByIdQuery = z.object({diff --git a/web/src/pages/api/public/annotation-queues/index.ts b/web/src/pages/api/public/annotation-queues/index.tsindex 3163a973d4..5c74ba113e 100644--- a/web/src/pages/api/public/annotation-queues/index.ts+++ b/web/src/pages/api/public/annotation-queues/index.ts@@ -2,12 +2,14 @@ import { prisma } from "@langfuse/shared/src/db";import { withMiddlewares } from "@/src/features/public-api/server/withMiddlewares";import { createAuthedProjectAPIRoute } from "@/src/features/public-api/server/createAuthedProjectAPIRoute";import {+ CreateAnnotationQueueBody,+ CreateAnnotationQueueResponse,GetAnnotationQueuesQuery,GetAnnotationQueuesResponse,} from "@/src/features/public-api/types/annotation-queues";+import { InvalidRequestError, MethodNotAllowedError } from "@langfuse/shared";export default withMiddlewares({- // NOTE: Post API requires entitlement checkGET: createAuthedProjectAPIRoute({name: "Get annotation queues",querySchema: GetAnnotationQueuesQuery,@@ -54,4 +56,72 @@ export default withMiddlewares({};},}),++ POST: createAuthedProjectAPIRoute({+ name: "Create annotation queue",+ bodySchema: CreateAnnotationQueueBody,+ responseSchema: CreateAnnotationQueueResponse,+ fn: async ({ body, auth }) => {+ // entitlement check+ if (auth.scope.plan === "cloud:hobby") {+ if (+ (await prisma.annotationQueue.count({+ where: {+ projectId: auth.scope.projectId,+ },+ })) >= 1+ ) {+ throw new MethodNotAllowedError(+ "Maximum number of annotation queues reached on Hobby plan.",+ );+ }+ }++ const existingQueue = await prisma.annotationQueue.findFirst({+ where: {+ projectId: auth.scope.projectId,+ name: body.name,+ },+ });++ if (existingQueue) {+ throw new InvalidRequestError("A queue with this name already exists.");+ }++ // verify the score configs exist+ const scoreConfigs = await prisma.scoreConfig.findMany({+ where: {+ id: { in: body.scoreConfigIds },+ projectId: auth.scope.projectId,+ },+ select: {+ id: true,+ },+ });+ const scoreConfigIdSet = new Set(scoreConfigs.map((config) => config.id));+ if (body.scoreConfigIds.some((id) => !scoreConfigIdSet.has(id))) {+ throw new InvalidRequestError(+ "At least one of the score config IDs cannot be found for the given project.",+ );+ }++ const queue = await prisma.annotationQueue.create({+ data: {+ projectId: auth.scope.projectId,+ name: body.name,+ description: body.description,+ scoreConfigIds: body.scoreConfigIds,+ },+ });++ return {+ id: queue.id,+ name: queue.name,+ description: queue.description,+ scoreConfigIds: queue.scoreConfigIds,+ createdAt: queue.createdAt,+ updatedAt: queue.updatedAt,+ };+ },+ }),});