Elffuss BraidHub

kikocis/continue public

main · 5.9 KiBRawPermalink
1import { z } from "zod";
2import { requestOptionsSchema } from "../models.js";
3import { autocompleteEventAllSchema } from "./autocomplete/index.js";
4import {
5 autocompleteEventSchema_0_1_0,
6 autocompleteEventSchema_0_1_0_noCode,
7} from "./autocomplete/v0.1.0.js";
8import {
9 autocompleteEventSchema_0_2_0,
10 autocompleteEventSchema_0_2_0_noCode,
11} from "./autocomplete/v0.2.0.js";
12import { chatFeedbackEventAllSchema } from "./chatFeedback/index.js";
13import {
14 chatFeedbackEventSchema_0_1_0,
15 chatFeedbackEventSchema_0_1_0_noCode,
16} from "./chatFeedback/v0.1.0.js";
17import {
18 chatFeedbackEventSchema_0_2_0,
19 chatFeedbackEventSchema_0_2_0_noCode,
20} from "./chatFeedback/v0.2.0.js";
21import { chatInteractionEventAllSchema } from "./chatInteraction/index.js";
22import {
23 chatInteractionEventSchema_0_2_0,
24 chatInteractionEventSchema_0_2_0_noCode,
25} from "./chatInteraction/v0.2.0.js";
26import { editInteractionEventAllSchema } from "./editInteraction/index.js";
27import {
28 editInteractionEventSchema_0_2_0,
29 editInteractionEventSchema_0_2_0_noCode,
30} from "./editInteraction/v0.2.0.js";
31import { editOutcomeEventAllSchema } from "./editOutcome/index.js";
32import {
33 editOutcomeEventSchema_0_2_0,
34 editOutcomeEventSchema_0_2_0_noCode,
35} from "./editOutcome/v0.2.0.js";
36import { nextEditOutcomeEventAllSchema } from "./nextEditOutcome/index.js";
37import {
38 nextEditOutcomeEventSchema_0_2_0,
39 nextEditOutcomeEventSchema_0_2_0_noCode,
40} from "./nextEditOutcome/v0.2.0.js";
41import { nextEditEventAllSchema } from "./nextEditWithHistory/index.js";
42import {
43 nextEditEventSchema_0_2_0,
44 nextEditEventSchema_0_2_0_noCode,
45} from "./nextEditWithHistory/v0.2.0.js";
46import { quickEditEventAllSchema } from "./quickEdit/index.js";
47import {
48 quickEditEventSchema_0_1_0,
49 quickEditEventSchema_0_1_0_noCode,
50} from "./quickEdit/v0.1.0.js";
51import { tokensGeneratedEventAllSchema } from "./tokensGenerated/index.js";
52import {
53 tokensGeneratedEventSchema_0_1_0,
54 tokensGeneratedEventSchema_0_1_0_noCode,
55} from "./tokensGenerated/v0.1.0.js";
56import {
57 tokensGeneratedEventSchema_0_2_0,
58 tokensGeneratedEventSchema_0_2_0_noCode,
59} from "./tokensGenerated/v0.2.0.js";
60import { toolUsageEventAllSchema } from "./toolUsage/index.js";
61import {
62 toolUsageEventSchema_0_2_0,
63 toolUsageEventSchema_0_2_0_noCode,
64} from "./toolUsage/v0.2.0.js";
65
66const semverRegex =
67 /^(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-]+)*))?$/;
68
69const dataLevel = z.union([z.literal("all"), z.literal("noCode")]);
70
71export const dataSchema = z.object({
72 name: z.string(),
73 destination: z.string(),
74 schema: z.string().regex(semverRegex, {
75 message: "Version must follow semver format, e.g. 0.2.0",
76 }),
77 level: dataLevel.optional(),
78 events: z.array(z.string()).optional(), // Could do literals e.g. "autocomplete", "chat" but want to allow some flexibility later
79 requestOptions: requestOptionsSchema.optional(),
80 apiKey: z.string().optional(),
81});
82
83export type DataDestination = z.infer<typeof dataSchema>;
84export type DataLogLevel = z.infer<typeof dataLevel>;
85
86// Schemas for data that the log function should have
87// In order to build event bodies for ALL versions of an event
88const devEventAllVersionDataSchemas = z.object({
89 autocomplete: autocompleteEventAllSchema,
90 quickEdit: quickEditEventAllSchema,
91 chatFeedback: chatFeedbackEventAllSchema,
92 tokensGenerated: tokensGeneratedEventAllSchema,
93 chatInteraction: chatInteractionEventAllSchema,
94 editInteraction: editInteractionEventAllSchema,
95 editOutcome: editOutcomeEventAllSchema,
96 nextEditOutcome: nextEditOutcomeEventAllSchema,
97 nextEditWithHistory: nextEditEventAllSchema,
98 toolUsage: toolUsageEventAllSchema,
99});
100
101// Version and level specific schemas are organized here
102export const devDataVersionedSchemas = {
103 ["0.1.0" as string]: {
104 all: {
105 autocomplete: autocompleteEventSchema_0_1_0,
106 quickEdit: quickEditEventSchema_0_1_0,
107 chatFeedback: chatFeedbackEventSchema_0_1_0,
108 tokensGenerated: tokensGeneratedEventSchema_0_1_0,
109 },
110 noCode: {
111 autocomplete: autocompleteEventSchema_0_1_0_noCode,
112 quickEdit: quickEditEventSchema_0_1_0_noCode,
113 chatFeedback: chatFeedbackEventSchema_0_1_0_noCode,
114 tokensGenerated: tokensGeneratedEventSchema_0_1_0_noCode,
115 },
116 },
117 ["0.2.0" as string]: {
118 all: {
119 autocomplete: autocompleteEventSchema_0_2_0,
120 chatFeedback: chatFeedbackEventSchema_0_2_0,
121 tokensGenerated: tokensGeneratedEventSchema_0_2_0,
122 chatInteraction: chatInteractionEventSchema_0_2_0,
123 editInteraction: editInteractionEventSchema_0_2_0,
124 editOutcome: editOutcomeEventSchema_0_2_0,
125 nextEditOutcome: nextEditOutcomeEventSchema_0_2_0,
126 nextEditWithHistory: nextEditEventSchema_0_2_0,
127 toolUsage: toolUsageEventSchema_0_2_0,
128 },
129 noCode: {
130 autocomplete: autocompleteEventSchema_0_2_0_noCode,
131 chatFeedback: chatFeedbackEventSchema_0_2_0_noCode,
132 tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode,
133 chatInteraction: chatInteractionEventSchema_0_2_0_noCode,
134 editInteraction: editInteractionEventSchema_0_2_0_noCode,
135 editOutcome: editOutcomeEventSchema_0_2_0_noCode,
136 nextEditOutcome: nextEditOutcomeEventSchema_0_2_0_noCode,
137 nextEditWithHistory: nextEditEventSchema_0_2_0_noCode,
138 toolUsage: toolUsageEventSchema_0_2_0_noCode,
139 },
140 },
141};
142
143type DevEventDataSchemas = z.infer<typeof devEventAllVersionDataSchemas>;
144export type DevEventName = keyof DevEventDataSchemas;
145type DevEventAllVersionsSchema<T extends DevEventName> = DevEventDataSchemas[T];
146
147export type DevDataLogEvent = {
148 [K in DevEventName]: {
149 name: K;
150 data: Omit<
151 DevEventAllVersionsSchema<K>,
152 | "eventName"
153 | "schema"
154 | "timestamp"
155 | "userId"
156 | "userAgent"
157 | "selectedProfileId"
158 >;
159 };
160}[DevEventName];
161
162export const allDevEventNames = Object.keys(
163 devEventAllVersionDataSchemas.shape,
164) as DevEventName[];