-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
5,501 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use server' | ||
|
||
import { findAllEvaluationTemplates } from '@latitude-data/core/data-access' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const fetchEvaluationTemplatesAction = authProcedure | ||
.createServerAction() | ||
.handler(async () => { | ||
const result = await findAllEvaluationTemplates() | ||
return result.unwrap() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { randomUUID } from 'crypto' | ||
|
||
import { | ||
Commit, | ||
DocumentVersion, | ||
Project, | ||
ProviderApiKey, | ||
Providers, | ||
User, | ||
Workspace, | ||
} from '@latitude-data/core/browser' | ||
import * as factories from '@latitude-data/core/factories' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { connectEvaluationsAction } from './connect' | ||
|
||
const mocks = vi.hoisted(() => { | ||
return { | ||
getSession: vi.fn(), | ||
} | ||
}) | ||
|
||
vi.mock('$/services/auth/getSession', () => ({ | ||
getSession: mocks.getSession, | ||
})) | ||
|
||
describe('connectEvaluationsAction', () => { | ||
describe('unauthorized', () => { | ||
it('errors when the user is not authenticated', async () => { | ||
const [_, error] = await connectEvaluationsAction({ | ||
projectId: 1, | ||
documentUuid: 'fake-document-uuid', | ||
commitUuid: 'fake-commit-uuid', | ||
templateIds: [1], | ||
evaluationUuids: ['fake-evaluation-uuid'], | ||
}) | ||
|
||
expect(error!.name).toEqual('UnauthorizedError') | ||
}) | ||
}) | ||
|
||
describe('authorized', () => { | ||
let workspace: Workspace, | ||
user: User, | ||
document: DocumentVersion, | ||
commit: Commit, | ||
provider: ProviderApiKey, | ||
project: Project | ||
|
||
beforeEach(async () => { | ||
const setup = await factories.createProject({ | ||
documents: { 'test-doc': 'Test content' }, | ||
}) | ||
workspace = setup.workspace | ||
user = setup.user | ||
document = setup.documents[0]! | ||
commit = setup.commit | ||
project = setup.project | ||
|
||
provider = await factories.createProviderApiKey({ | ||
workspace, | ||
type: Providers.OpenAI, | ||
name: 'Test Provider', | ||
user, | ||
}) | ||
|
||
mocks.getSession.mockReturnValue({ | ||
user, | ||
workspace: { id: workspace.id, name: workspace.name }, | ||
}) | ||
}) | ||
|
||
it('connects evaluations and templates to a document', async () => { | ||
const evaluation = await factories.createEvaluation({ | ||
provider, | ||
name: 'Test Evaluation', | ||
}) | ||
|
||
const template = await factories.createEvaluationTemplate({ | ||
name: 'Test Template', | ||
description: 'Test description', | ||
prompt: 'Test prompt', | ||
}) | ||
|
||
const [result, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: document.documentUuid, | ||
commitUuid: commit.uuid, | ||
templateIds: [template.id], | ||
evaluationUuids: [evaluation.uuid], | ||
}) | ||
|
||
expect(error).toBeNull() | ||
expect(result).toHaveLength(2) | ||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
documentUuid: document.documentUuid, | ||
evaluationId: evaluation.id, | ||
}), | ||
expect.objectContaining({ | ||
documentUuid: document.documentUuid, | ||
evaluationId: expect.any(Number), | ||
}), | ||
]), | ||
) | ||
}) | ||
|
||
it('returns an empty array when no evaluations or templates are provided', async () => { | ||
const [result, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: document.documentUuid, | ||
commitUuid: commit.uuid, | ||
templateIds: [], | ||
evaluationUuids: [], | ||
}) | ||
|
||
expect(error).toBeNull() | ||
expect(result).toHaveLength(0) | ||
}) | ||
|
||
it('fails when the document does not exist', async () => { | ||
const [_, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: 'non-existent-uuid', | ||
commitUuid: randomUUID(), | ||
templateIds: [], | ||
evaluationUuids: [], | ||
}) | ||
|
||
expect(error!.name).toEqual('NotFoundError') | ||
}) | ||
|
||
it('fails when the commit does not exist', async () => { | ||
const [_, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: document.documentUuid, | ||
commitUuid: randomUUID(), | ||
templateIds: [], | ||
evaluationUuids: [], | ||
}) | ||
|
||
expect(error!.name).toEqual('NotFoundError') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use server' | ||
|
||
import { findAllEvaluationTemplates } from '@latitude-data/core/data-access' | ||
import { | ||
DocumentVersionsRepository, | ||
EvaluationsRepository, | ||
} from '@latitude-data/core/repositories' | ||
import { connectEvaluations } from '@latitude-data/core/services/evaluations/connect' | ||
import { z } from 'zod' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const connectEvaluationsAction = withProject | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
documentUuid: z.string(), | ||
commitUuid: z.string(), | ||
templateIds: z.array(z.number()), | ||
evaluationUuids: z.array(z.string()), | ||
}), | ||
) | ||
.handler(async ({ ctx, input }) => { | ||
const evaluationTemplates = await findAllEvaluationTemplates().then((r) => | ||
r.unwrap(), | ||
) | ||
const scope = new EvaluationsRepository(ctx.workspace.id) | ||
const evaluations = await scope.findAll().then((r) => r.unwrap()) | ||
|
||
const selectedTemplates = evaluationTemplates.filter((template) => | ||
input.templateIds.includes(template.id), | ||
) | ||
const selectedEvaluations = evaluations.filter((evaluation) => | ||
input.evaluationUuids.includes(evaluation.uuid), | ||
) | ||
|
||
const documentsScope = new DocumentVersionsRepository(ctx.workspace.id) | ||
const document = await documentsScope | ||
.getDocumentAtCommit({ | ||
projectId: ctx.project.id, | ||
commitUuid: input.commitUuid, | ||
documentUuid: input.documentUuid, | ||
}) | ||
.then((r) => r.unwrap()) | ||
|
||
const connectedEvaluations = await connectEvaluations({ | ||
document, | ||
templates: selectedTemplates, | ||
evaluations: selectedEvaluations, | ||
}).then((r) => r.unwrap()) | ||
|
||
return connectedEvaluations | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
'use server' | ||
|
||
import { EvaluationsRepository } from '@latitude-data/core/repositories' | ||
import { z } from 'zod' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const fetchEvaluationsAction = authProcedure | ||
.createServerAction() | ||
.handler(async ({ ctx }) => { | ||
const evaluationsScope = new EvaluationsRepository(ctx.workspace.id) | ||
const evaluations = await evaluationsScope.findAll().then((r) => r.unwrap()) | ||
.input(() => z.object({ documentUuid: z.string().optional() }).optional()) | ||
.handler(async ({ ctx, input }) => { | ||
const scope = new EvaluationsRepository(ctx.workspace.id) | ||
let result | ||
if (input?.documentUuid) { | ||
result = await scope.findByDocumentUuid(input.documentUuid) | ||
} else { | ||
result = await scope.findAll() | ||
} | ||
|
||
return evaluations | ||
return result.unwrap() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
apps/web/src/app/(private)/evaluations/_components/ActiveEvaluations/Table/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client' | ||
|
||
import { Evaluation } from '@latitude-data/core/browser' | ||
import { | ||
Icon, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.