dev data schemas

This commit is contained in:
Dallin Romney 2025-01-31 12:13:54 -08:00
parent ca696ba6d0
commit 7dc1b51867
15 changed files with 102 additions and 31 deletions

View file

@ -1,12 +1,12 @@
{
"name": "@continuedev/config-yaml",
"version": "1.0.23",
"version": "1.0.24",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@continuedev/config-yaml",
"version": "1.0.23",
"version": "1.0.24",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/config-types": "^1.0.14",

View file

@ -1,3 +1,5 @@
import { z } from "zod";
export const baseSchema = z.object({});
export const baseSchema = z.object({
userId: z.string(),
});

View file

@ -1,6 +1,6 @@
import { z } from "zod";
export const chatDevDataSchema = z.object({
export const chatFeedbackEventAllSchema = z.object({
modelTitle: z.string(),
completionOptions: z.object({}),
prompt: z.string(),

View file

@ -0,0 +1,16 @@
import { chatFeedbackEventAllSchema } from "./index.js";
export const chatFeedbackEventSchema_0_1_0 = chatFeedbackEventAllSchema.pick({
modelTitle: true,
completionOptions: true,
prompt: true,
completion: true,
feedback: true,
sessionId: true,
});
export const chatFeedbackEventSchema_0_1_0_noPII =
chatFeedbackEventSchema_0_1_0.omit({
prompt: true,
completion: true,
});

View file

@ -0,0 +1,12 @@
import { chatFeedbackEventAllSchema } from "./index.js";
export const chatFeedbackEventSchema_0_2_0 = chatFeedbackEventAllSchema.pick({
prompt: true,
completion: true,
});
export const chatFeedbackEventSchema_0_2_0_noPII =
chatFeedbackEventAllSchema.omit({
prompt: true,
completion: true,
});

View file

@ -0,0 +1,4 @@
import { z } from "zod";
// Edit event is not yet implemented
const editEventAllSchema = z.object({});

View file

@ -1,19 +1,37 @@
import { z, ZodObject } from "zod";
import { z } from "zod";
import { autocompleteEventAllSchema } from "./autocomplete/index.js";
import { requestOptionsSchema } from "../models.js";
import {
autocompleteEventSchema_0_1_0,
autocompleteEventSchema_0_1_0_noPII,
} from "./autocomplete/0.1.0.js";
} from "./autocomplete/v0.1.0.js";
import {
quickEditEventSchema_0_1_0,
quickEditEventSchema_0_1_0_noPII,
} from "./quickEdit/0.1.0.js";
} from "./quickEdit/v0.1.0.js";
import {
autocompleteEventSchema_0_2_0,
autocompleteEventSchema_0_2_0_noPII,
} from "./autocomplete/0.2.0.js";
} from "./autocomplete/v0.2.0.js";
import { quickEditEventAllSchema } from "./quickEdit/index.js";
import { chatFeedbackEventAllSchema } from "./chatFeedback/index.js";
import { tokensGeneratedEventAllSchema } from "./tokensGenerated/index.js";
import {
chatFeedbackEventSchema_0_1_0,
chatFeedbackEventSchema_0_1_0_noPII,
} from "./chatFeedback/v0.1.0.js";
import {
tokensGeneratedEventSchema_0_1_0,
tokensGeneratedEventSchema_0_1_0_noPII,
} from "./tokensGenerated/v0.1.0.js";
import {
chatFeedbackEventSchema_0_2_0,
chatFeedbackEventSchema_0_2_0_noPII,
} from "./chatFeedback/v0.2.0.js";
import {
tokensGeneratedEventSchema_0_2_0,
tokensGeneratedEventSchema_0_2_0_noPII,
} from "./tokensGenerated/v0.2.0.js";
const semverRegex =
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
@ -23,10 +41,10 @@ const dataLevel = z.union([z.literal("all"), z.literal("noPII")]);
export const dataSchema = z.object({
name: z.string(),
destination: z.string().url(),
version: z.string().regex(semverRegex, {
schemaVersion: z.string().regex(semverRegex, {
message: "Version must follow semver format, e.g. 0.2.0",
}),
level: dataLevel.optional(), // Could do literals
level: dataLevel.optional(),
events: z.array(z.string()).optional(), // Could do literals e.g. "autocomplete", "chat" but want to allow some flexibility later
requestOptions: requestOptionsSchema.optional(),
apiKey: z.string().optional(),
@ -35,50 +53,52 @@ export const dataSchema = z.object({
export type DataDestination = z.infer<typeof dataSchema>;
export type DataLogLevel = z.infer<typeof dataLevel>;
// export const devEventDataSchemas = z.object({
// tokensGenerated: tokensGeneratedDevDataSchema,
// chat: chatDevDataSchema,
// quickEdit: quickEditEventData,
// autocomplete: autocompleteEventData,
// });
// Schemas for data that the log function should have
// In order to build event bodies for ALL versions of an event
const devEventAllVersionDataSchemas = z.object({
autocomplete: autocompleteEventAllSchema,
quickEdit: quickEditEventAllSchema,
chatFeedback: chatFeedbackEventAllSchema,
tokensGenerated: tokensGeneratedEventAllSchema,
});
// Here all schemas are organized by version and level
// Version and level specific schemas are organized here
export const devDataVersionedSchemas = {
["0.1.0" as string]: {
all: {
autocomplete: autocompleteEventSchema_0_1_0,
quickEdit: quickEditEventSchema_0_1_0,
chatFeedback: chatFeedbackEventSchema_0_1_0,
tokensGenerated: tokensGeneratedEventSchema_0_1_0,
},
noPII: {
autocomplete: autocompleteEventSchema_0_1_0_noPII,
quickEdit: quickEditEventSchema_0_1_0_noPII,
chatFeedback: chatFeedbackEventSchema_0_1_0_noPII,
tokensGenerated: tokensGeneratedEventSchema_0_1_0_noPII,
},
},
["0.2.0" as string]: {
all: {
autocomplete: autocompleteEventSchema_0_2_0,
// chat: blockSchema,
// edit: blockItemWrapperSchema,
// tokensGenerated: blockSchema,
chatFeedback: chatFeedbackEventSchema_0_2_0,
tokensGenerated: tokensGeneratedEventSchema_0_2_0,
},
noPII: {
autocomplete: autocompleteEventSchema_0_2_0_noPII,
chatFeedback: chatFeedbackEventSchema_0_2_0_noPII,
tokensGenerated: tokensGeneratedEventSchema_0_2_0_noPII,
},
},
};
type DevEventDataSchemas = z.infer<typeof devEventAllVersionDataSchemas>;
type DevEventName = keyof DevEventDataSchemas;
export type DevEventName = keyof DevEventDataSchemas;
type DevEventAllVersionsSchema<T extends DevEventName> = DevEventDataSchemas[T];
export type DevDataLogEvent = {
[K in DevEventName]: {
schema: K;
name: K;
data: DevEventAllVersionsSchema<K>;
};
}[DevEventName];

View file

@ -1,15 +1,8 @@
import { z } from "zod";
export const tokensGeneratedEventData = z.object({
export const tokensGeneratedEventAllSchema = z.object({
model: z.string(),
provider: z.string(),
promptTokens: z.number(),
generatedTokens: z.number(),
});
export const tokensGeneratedEventV1Schema = tokensGeneratedEventData.pick({
model: true,
provider: true,
promptTokens: true,
generatedTokens: true,
});

View file

@ -0,0 +1,12 @@
import { tokensGeneratedEventAllSchema } from "./index.js";
export const tokensGeneratedEventSchema_0_1_0 =
tokensGeneratedEventAllSchema.pick({
model: true,
provider: true,
promptTokens: true,
generatedTokens: true,
});
export const tokensGeneratedEventSchema_0_1_0_noPII =
tokensGeneratedEventSchema_0_1_0;

View file

@ -0,0 +1,12 @@
import { tokensGeneratedEventAllSchema } from "./index.js";
export const tokensGeneratedEventSchema_0_2_0 =
tokensGeneratedEventAllSchema.pick({
model: true,
provider: true,
promptTokens: true,
generatedTokens: true,
});
export const tokensGeneratedEventSchema_0_2_0_noPII =
tokensGeneratedEventSchema_0_2_0;