Skip to content

Commit

Permalink
feature: add more analytics events (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
geclos authored Oct 1, 2024
1 parent a8f513d commit 7e73cca
Show file tree
Hide file tree
Showing 82 changed files with 3,451 additions and 642 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('GET documents', () => {
user,
})
const document = await createDocumentVersion({
workspace,
user,
commit,
path,
content: helpers.createPrompt({ provider: providers[0]! }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ describe('POST /run', () => {
user,
})
const document = await createDocumentVersion({
workspace,
user,
commit: cmt,
path,
content: helpers.createPrompt({ provider: providers[0]! }),
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/actions/commits/deleteDraftCommit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ describe('getUsersAction', () => {
user,
})
await factories.createDocumentVersion({
workspace,
user,
commit: draft,
path: 'patata/doc1',
content: factories.helpers.createPrompt({ provider }),
})
await factories.createDocumentVersion({
workspace,
user,
commit: anotherDraf,
path: 'patata/doc2',
content: factories.helpers.createPrompt({ provider }),
Expand Down
11 changes: 11 additions & 0 deletions apps/web/src/actions/commits/publishDraftCommitAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use server'

import { publisher } from '@latitude-data/core/events/publisher'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { mergeCommit } from '@latitude-data/core/services/commits/merge'
import { z } from 'zod'
Expand All @@ -15,5 +16,15 @@ export const publishDraftCommitAction = withProject
.getCommitById(input.id)
.then((r) => r.unwrap())
const merged = await mergeCommit(commit).then((r) => r.unwrap())

publisher.publishLater({
type: 'commitPublished',
data: {
commit: merged,
userEmail: ctx.user.email,
workspaceId: ctx.workspace.id,
},
})

return merged
})
6 changes: 5 additions & 1 deletion apps/web/src/actions/connectedEvaluations/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ describe('updateConnectedEvaluationAction', () => {
user = setup.user

// Create a connected evaluation using a factory
const evaluation = await factories.createLlmAsJudgeEvaluation({ workspace })
const evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
user,
})
const { commit } = await factories.createDraft({ project, user })
const { documentLog } = await factories.createDocumentLog({
document: setup.documents[0]!,
commit,
})

connectedEvaluation = await factories.createConnectedEvaluation({
user,
workspace,
evaluationUuid: evaluation.uuid,
documentUuid: documentLog.documentUuid,
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/actions/datasets/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const createDatasetAction = authProcedure
input.csvDelimiter === 'custom'
? input.csvCustomDelimiter
: DELIMITER_VALUES[input.csvDelimiter]

return createDataset({
workspace: ctx.workspace,
author: ctx.user,
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/actions/documents/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const createDocumentVersionAction = withProject
.then((r) => r.unwrap())

const result = await createNewDocument({
workspace: ctx.workspace,
user: ctx.user,
commit,
path: input.path,
})
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/actions/evaluations/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('connectEvaluationsAction', () => {
it('connects evaluations and templates to a document', async () => {
const evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
user,
name: 'Test Evaluation',
prompt: factories.helpers.createPrompt({ provider }),
})
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/actions/evaluations/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const connectEvaluationsAction = withProject
documentUuid: input.documentUuid,
evaluationUuids: input.evaluationUuids,
templateIds: input.templateIds,
user: ctx.user,
}).then((r) => r.unwrap())

return connectedEvaluations
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/actions/evaluations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const createEvaluationAction = authProcedure
metadata: input.metadata,
configuration: input.configuration,
type: input.type,
user: ctx.user,
})

return result.unwrap()
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/actions/evaluations/destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('destroyEvaluationAction', () => {
})
const evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
user: userData,
prompt: factories.helpers.createPrompt({ provider }),
})
evaluationId = evaluation.id
Expand Down Expand Up @@ -68,6 +69,7 @@ describe('destroyEvaluationAction', () => {
})
evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
user,
prompt: factories.helpers.createPrompt({ provider }),
})

Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/actions/evaluations/runBatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const mocks = vi.hoisted(() => ({
jobs: {
enqueueCreateEventJob: vi.fn(),
enqueuePublishEventJob: vi.fn(),
enqueuePublishToAnalyticsJob: vi.fn(),
},
},
},
Expand Down Expand Up @@ -91,6 +92,7 @@ describe('runBatchAction', () => {
.then((result) => result.dataset)

evaluation = await factories.createLlmAsJudgeEvaluation({
user,
workspace,
name: 'Test Evaluation',
})
Expand Down Expand Up @@ -179,6 +181,7 @@ describe('runBatchAction', () => {

it('enqueues multiple evaluation jobs for multiple evaluationIds', async () => {
const evaluation2 = await factories.createLlmAsJudgeEvaluation({
user,
workspace,
name: 'Test Evaluation 2',
})
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/actions/evaluations/runBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export const runBatchEvaluationAction = withDataset
const queues = await setupJobs()
evaluations.forEach((evaluation) => {
const batchId = `evaluation:${evaluation.id}:${nanoid(5)}`

queues.defaultQueue.jobs.enqueueRunBatchEvaluationJob({
workspace: ctx.workspace,
user: ctx.user,
evaluation,
dataset: ctx.dataset,
document: ctx.document,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/providerApiKeys/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const createProviderApiKeyAction = authProcedure
provider: input.provider,
token: input.token,
name: input.name,
authorId: ctx.user.id,
author: ctx.user,
})
.then((r) => r.unwrap())
.then(providerApiKeyPresenter)
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/providerApiKeys/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('getProviderApiKeyAction', async () => {
// openai example apikey token
token: 'sk-1234567890abcdef1234567890abcdef',
workspace: session!.workspace,
author: session!.userData,
name: 'foo',
authorId: session!.userData.id,
})

const [data, error] = await getProviderApiKeyAction()
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/actions/user/setupAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const setupAction = errorHandlingProcedure
.handler(async ({ input }) => {
const result = await setupService(input)
const { user } = result.unwrap()

await createMagicLinkToken({ user: user }).then((r) => r.unwrap())

redirect(ROUTES.auth.magicLinkSent(user.email))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ describe('GET /api/documents/[projectId]/[commitUuid]/[documentUuid]/evaluations
mockEvaluations = [
await factories.createConnectedEvaluation({
workspace,
user: setup.user,
documentUuid: documents[0]!.documentUuid,
}),
await factories.createConnectedEvaluation({
workspace,
user: setup.user,
documentUuid: documents[1]!.documentUuid,
}),
]
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/services/user/setupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function setupService({
provider: Providers.OpenAI,
name: env.DEFAULT_PROVIDER_ID,
token: env.DEFAULT_PROVIDER_API_KEY,
authorId: user.id,
author: user,
},
tx,
)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"nodemailer-html-to-text": "^3.2.0",
"nodemailer-mailgun-transport": "^2.1.5",
"pg": "^8.12.0",
"posthog-node": "^4.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-resizable": "^3.0.5",
Expand Down
24 changes: 24 additions & 0 deletions packages/core/drizzle/0061_orange_master_mold.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Unfortunately in current drizzle-kit version we can't automatically get name for primary key.
We are working on making it available!
Meanwhile you can:
1. Check pk name in your database, by running
SELECT constraint_name FROM information_schema.table_constraints
WHERE table_schema = 'latitude'
AND table_name = 'events'
AND constraint_type = 'PRIMARY KEY';
2. Uncomment code below and paste pk name manually
Hope to release this update as soon as possible
*/

-- ALTER TABLE "events" DROP CONSTRAINT "<constraint_name>";--> statement-breakpoint
ALTER TABLE "latitude"."events" ADD COLUMN "workspace_id" bigint;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "latitude"."events" ADD CONSTRAINT "events_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "latitude"."workspaces"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "event_workspace_idx" ON "latitude"."events" USING btree ("workspace_id");
Loading

0 comments on commit 7e73cca

Please sign in to comment.