🪢 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(api): add api for annotation queues (#5945)
Marc Klingen5dd5a39f9060
diff --git a/fern/apis/server/definition/annotation-queues.yml b/fern/apis/server/definition/annotation-queues.ymlnew file mode 100644index 0000000000..1e37fab36e--- /dev/null+++ b/fern/apis/server/definition/annotation-queues.yml@@ -0,0 +1,165 @@+# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json+imports:+ commons: ./commons.yml+ pagination: ./utils/pagination.yml++service:+ auth: true+ base-path: /api/public+ endpoints:+ listQueues:+ docs: Get all annotation queues+ method: GET+ path: /annotation-queues+ request:+ name: GetAnnotationQueuesRequest+ query-parameters:+ page:+ type: optional<integer>+ docs: page number, starts at 1+ limit:+ type: optional<integer>+ docs: limit of items per page+ response: PaginatedAnnotationQueues++ getQueue:+ docs: Get an annotation queue by ID+ method: GET+ path: /annotation-queues/{queueId}+ path-parameters:+ queueId:+ type: string+ docs: The unique identifier of the annotation queue+ response: AnnotationQueue++ listQueueItems:+ docs: Get items for a specific annotation queue+ method: GET+ path: /annotation-queues/{queueId}/items+ path-parameters:+ queueId:+ type: string+ docs: The unique identifier of the annotation queue+ request:+ name: GetAnnotationQueueItemsRequest+ query-parameters:+ status:+ type: optional<AnnotationQueueStatus>+ docs: Filter by status+ page:+ type: optional<integer>+ docs: page number, starts at 1+ limit:+ type: optional<integer>+ docs: limit of items per page+ response: PaginatedAnnotationQueueItems++ getQueueItem:+ docs: Get a specific item from an annotation queue+ method: GET+ path: /annotation-queues/{queueId}/items/{itemId}+ path-parameters:+ queueId:+ type: string+ docs: The unique identifier of the annotation queue+ itemId:+ type: string+ docs: The unique identifier of the annotation queue item+ response: AnnotationQueueItem++ createQueueItem:+ docs: Add an item to an annotation queue+ method: POST+ path: /annotation-queues/{queueId}/items+ path-parameters:+ queueId:+ type: string+ docs: The unique identifier of the annotation queue+ request: CreateAnnotationQueueItemRequest+ response: AnnotationQueueItem++ updateQueueItem:+ docs: Update an annotation queue item+ method: PATCH+ path: /annotation-queues/{queueId}/items/{itemId}+ path-parameters:+ queueId:+ type: string+ docs: The unique identifier of the annotation queue+ itemId:+ type: string+ docs: The unique identifier of the annotation queue item+ request: UpdateAnnotationQueueItemRequest+ response: AnnotationQueueItem++ deleteQueueItem:+ docs: Remove an item from an annotation queue+ method: DELETE+ path: /annotation-queues/{queueId}/items/{itemId}+ path-parameters:+ queueId:+ type: string+ docs: The unique identifier of the annotation queue+ itemId:+ type: string+ docs: The unique identifier of the annotation queue item+ response: DeleteAnnotationQueueItemResponse++types:+ AnnotationQueueStatus:+ enum:+ - PENDING+ - COMPLETED++ AnnotationQueueObjectType:+ enum:+ - TRACE+ - OBSERVATION++ AnnotationQueue:+ properties:+ id: string+ name: string+ description: optional<string>+ scoreConfigIds: list<string>+ createdAt: datetime+ updatedAt: datetime++ AnnotationQueueItem:+ properties:+ id: string+ queueId: string+ objectId: string+ objectType: AnnotationQueueObjectType+ status: AnnotationQueueStatus+ completedAt: optional<datetime>+ createdAt: datetime+ updatedAt: datetime++ PaginatedAnnotationQueues:+ properties:+ data: list<AnnotationQueue>+ meta: pagination.MetaResponse++ PaginatedAnnotationQueueItems:+ properties:+ data: list<AnnotationQueueItem>+ meta: pagination.MetaResponse++ CreateAnnotationQueueItemRequest:+ properties:+ objectId: string+ objectType: AnnotationQueueObjectType+ status:+ type: optional<AnnotationQueueStatus>+ docs: Defaults to PENDING for new queue items++ UpdateAnnotationQueueItemRequest:+ properties:+ status:+ type: optional<AnnotationQueueStatus>++ DeleteAnnotationQueueItemResponse:+ properties:+ success: boolean+ message: stringdiff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex a1602a8239..8cc92e2e25 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -24,6 +24,391 @@ info:- Postman collection:https://cloud.langfuse.com/generated/postman/collection.jsonpaths:+ /api/public/annotation-queues:+ get:+ description: Get all annotation queues+ operationId: annotationQueues_listQueues+ tags:+ - AnnotationQueues+ parameters:+ - name: page+ in: query+ description: page number, starts at 1+ required: false+ schema:+ type: integer+ nullable: true+ - name: limit+ in: query+ description: limit of items per page+ required: false+ schema:+ type: integer+ nullable: true+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/PaginatedAnnotationQueues'+ '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: []+ /api/public/annotation-queues/{queueId}:+ get:+ description: Get an annotation queue by ID+ operationId: annotationQueues_getQueue+ tags:+ - AnnotationQueues+ parameters:+ - name: queueId+ in: path+ description: The unique identifier of the annotation queue+ required: true+ schema:+ type: string+ 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: []+ /api/public/annotation-queues/{queueId}/items:+ get:+ description: Get items for a specific annotation queue+ operationId: annotationQueues_listQueueItems+ tags:+ - AnnotationQueues+ parameters:+ - name: queueId+ in: path+ description: The unique identifier of the annotation queue+ required: true+ schema:+ type: string+ - name: status+ in: query+ description: Filter by status+ required: false+ schema:+ $ref: '#/components/schemas/AnnotationQueueStatus'+ nullable: true+ - name: page+ in: query+ description: page number, starts at 1+ required: false+ schema:+ type: integer+ nullable: true+ - name: limit+ in: query+ description: limit of items per page+ required: false+ schema:+ type: integer+ nullable: true+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/PaginatedAnnotationQueueItems'+ '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: []+ post:+ description: Add an item to an annotation queue+ operationId: annotationQueues_createQueueItem+ tags:+ - AnnotationQueues+ parameters:+ - name: queueId+ in: path+ description: The unique identifier of the annotation queue+ required: true+ schema:+ type: string+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/AnnotationQueueItem'+ '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/CreateAnnotationQueueItemRequest'+ /api/public/annotation-queues/{queueId}/items/{itemId}:+ get:+ description: Get a specific item from an annotation queue+ operationId: annotationQueues_getQueueItem+ tags:+ - AnnotationQueues+ parameters:+ - name: queueId+ in: path+ description: The unique identifier of the annotation queue+ required: true+ schema:+ type: string+ - name: itemId+ in: path+ description: The unique identifier of the annotation queue item+ required: true+ schema:+ type: string+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/AnnotationQueueItem'+ '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: []+ patch:+ description: Update an annotation queue item+ operationId: annotationQueues_updateQueueItem+ tags:+ - AnnotationQueues+ parameters:+ - name: queueId+ in: path+ description: The unique identifier of the annotation queue+ required: true+ schema:+ type: string+ - name: itemId+ in: path+ description: The unique identifier of the annotation queue item+ required: true+ schema:+ type: string+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/AnnotationQueueItem'+ '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/UpdateAnnotationQueueItemRequest'+ delete:+ description: Remove an item from an annotation queue+ operationId: annotationQueues_deleteQueueItem+ tags:+ - AnnotationQueues+ parameters:+ - name: queueId+ in: path+ description: The unique identifier of the annotation queue+ required: true+ schema:+ type: string+ - name: itemId+ in: path+ description: The unique identifier of the annotation queue item+ required: true+ schema:+ type: string+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/DeleteAnnotationQueueItemResponse'+ '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: []/api/public/comments:post:description: >-@@ -2777,6 +3162,136 @@ paths:- traceIdscomponents:schemas:+ AnnotationQueueStatus:+ title: AnnotationQueueStatus+ type: string+ enum:+ - PENDING+ - COMPLETED+ AnnotationQueueObjectType:+ title: AnnotationQueueObjectType+ type: string+ enum:+ - TRACE+ - OBSERVATION+ AnnotationQueue:+ title: AnnotationQueue+ type: object+ properties:+ id:+ type: string+ name:+ type: string+ description:+ type: string+ nullable: true+ scoreConfigIds:+ type: array+ items:+ type: string+ createdAt:+ type: string+ format: date-time+ updatedAt:+ type: string+ format: date-time+ required:+ - id+ - name+ - scoreConfigIds+ - createdAt+ - updatedAt+ AnnotationQueueItem:+ title: AnnotationQueueItem+ type: object+ properties:+ id:+ type: string+ queueId:+ type: string+ objectId:+ type: string+ objectType:+ $ref: '#/components/schemas/AnnotationQueueObjectType'+ status:+ $ref: '#/components/schemas/AnnotationQueueStatus'+ completedAt:+ type: string+ format: date-time+ nullable: true+ createdAt:+ type: string+ format: date-time+ updatedAt:+ type: string+ format: date-time+ required:+ - id+ - queueId+ - objectId+ - objectType+ - status+ - createdAt+ - updatedAt+ PaginatedAnnotationQueues:+ title: PaginatedAnnotationQueues+ type: object+ properties:+ data:+ type: array+ items:+ $ref: '#/components/schemas/AnnotationQueue'+ meta:+ $ref: '#/components/schemas/utilsMetaResponse'+ required:+ - data+ - meta+ PaginatedAnnotationQueueItems:+ title: PaginatedAnnotationQueueItems+ type: object+ properties:+ data:+ type: array+ items:+ $ref: '#/components/schemas/AnnotationQueueItem'+ meta:+ $ref: '#/components/schemas/utilsMetaResponse'+ required:+ - data+ - meta+ CreateAnnotationQueueItemRequest:+ title: CreateAnnotationQueueItemRequest+ type: object+ properties:+ objectId:+ type: string+ objectType:+ $ref: '#/components/schemas/AnnotationQueueObjectType'+ status:+ $ref: '#/components/schemas/AnnotationQueueStatus'+ nullable: true+ description: Defaults to PENDING for new queue items+ required:+ - objectId+ - objectType+ UpdateAnnotationQueueItemRequest:+ title: UpdateAnnotationQueueItemRequest+ type: object+ properties:+ status:+ $ref: '#/components/schemas/AnnotationQueueStatus'+ nullable: true+ DeleteAnnotationQueueItemResponse:+ title: DeleteAnnotationQueueItemResponse+ type: object+ properties:+ success:+ type: boolean+ message:+ type: string+ required:+ - success+ - messageCreateCommentRequest:title: CreateCommentRequesttype: objectdiff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.jsonindex d8a4ca1e3d..160145374d 100644--- a/web/public/generated/postman/collection.json+++ b/web/public/generated/postman/collection.json@@ -37,6 +37,296 @@]},"item": [+ {+ "_type": "container",+ "description": null,+ "name": "Annotation Queues",+ "item": [+ {+ "_type": "endpoint",+ "name": "List Queues",+ "request": {+ "description": "Get all annotation queues",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues?page=&limit=",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues"+ ],+ "query": [+ {+ "key": "page",+ "value": "",+ "description": "page number, starts at 1"+ },+ {+ "key": "limit",+ "value": "",+ "description": "limit of items per page"+ }+ ],+ "variable": []+ },+ "header": [],+ "method": "GET",+ "auth": null,+ "body": null+ },+ "response": []+ },+ {+ "_type": "endpoint",+ "name": "Get Queue",+ "request": {+ "description": "Get an annotation queue by ID",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues/:queueId",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues",+ ":queueId"+ ],+ "query": [],+ "variable": [+ {+ "key": "queueId",+ "value": "",+ "description": "The unique identifier of the annotation queue"+ }+ ]+ },+ "header": [],+ "method": "GET",+ "auth": null,+ "body": null+ },+ "response": []+ },+ {+ "_type": "endpoint",+ "name": "List Queue Items",+ "request": {+ "description": "Get items for a specific annotation queue",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues/:queueId/items?status=&page=&limit=",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues",+ ":queueId",+ "items"+ ],+ "query": [+ {+ "key": "status",+ "value": "",+ "description": "Filter by status"+ },+ {+ "key": "page",+ "value": "",+ "description": "page number, starts at 1"+ },+ {+ "key": "limit",+ "value": "",+ "description": "limit of items per page"+ }+ ],+ "variable": [+ {+ "key": "queueId",+ "value": "",+ "description": "The unique identifier of the annotation queue"+ }+ ]+ },+ "header": [],+ "method": "GET",+ "auth": null,+ "body": null+ },+ "response": []+ },+ {+ "_type": "endpoint",+ "name": "Get Queue Item",+ "request": {+ "description": "Get a specific item from an annotation queue",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues/:queueId/items/:itemId",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues",+ ":queueId",+ "items",+ ":itemId"+ ],+ "query": [],+ "variable": [+ {+ "key": "queueId",+ "value": "",+ "description": "The unique identifier of the annotation queue"+ },+ {+ "key": "itemId",+ "value": "",+ "description": "The unique identifier of the annotation queue item"+ }+ ]+ },+ "header": [],+ "method": "GET",+ "auth": null,+ "body": null+ },+ "response": []+ },+ {+ "_type": "endpoint",+ "name": "Create Queue Item",+ "request": {+ "description": "Add an item to an annotation queue",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues/:queueId/items",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues",+ ":queueId",+ "items"+ ],+ "query": [],+ "variable": [+ {+ "key": "queueId",+ "value": "",+ "description": "The unique identifier of the annotation queue"+ }+ ]+ },+ "header": [],+ "method": "POST",+ "auth": null,+ "body": {+ "mode": "raw",+ "raw": "{\n \"objectId\": \"example\",\n \"objectType\": \"TRACE\",\n \"status\": \"PENDING\"\n}",+ "options": {+ "raw": {+ "language": "json"+ }+ }+ }+ },+ "response": []+ },+ {+ "_type": "endpoint",+ "name": "Update Queue Item",+ "request": {+ "description": "Update an annotation queue item",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues/:queueId/items/:itemId",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues",+ ":queueId",+ "items",+ ":itemId"+ ],+ "query": [],+ "variable": [+ {+ "key": "queueId",+ "value": "",+ "description": "The unique identifier of the annotation queue"+ },+ {+ "key": "itemId",+ "value": "",+ "description": "The unique identifier of the annotation queue item"+ }+ ]+ },+ "header": [],+ "method": "PATCH",+ "auth": null,+ "body": {+ "mode": "raw",+ "raw": "{\n \"status\": \"PENDING\"\n}",+ "options": {+ "raw": {+ "language": "json"+ }+ }+ }+ },+ "response": []+ },+ {+ "_type": "endpoint",+ "name": "Delete Queue Item",+ "request": {+ "description": "Remove an item from an annotation queue",+ "url": {+ "raw": "{{baseUrl}}/api/public/annotation-queues/:queueId/items/:itemId",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "annotation-queues",+ ":queueId",+ "items",+ ":itemId"+ ],+ "query": [],+ "variable": [+ {+ "key": "queueId",+ "value": "",+ "description": "The unique identifier of the annotation queue"+ },+ {+ "key": "itemId",+ "value": "",+ "description": "The unique identifier of the annotation queue item"+ }+ ]+ },+ "header": [],+ "method": "DELETE",+ "auth": null,+ "body": null+ },+ "response": []+ }+ ]+ },{"_type": "container","description": null,diff --git a/web/src/__tests__/annotation-queues-api.servertest.ts b/web/src/__tests__/annotation-queues-api.servertest.tsnew file mode 100644index 0000000000..e980cf7e68--- /dev/null+++ b/web/src/__tests__/annotation-queues-api.servertest.ts@@ -0,0 +1,656 @@+/** @jest-environment node */++import { prisma } from "@langfuse/shared/src/db";+import {+ makeZodVerifiedAPICall,+ makeAPICall,+ pruneDatabase,+} from "@/src/__tests__/test-utils";+import {+ GetAnnotationQueuesResponse,+ GetAnnotationQueueByIdResponse,+ GetAnnotationQueueItemsResponse,+ GetAnnotationQueueItemByIdResponse,+ CreateAnnotationQueueItemResponse,+ UpdateAnnotationQueueItemResponse,+ DeleteAnnotationQueueItemResponse,+} from "@/src/features/public-api/types/annotation-queues";+import {+ AnnotationQueueObjectType,+ AnnotationQueueStatus,+} from "@langfuse/shared";+import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";+import { v4 as uuidv4 } from "uuid";++describe("Annotation Queues API Endpoints", () => {+ let auth: string;+ let projectId: string;+ let queueId: string;+ let queueItemId: string;+ const TOTAL_TEST_QUEUES = 15; // Create enough queues to test pagination+ const TOTAL_TEST_QUEUE_ITEMS = 20; // Create enough queue items to test pagination++ beforeAll(async () => {+ // Create organization, project, and API key for testing+ const { auth: newAuth, projectId: newProjectId } =+ await createOrgProjectAndApiKey();+ auth = newAuth;+ projectId = newProjectId;++ // Create multiple test annotation queues+ const queuePromises = [];+ for (let i = 0; i < TOTAL_TEST_QUEUES; i++) {+ queuePromises.push(+ prisma.annotationQueue.create({+ data: {+ name: `Test Queue ${i + 1}`,+ description: `Test Queue Description ${i + 1}`,+ scoreConfigIds: [],+ projectId,+ },+ }),+ );+ }++ const queues = await Promise.all(queuePromises);+ queueId = queues[0].id; // Use the first queue for specific tests++ // Create multiple test annotation queue items+ const queueItemPromises = [];+ for (let i = 0; i < TOTAL_TEST_QUEUE_ITEMS; i++) {+ // Distribute items across the first 3 queues to test filtering+ const targetQueueId = queues[i % 3].id;++ // Alternate between PENDING and COMPLETED status+ const status =+ i % 2 === 0+ ? AnnotationQueueStatus.PENDING+ : AnnotationQueueStatus.COMPLETED;++ // Set completedAt for COMPLETED items+ const completedAt =+ status === AnnotationQueueStatus.COMPLETED ? new Date() : null;++ queueItemPromises.push(+ prisma.annotationQueueItem.create({+ data: {+ queueId: targetQueueId,+ objectId: uuidv4(),+ objectType: AnnotationQueueObjectType.TRACE,+ status,+ completedAt,+ projectId,+ },+ }),+ );+ }++ const queueItems = await Promise.all(queueItemPromises);+ queueItemId = queueItems[0].id; // Use the first queue item for specific tests+ });++ afterAll(async () => {+ await pruneDatabase();+ });++ describe("GET /annotation-queues", () => {+ it("should get all annotation queues", async () => {+ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueuesResponse,+ "GET",+ "/api/public/annotation-queues",+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.data.length).toBeGreaterThan(0);+ expect(response.body.data[0]).toHaveProperty("id");+ expect(response.body.data[0]).toHaveProperty("name");+ expect(response.body.meta).toHaveProperty("totalItems");+ expect(response.body.meta.totalItems).toBe(TOTAL_TEST_QUEUES);+ });++ it("should support pagination with correct limits", async () => {+ const limit = 5;+ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueuesResponse,+ "GET",+ `/api/public/annotation-queues?page=1&limit=${limit}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.meta.page).toBe(1);+ expect(response.body.meta.limit).toBe(limit);+ expect(response.body.data.length).toBe(limit);+ expect(response.body.meta.totalItems).toBe(TOTAL_TEST_QUEUES);+ expect(response.body.meta.totalPages).toBe(+ Math.ceil(TOTAL_TEST_QUEUES / limit),+ );+ });++ it("should return different results for different pages", async () => {+ const limit = 5;++ // Get first page+ const firstPageResponse = await makeZodVerifiedAPICall(+ GetAnnotationQueuesResponse,+ "GET",+ `/api/public/annotation-queues?page=1&limit=${limit}`,+ undefined,+ auth,+ );++ // Get second page+ const secondPageResponse = await makeZodVerifiedAPICall(+ GetAnnotationQueuesResponse,+ "GET",+ `/api/public/annotation-queues?page=2&limit=${limit}`,+ undefined,+ auth,+ );++ expect(firstPageResponse.status).toBe(200);+ expect(secondPageResponse.status).toBe(200);++ // Check that we got different items on each page+ const firstPageIds = firstPageResponse.body.data.map((queue) => queue.id);+ const secondPageIds = secondPageResponse.body.data.map(+ (queue) => queue.id,+ );++ // No IDs should be in both pages+ const intersection = firstPageIds.filter((id) =>+ secondPageIds.includes(id),+ );+ expect(intersection.length).toBe(0);++ // Both pages should have the expected number of items+ expect(firstPageResponse.body.data.length).toBe(limit);+ expect(secondPageResponse.body.data.length).toBe(limit);+ });+ });++ describe("GET /annotation-queues/:queueId", () => {+ it("should get a specific annotation queue", async () => {+ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueueByIdResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.id).toBe(queueId);+ expect(response.body.name).toBe("Test Queue 1");+ expect(response.body.description).toBe("Test Queue Description 1");+ });++ it("should return 404 for non-existent queue", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "GET",+ `/api/public/annotation-queues/${nonExistentId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(404);+ });+ });++ describe("GET /annotation-queues/:queueId/items", () => {+ it("should get all items for a specific queue", async () => {+ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.data.length).toBeGreaterThan(0);+ expect(response.body.data[0]).toHaveProperty("id");+ expect(response.body.data[0]).toHaveProperty("queueId");+ expect(response.body.meta).toHaveProperty("totalItems");+ expect(response.body.data.every((item) => item.queueId === queueId)).toBe(+ true,+ );+ });++ it("should support pagination with correct limits for queue items", async () => {+ const limit = 7;+ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items?page=1&limit=${limit}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.meta.page).toBe(1);+ expect(response.body.meta.limit).toBe(limit);+ expect(response.body.data.length).toBeGreaterThan(0);+ expect(response.body.data.every((item) => item.queueId === queueId)).toBe(+ true,+ );+ });++ it("should return different results for different pages of queue items", async () => {+ // First, create enough items to ensure we have multiple pages+ const itemsToCreate = 15;+ const createPromises = [];++ for (let i = 0; i < itemsToCreate; i++) {+ createPromises.push(+ makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId: uuidv4(),+ objectType: AnnotationQueueObjectType.TRACE,+ },+ auth,+ ),+ );+ }++ await Promise.all(createPromises);++ const limit = 7;++ // Get first page+ const firstPageResponse = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items?page=1&limit=${limit}`,+ undefined,+ auth,+ );++ // Get second page+ const secondPageResponse = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items?page=2&limit=${limit}`,+ undefined,+ auth,+ );++ expect(firstPageResponse.status).toBe(200);+ expect(secondPageResponse.status).toBe(200);++ // Check that we got different items on each page+ const firstPageIds = firstPageResponse.body.data.map((item) => item.id);+ const secondPageIds = secondPageResponse.body.data.map((item) => item.id);++ // No IDs should be in both pages+ const intersection = firstPageIds.filter((id) =>+ secondPageIds.includes(id),+ );+ expect(intersection.length).toBe(0);++ // Both pages should have items+ expect(firstPageResponse.body.data.length).toBe(limit);+ expect(secondPageResponse.body.data.length).toBeGreaterThan(0);+ });++ it("should filter by status", async () => {+ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items?status=PENDING`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.data.length).toBeGreaterThan(0);+ expect(+ response.body.data.every(+ (item) =>+ item.queueId === queueId &&+ item.status === AnnotationQueueStatus.PENDING,+ ),+ ).toBe(true);+ });++ it("should return 404 for non-existent queue", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "GET",+ `/api/public/annotation-queues/${nonExistentId}/items`,+ undefined,+ auth,+ );++ expect(response.status).toBe(404);+ });+ });++ describe("GET /annotation-queues/:queueId/items/:itemId", () => {+ it("should get a specific annotation queue item", async () => {+ // First, get an item that belongs to the queue+ const itemsResponse = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items?limit=1`,+ undefined,+ auth,+ );++ expect(itemsResponse.status).toBe(200);+ expect(itemsResponse.body.data.length).toBeGreaterThan(0);++ const itemId = itemsResponse.body.data[0].id;++ const response = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemByIdResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items/${itemId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.id).toBe(itemId);+ expect(response.body.queueId).toBe(queueId);+ });++ it("should return 404 for non-existent queue item", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "GET",+ `/api/public/annotation-queues/${queueId}/items/${nonExistentId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(404);+ });++ it("should return 404 for non-existent queue", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "GET",+ `/api/public/annotation-queues/${nonExistentId}/items/${queueItemId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(404);+ });+ });++ describe("POST /annotation-queues/:queueId/items", () => {+ it("should create a new annotation queue item", async () => {+ const objectId = uuidv4();+ const response = await makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId,+ objectType: AnnotationQueueObjectType.TRACE,+ },+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.queueId).toBe(queueId);+ expect(response.body.objectId).toBe(objectId);+ expect(response.body.objectType).toBe(AnnotationQueueObjectType.TRACE);+ expect(response.body.status).toBe(AnnotationQueueStatus.PENDING);+ });++ it("should create queue items with different object types and statuses", async () => {+ // Create a queue item with TRACE object type+ const traceObjectId = uuidv4();+ const traceResponse = await makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId: traceObjectId,+ objectType: AnnotationQueueObjectType.TRACE,+ status: AnnotationQueueStatus.COMPLETED,+ },+ auth,+ );++ expect(traceResponse.status).toBe(200);+ expect(traceResponse.body.objectType).toBe(+ AnnotationQueueObjectType.TRACE,+ );++ // Create a queue item with OBSERVATION object type+ const observationObjectId = uuidv4();+ const observationResponse = await makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId: observationObjectId,+ objectType: AnnotationQueueObjectType.OBSERVATION,+ status: AnnotationQueueStatus.PENDING,+ },+ auth,+ );++ expect(observationResponse.status).toBe(200);+ expect(observationResponse.body.objectType).toBe(+ AnnotationQueueObjectType.OBSERVATION,+ );++ // Verify we can retrieve items with different object types+ const itemsResponse = await makeZodVerifiedAPICall(+ GetAnnotationQueueItemsResponse,+ "GET",+ `/api/public/annotation-queues/${queueId}/items`,+ undefined,+ auth,+ );++ expect(itemsResponse.status).toBe(200);++ // Find our created items in the response+ const traceItem = itemsResponse.body.data.find(+ (item) => item.objectId === traceObjectId,+ );+ const observationItem = itemsResponse.body.data.find(+ (item) => item.objectId === observationObjectId,+ );++ expect(traceItem).toBeDefined();+ expect(traceItem?.objectType).toBe(AnnotationQueueObjectType.TRACE);+ expect(traceItem?.status).toBe(AnnotationQueueStatus.COMPLETED);+ expect(observationItem).toBeDefined();+ expect(observationItem?.objectType).toBe(+ AnnotationQueueObjectType.OBSERVATION,+ );+ expect(observationItem?.status).toBe(AnnotationQueueStatus.PENDING);+ });++ it("should return 404 for non-existent queue", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "POST",+ `/api/public/annotation-queues/${nonExistentId}/items`,+ {+ objectId: uuidv4(),+ objectType: AnnotationQueueObjectType.TRACE,+ },+ auth,+ );++ expect(response.status).toBe(404);+ });+ });++ describe("PATCH /annotation-queues/:queueId/items/:itemId", () => {+ it("should update an annotation queue item to COMPLETED", async () => {+ // Create a new item to update+ const createResponse = await makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId: uuidv4(),+ objectType: AnnotationQueueObjectType.TRACE,+ },+ auth,+ );++ const newItemId = createResponse.body.id;++ const response = await makeZodVerifiedAPICall(+ UpdateAnnotationQueueItemResponse,+ "PATCH",+ `/api/public/annotation-queues/${queueId}/items/${newItemId}`,+ {+ status: AnnotationQueueStatus.COMPLETED,+ },+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.id).toBe(newItemId);+ expect(response.body.status).toBe(AnnotationQueueStatus.COMPLETED);+ expect(response.body.completedAt).not.toBeNull();+ });++ it("should update an annotation queue item from COMPLETED to PENDING", async () => {+ // Create a new item with COMPLETED status+ const createResponse = await makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId: uuidv4(),+ objectType: AnnotationQueueObjectType.TRACE,+ status: AnnotationQueueStatus.COMPLETED,+ },+ auth,+ );++ const newItemId = createResponse.body.id;++ // Verify it was created with COMPLETED status+ expect(createResponse.body.status).toBe(AnnotationQueueStatus.COMPLETED);+ expect(createResponse.body.completedAt).not.toBeNull();++ // Update it to PENDING+ const response = await makeZodVerifiedAPICall(+ UpdateAnnotationQueueItemResponse,+ "PATCH",+ `/api/public/annotation-queues/${queueId}/items/${newItemId}`,+ {+ status: AnnotationQueueStatus.PENDING,+ },+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.id).toBe(newItemId);+ expect(response.body.status).toBe(AnnotationQueueStatus.PENDING);+ expect(response.body.completedAt).not.toBeNull(); // is not reset by moving to PENDING+ });++ it("should return 404 for non-existent queue item", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "PATCH",+ `/api/public/annotation-queues/${queueId}/items/${nonExistentId}`,+ {+ status: AnnotationQueueStatus.COMPLETED,+ },+ auth,+ );++ expect(response.status).toBe(404);+ });++ it("should return 404 for non-existent queue", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "PATCH",+ `/api/public/annotation-queues/${nonExistentId}/items/${queueItemId}`,+ {+ status: AnnotationQueueStatus.COMPLETED,+ },+ auth,+ );++ expect(response.status).toBe(404);+ });+ });++ describe("DELETE /annotation-queues/:queueId/items/:itemId", () => {+ it("should delete an annotation queue item", async () => {+ // Create a new item to delete+ const createResponse = await makeZodVerifiedAPICall(+ CreateAnnotationQueueItemResponse,+ "POST",+ `/api/public/annotation-queues/${queueId}/items`,+ {+ objectId: uuidv4(),+ objectType: AnnotationQueueObjectType.TRACE,+ },+ auth,+ );++ const newItemId = createResponse.body.id;++ const response = await makeZodVerifiedAPICall(+ DeleteAnnotationQueueItemResponse,+ "DELETE",+ `/api/public/annotation-queues/${queueId}/items/${newItemId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(200);+ expect(response.body.success).toBe(true);++ // Verify the item is deleted+ const getResponse = await makeAPICall(+ "GET",+ `/api/public/annotation-queues/${queueId}/items/${newItemId}`,+ undefined,+ auth,+ );++ expect(getResponse.status).toBe(404);+ });++ it("should return 404 for non-existent queue item", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "DELETE",+ `/api/public/annotation-queues/${queueId}/items/${nonExistentId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(404);+ });++ it("should return 404 for non-existent queue", async () => {+ const nonExistentId = uuidv4();+ const response = await makeAPICall(+ "DELETE",+ `/api/public/annotation-queues/${nonExistentId}/items/${queueItemId}`,+ undefined,+ auth,+ );++ expect(response.status).toBe(404);+ });+ });+});diff --git a/web/src/features/public-api/types/annotation-queues.ts b/web/src/features/public-api/types/annotation-queues.tsnew file mode 100644index 0000000000..f0b0320b82--- /dev/null+++ b/web/src/features/public-api/types/annotation-queues.ts@@ -0,0 +1,131 @@+import { z } from "zod";+import {+ paginationMetaResponseZod,+ publicApiPaginationZod,+} from "@langfuse/shared";+import {+ AnnotationQueueObjectType,+ AnnotationQueueStatus,+} from "@langfuse/shared";++/**+ * Common Types+ */++export const AnnotationQueueItemSchema = z+ .object({+ id: z.string(),+ queueId: z.string(),+ objectId: z.string(),+ objectType: z.nativeEnum(AnnotationQueueObjectType),+ status: z.nativeEnum(AnnotationQueueStatus),+ completedAt: z.coerce.date().nullable(),+ createdAt: z.coerce.date(),+ updatedAt: z.coerce.date(),+ })+ .strict();++export const AnnotationQueueSchema = z+ .object({+ id: z.string(),+ name: z.string(),+ description: z.string().nullable(),+ scoreConfigIds: z.array(z.string()),+ createdAt: z.coerce.date(),+ updatedAt: z.coerce.date(),+ })+ .strict();++export type AnnotationQueueItem = z.infer<typeof AnnotationQueueItemSchema>;+export type AnnotationQueue = z.infer<typeof AnnotationQueueSchema>;++/**+ * Endpoints+ */++// GET /annotation-queues+export const GetAnnotationQueuesQuery = z+ .object({+ ...publicApiPaginationZod,+ })+ .strict();++export const GetAnnotationQueuesResponse = z+ .object({+ data: z.array(AnnotationQueueSchema),+ meta: paginationMetaResponseZod,+ })+ .strict();++// GET /annotation-queues/:queueId+export const GetAnnotationQueueByIdQuery = z+ .object({+ queueId: z.string(),+ })+ .strict();++export const GetAnnotationQueueByIdResponse = AnnotationQueueSchema;++// GET /annotation-queues/:queueId/items+export const GetAnnotationQueueItemsQuery = z+ .object({+ ...publicApiPaginationZod,+ queueId: z.string(),+ status: z.nativeEnum(AnnotationQueueStatus).optional(),+ })+ .strict();++export const GetAnnotationQueueItemsResponse = z+ .object({+ data: z.array(AnnotationQueueItemSchema),+ meta: paginationMetaResponseZod,+ })+ .strict();++// GET /annotation-queues/:queueId/items/:itemId+export const GetAnnotationQueueItemByIdQuery = z+ .object({+ queueId: z.string(),+ itemId: z.string(),+ })+ .strict();++export const GetAnnotationQueueItemByIdResponse = AnnotationQueueItemSchema;++// POST /annotation-queues/:queueId/items+export const CreateAnnotationQueueItemBody = z+ .object({+ objectId: z.string(),+ objectType: z.nativeEnum(AnnotationQueueObjectType),+ status: z+ .nativeEnum(AnnotationQueueStatus)+ .optional()+ .default(AnnotationQueueStatus.PENDING),+ })+ .strict();++export const CreateAnnotationQueueItemResponse = AnnotationQueueItemSchema;++// PATCH /annotation-queues/:queueId/items/:itemId+export const UpdateAnnotationQueueItemBody = z+ .object({+ status: z.nativeEnum(AnnotationQueueStatus).optional(),+ })+ .strict();++export const UpdateAnnotationQueueItemResponse = AnnotationQueueItemSchema;++// DELETE /annotation-queues/:queueId/items/:itemId+export const DeleteAnnotationQueueItemQuery = z+ .object({+ queueId: z.string(),+ itemId: z.string(),+ })+ .strict();++export const DeleteAnnotationQueueItemResponse = z+ .object({+ success: z.boolean(),+ message: z.string(),+ })+ .strict();diff --git a/web/src/pages/api/public/annotation-queues/[queueId].ts b/web/src/pages/api/public/annotation-queues/[queueId].tsnew file mode 100644index 0000000000..b8811f3c26--- /dev/null+++ b/web/src/pages/api/public/annotation-queues/[queueId].ts@@ -0,0 +1,37 @@+import { prisma } from "@langfuse/shared/src/db";+import { withMiddlewares } from "@/src/features/public-api/server/withMiddlewares";+import { createAuthedAPIRoute } from "@/src/features/public-api/server/createAuthedAPIRoute";+import {+ GetAnnotationQueueByIdQuery,+ GetAnnotationQueueByIdResponse,+} from "@/src/features/public-api/types/annotation-queues";+import { LangfuseNotFoundError } from "@langfuse/shared";++export default withMiddlewares({+ GET: createAuthedAPIRoute({+ name: "Get annotation queue by ID",+ querySchema: GetAnnotationQueueByIdQuery,+ responseSchema: GetAnnotationQueueByIdResponse,+ fn: async ({ query, auth }) => {+ const queue = await prisma.annotationQueue.findUnique({+ where: {+ id: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!queue) {+ throw new LangfuseNotFoundError("Annotation queue not found");+ }++ return {+ id: queue.id,+ name: queue.name,+ description: queue.description,+ scoreConfigIds: queue.scoreConfigIds,+ createdAt: queue.createdAt,+ updatedAt: queue.updatedAt,+ };+ },+ }),+});diff --git a/web/src/pages/api/public/annotation-queues/[queueId]/items/[itemId].ts b/web/src/pages/api/public/annotation-queues/[queueId]/items/[itemId].tsnew file mode 100644index 0000000000..67dd8c11c3--- /dev/null+++ b/web/src/pages/api/public/annotation-queues/[queueId]/items/[itemId].ts@@ -0,0 +1,162 @@+import { prisma } from "@langfuse/shared/src/db";+import { withMiddlewares } from "@/src/features/public-api/server/withMiddlewares";+import { createAuthedAPIRoute } from "@/src/features/public-api/server/createAuthedAPIRoute";+import {+ GetAnnotationQueueItemByIdQuery,+ GetAnnotationQueueItemByIdResponse,+ UpdateAnnotationQueueItemBody,+ UpdateAnnotationQueueItemResponse,+ DeleteAnnotationQueueItemQuery,+ DeleteAnnotationQueueItemResponse,+} from "@/src/features/public-api/types/annotation-queues";+import { LangfuseNotFoundError } from "@langfuse/shared";+import { AnnotationQueueStatus } from "@langfuse/shared";++export default withMiddlewares({+ GET: createAuthedAPIRoute({+ name: "Get annotation queue item by ID",+ querySchema: GetAnnotationQueueItemByIdQuery,+ responseSchema: GetAnnotationQueueItemByIdResponse,+ fn: async ({ query, auth }) => {+ // Verify the queue exists+ const queue = await prisma.annotationQueue.findUnique({+ where: {+ id: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!queue) {+ throw new LangfuseNotFoundError("Annotation queue not found");+ }++ const item = await prisma.annotationQueueItem.findUnique({+ where: {+ id: query.itemId,+ queueId: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!item) {+ throw new LangfuseNotFoundError("Annotation queue item not found");+ }++ return {+ id: item.id,+ queueId: item.queueId,+ objectId: item.objectId,+ objectType: item.objectType,+ status: item.status,+ completedAt: item.completedAt,+ createdAt: item.createdAt,+ updatedAt: item.updatedAt,+ };+ },+ }),+ PATCH: createAuthedAPIRoute({+ name: "Update annotation queue item",+ querySchema: GetAnnotationQueueItemByIdQuery,+ bodySchema: UpdateAnnotationQueueItemBody,+ responseSchema: UpdateAnnotationQueueItemResponse,+ fn: async ({ query, body, auth }) => {+ // Verify the queue exists+ const queue = await prisma.annotationQueue.findUnique({+ where: {+ id: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!queue) {+ throw new LangfuseNotFoundError("Annotation queue not found");+ }++ // Check if the item exists+ const existingItem = await prisma.annotationQueueItem.findUnique({+ where: {+ id: query.itemId,+ queueId: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!existingItem) {+ throw new LangfuseNotFoundError("Annotation queue item not found");+ }++ const updateData = {+ ...body,+ completedAt:+ body.status === AnnotationQueueStatus.COMPLETED+ ? new Date()+ : undefined,+ };++ const item = await prisma.annotationQueueItem.update({+ where: {+ id: query.itemId,+ queueId: query.queueId,+ projectId: auth.scope.projectId,+ },+ data: updateData,+ });++ return {+ id: item.id,+ queueId: item.queueId,+ objectId: item.objectId,+ objectType: item.objectType,+ status: item.status,+ completedAt: item.completedAt,+ createdAt: item.createdAt,+ updatedAt: item.updatedAt,+ };+ },+ }),+ DELETE: createAuthedAPIRoute({+ name: "Delete annotation queue item",+ querySchema: DeleteAnnotationQueueItemQuery,+ responseSchema: DeleteAnnotationQueueItemResponse,+ fn: async ({ query, auth }) => {+ // Verify the queue exists+ const queue = await prisma.annotationQueue.findUnique({+ where: {+ id: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!queue) {+ throw new LangfuseNotFoundError("Annotation queue not found");+ }++ // Check if the item exists+ const existingItem = await prisma.annotationQueueItem.findUnique({+ where: {+ id: query.itemId,+ queueId: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!existingItem) {+ throw new LangfuseNotFoundError("Annotation queue item not found");+ }++ // Delete the item+ await prisma.annotationQueueItem.delete({+ where: {+ id: query.itemId,+ queueId: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ return {+ success: true,+ message: "Annotation queue item deleted successfully",+ };+ },+ }),+});diff --git a/web/src/pages/api/public/annotation-queues/[queueId]/items/index.ts b/web/src/pages/api/public/annotation-queues/[queueId]/items/index.tsnew file mode 100644index 0000000000..d5bf96a6c9--- /dev/null+++ b/web/src/pages/api/public/annotation-queues/[queueId]/items/index.ts@@ -0,0 +1,132 @@+import { prisma } from "@langfuse/shared/src/db";+import { withMiddlewares } from "@/src/features/public-api/server/withMiddlewares";+import { createAuthedAPIRoute } from "@/src/features/public-api/server/createAuthedAPIRoute";+import {+ GetAnnotationQueueItemsQuery,+ GetAnnotationQueueItemsResponse,+ CreateAnnotationQueueItemBody,+ CreateAnnotationQueueItemResponse,+} from "@/src/features/public-api/types/annotation-queues";+import { LangfuseNotFoundError } from "@langfuse/shared";+import { AnnotationQueueStatus } from "@langfuse/shared";++export default withMiddlewares({+ GET: createAuthedAPIRoute({+ name: "Get annotation queue items",+ querySchema: GetAnnotationQueueItemsQuery,+ responseSchema: GetAnnotationQueueItemsResponse,+ fn: async ({ query, auth }) => {+ // Verify the queue exists+ const queue = await prisma.annotationQueue.findUnique({+ where: {+ id: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!queue) {+ throw new LangfuseNotFoundError("Annotation queue not found");+ }++ // Build the where clause based on the query parameters+ const where: {+ projectId: string;+ queueId: string;+ status?: AnnotationQueueStatus;+ } = {+ projectId: auth.scope.projectId,+ queueId: query.queueId,+ };++ if (query.status) {+ where.status = query.status;+ }++ const [items, totalItems] = await Promise.all([+ prisma.annotationQueueItem.findMany({+ where,+ orderBy: [+ {+ createdAt: "desc",+ },+ {+ id: "desc",+ },+ ],+ take: query.limit,+ skip: (query.page - 1) * query.limit,+ }),+ prisma.annotationQueueItem.count({+ where,+ }),+ ]);++ return {+ data: items.map((item) => ({+ id: item.id,+ queueId: item.queueId,+ objectId: item.objectId,+ objectType: item.objectType,+ status: item.status,+ completedAt: item.completedAt,+ createdAt: item.createdAt,+ updatedAt: item.updatedAt,+ })),+ meta: {+ page: query.page,+ limit: query.limit,+ totalItems,+ totalPages: Math.ceil(totalItems / query.limit),+ },+ };+ },+ }),+ POST: createAuthedAPIRoute({+ name: "Create annotation queue item",+ querySchema: GetAnnotationQueueItemsQuery,+ bodySchema: CreateAnnotationQueueItemBody,+ responseSchema: CreateAnnotationQueueItemResponse,+ fn: async ({ query, body, auth }) => {+ // Check if the queue exists+ const queue = await prisma.annotationQueue.findUnique({+ where: {+ id: query.queueId,+ projectId: auth.scope.projectId,+ },+ });++ if (!queue) {+ throw new LangfuseNotFoundError("Annotation queue not found");+ }++ // Create the queue item with status defaulting to PENDING if not provided+ const status = body.status || AnnotationQueueStatus.PENDING;++ // Set completedAt if status is COMPLETED+ const completedAt =+ status === AnnotationQueueStatus.COMPLETED ? new Date() : null;++ const item = await prisma.annotationQueueItem.create({+ data: {+ queueId: query.queueId,+ objectId: body.objectId,+ objectType: body.objectType,+ status,+ completedAt,+ projectId: auth.scope.projectId,+ },+ });++ return {+ id: item.id,+ queueId: item.queueId,+ objectId: item.objectId,+ objectType: item.objectType,+ status: item.status,+ completedAt: item.completedAt,+ createdAt: item.createdAt,+ updatedAt: item.updatedAt,+ };+ },+ }),+});diff --git a/web/src/pages/api/public/annotation-queues/index.ts b/web/src/pages/api/public/annotation-queues/index.tsnew file mode 100644index 0000000000..e1b51c7087--- /dev/null+++ b/web/src/pages/api/public/annotation-queues/index.ts@@ -0,0 +1,57 @@+import { prisma } from "@langfuse/shared/src/db";+import { withMiddlewares } from "@/src/features/public-api/server/withMiddlewares";+import { createAuthedAPIRoute } from "@/src/features/public-api/server/createAuthedAPIRoute";+import {+ GetAnnotationQueuesQuery,+ GetAnnotationQueuesResponse,+} from "@/src/features/public-api/types/annotation-queues";++export default withMiddlewares({+ // NOTE: Post API requires entitlement check+ GET: createAuthedAPIRoute({+ name: "Get annotation queues",+ querySchema: GetAnnotationQueuesQuery,+ responseSchema: GetAnnotationQueuesResponse,+ fn: async ({ query, auth }) => {+ const [queues, totalItems] = await Promise.all([+ prisma.annotationQueue.findMany({+ where: {+ projectId: auth.scope.projectId,+ },+ orderBy: [+ {+ createdAt: "desc",+ },+ {+ id: "desc",+ },+ ],+ take: query.limit,+ skip: (query.page - 1) * query.limit,+ }),+ prisma.annotationQueue.count({+ where: {+ projectId: auth.scope.projectId,+ },+ }),+ ]);++ return {+ data: queues.map((queue) => ({+ id: queue.id,+ name: queue.name,+ description: queue.description,+ scoreConfigIds: queue.scoreConfigIds,+ createdAt: queue.createdAt,+ updatedAt: queue.updatedAt,+ })),+ meta: {+ page: query.page,+ limit: query.limit,+ totalItems,+ totalPages: Math.ceil(totalItems / query.limit),+ },+ };+ },+ }),+});