fix base schema inclusions

This commit is contained in:
Dallin Romney 2025-02-17 18:02:42 -08:00
parent 57ec041638
commit 66238d9b99
9 changed files with 131 additions and 75 deletions

View file

@ -104,6 +104,7 @@ export class Core {
progress: 0,
};
const ideInfoPromise = messenger.request("getIdeInfo", undefined);
const ideSettingsPromise = messenger.request("getIdeSettings", undefined);
const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", {
silent: true,
@ -144,6 +145,8 @@ export class Core {
// Dev Data Logger
const dataLogger = DataLogger.getInstance();
dataLogger.core = this;
dataLogger.ideInfoPromise = ideInfoPromise;
dataLogger.ideSettingsPromise = ideSettingsPromise;
// Codebase Indexer and ContinueServerClient depend on IdeSettings
let codebaseIndexerResolve: (_: any) => void | undefined;

View file

@ -13,12 +13,16 @@ import { fetchwithRequestOptions } from "@continuedev/fetch";
import { joinPathsToUri } from "../util/uri.js";
import * as URI from "uri-js";
import { fileURLToPath } from "url";
import { ZodObject } from "zod";
import { IdeInfo, IdeSettings } from "../index.js";
const DEFAULT_DEV_DATA_LEVEL: DataLogLevel = "all";
export const LOCAL_DEV_DATA_VERSION = "0.2.0";
export class DataLogger {
private static instance: DataLogger | null = null;
core?: Core;
ideSettingsPromise?: Promise<IdeSettings>;
ideInfoPromise?: Promise<IdeInfo>;
private constructor() {}
@ -29,28 +33,39 @@ export class DataLogger {
return DataLogger.instance;
}
addBaseValues(body: object, eventName: string, schema: string): object {
if ("eventName" in body) {
body.eventName = eventName;
async addBaseValues(
body: Record<string, any>,
eventName: string,
schema: string,
zodSchema: ZodObject<any>,
): Promise<Record<string, any>> {
const newBody = { ...body };
const ideSettings = await this.ideSettingsPromise;
const ideInfo = await this.ideInfoPromise;
if ("eventName" in zodSchema.shape) {
newBody.eventName = eventName;
}
if ("createdAt" in body) {
body.createdAt = new Date().toISOString();
if ("timestamp" in zodSchema.shape) {
newBody.timestamp = new Date().toISOString();
}
if ("schema" in body) {
body.schema = schema;
if ("schema" in zodSchema.shape) {
newBody.schema = schema;
}
if ("userAgent" in body) {
body.userAgent = navigator.userAgent; // TODO sufficient user agent info?
if ("userAgent" in zodSchema.shape) {
newBody.userAgent = ideInfo
? `${ideInfo.name}/${ideInfo.version} (Continue/${ideInfo.extensionVersion})`
: "Unknown/Unknown (Continue/Unknown)";
}
if ("selectedProfileId" in body) {
body.selectedProfileId =
if ("selectedProfileId" in zodSchema.shape) {
newBody.selectedProfileId =
this.core?.configHandler.currentProfile?.profileDescription.id ?? "";
}
if ("userId" in body) {
body.userId = "not-implemented";
if ("userId" in zodSchema.shape) {
newBody.userId = ideSettings?.userToken ?? "";
}
return body;
return newBody;
}
async logDevData(event: DevDataLogEvent) {
@ -62,14 +77,23 @@ export class DataLogger {
);
const localSchema =
devDataVersionedSchemas[LOCAL_DEV_DATA_VERSION]["all"][event.name];
const parsed = localSchema?.safeParse(event.data);
if (parsed?.success) {
const withBaseValues = this.addBaseValues(
parsed.data,
event.name,
LOCAL_DEV_DATA_VERSION,
if (!localSchema) {
throw new Error(
`Schema ${LOCAL_DEV_DATA_VERSION} doesn't exist at level "all"`,
);
fs.writeFileSync(filepath, `${JSON.stringify(withBaseValues)}\n`, {
}
const eventDataWithBaseValues = await this.addBaseValues(
event.data,
event.name,
LOCAL_DEV_DATA_VERSION,
localSchema,
);
const parsed = localSchema?.safeParse(eventDataWithBaseValues);
if (parsed?.success) {
fs.writeFileSync(filepath, `${JSON.stringify(parsed.data)}\n`, {
flag: "a",
});
}
@ -115,16 +139,20 @@ export class DataLogger {
);
}
const parsed = zodSchema.safeParse(event.data);
const eventDataWithBaseValues = await this.addBaseValues(
event.data,
event.name,
schema,
zodSchema,
);
const parsed = zodSchema.safeParse(eventDataWithBaseValues);
if (!parsed.success) {
throw new Error(
`Failed to parse event data ${parsed.error.toString()}`,
`Failed to parse event data for event ${event.name} and schema ${schema}\n:${parsed.error.toString()}`,
);
}
// Add base values like createdAt etc. if keys present in body
const payload = this.addBaseValues(parsed.data, event.name, schema);
const uriComponents = URI.parse(dataConfig.destination);
// Send to remote server
@ -139,7 +167,7 @@ export class DataLogger {
headers["Authorization"] = `Bearer ${dataConfig.apiKey}`;
}
// For Continue events, overwrite the access token
// For events going to Continue, overwrite the access token
if (
uriComponents.host?.endsWith(".continue.dev") ||
uriComponents.host === "continue.dev"
@ -159,7 +187,7 @@ export class DataLogger {
headers,
body: JSON.stringify({
name: event.name,
data: payload,
data: parsed.data,
schema,
level,
profileId,

View file

@ -49,11 +49,11 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
acceptDiff: [{ filepath: string; streamId?: string }, void];
rejectDiff: [{ filepath: string; streamId?: string }, void];
"edit/sendPrompt": [
{ prompt: MessageContent; range: RangeInFileWithContents },
void,
];
"edit/acceptReject": [
{ accept: boolean; onlyFirst: boolean; filepath: string },
{
prompt: MessageContent;
range: RangeInFileWithContents;
selectedModelTitle: string;
},
void,
];
"edit/exit": [{ shouldFocusEditor: boolean }, void];

View file

@ -286,13 +286,10 @@ export class VsCodeMessenger {
const prompt = msg.data.prompt;
const { start, end } = msg.data.range.range;
const verticalDiffManager = await verticalDiffManagerPromise;
const modelTitle = await this.webviewProtocol.request(
"getDefaultModelTitle",
undefined,
);
const fileAfterEdit = await verticalDiffManager.streamEdit(
stripImages(prompt),
modelTitle,
msg.data.selectedModelTitle,
"edit",
undefined,
undefined,
@ -307,30 +304,6 @@ export class VsCodeMessenger {
fileAfterEdit,
});
});
this.onWebview("edit/acceptReject", async (msg) => {
const { onlyFirst, accept, filepath } = msg.data;
if (accept && onlyFirst) {
// Accept first
vscode.commands.executeCommand(
"continue.acceptVerticalDiffBlock",
filepath,
0,
);
} else if (accept) {
vscode.commands.executeCommand("continue.acceptDiff", filepath);
// Accept all
} else if (onlyFirst) {
// Reject first
vscode.commands.executeCommand(
"continue.rejectVerticalDiffBlock",
filepath,
0,
);
} else {
// Reject all
vscode.commands.executeCommand("continue.rejectDiff", filepath);
}
});
this.onWebview("edit/exit", async (msg) => {
if (msg.data.shouldFocusEditor) {
const activeEditor = vscode.window.activeTextEditor;

View file

@ -338,6 +338,7 @@ export function Chat() {
ideMessenger.post("edit/sendPrompt", {
prompt,
range: codeToEdit[0] as RangeInFileWithContents,
selectedModelTitle,
});
dispatch(submitEdit(prompt));

View file

@ -60,19 +60,31 @@ export const streamNormalInput = createAsyncThunk<
dispatch(addPromptCompletionPair([next.value]));
try {
debugger;
extra.ideMessenger.post("devdata/log", {
name: "chatInteraction",
data: {
prompt: next.value.prompt,
completion: next.value.completion,
modelProvider: defaultModel.provider,
modelTitle: defaultModel.title,
sessionId: state.session.id,
},
});
if (state.session.mode === "chat") {
extra.ideMessenger.post("devdata/log", {
name: "chatInteraction",
data: {
prompt: next.value.prompt,
completion: next.value.completion,
modelProvider: defaultModel.provider,
modelTitle: defaultModel.title,
sessionId: state.session.id,
},
});
}
if (state.session.mode === "edit") {
extra.ideMessenger.post("devdata/log", {
name: "editInteraction",
data: {
prompt: next.value.prompt,
completion: next.value.completion,
modelProvider: defaultModel.provider,
modelTitle: defaultModel.title,
},
});
}
} catch (e) {
console.error("Failed to send dev data chatInteraction log");
console.error("Failed to send dev data interaction log", e);
}
}

View file

@ -43,7 +43,7 @@ export const streamResponseAfterToolCall = createAsyncThunk<
content: renderContextItems(toolOutput),
toolCallId,
};
debugger;
dispatch(streamUpdate([newMessage]));
dispatch(
addContextItemsAtIndex({

View file

@ -0,0 +1,15 @@
import { z } from "zod";
import { baseDevDataAllSchema } from "../base.js";
export const editOutcomeEventAllSchema = baseDevDataAllSchema.extend({
modelProvider: z.string(),
modelTitle: z.string(),
prompt: z.string(),
completion: z.string(),
previousCode: z.string(),
newCode: z.string(),
previousCodeLines: z.number(),
newCodeLines: z.number(),
lineChange: z.number(),
accepted: z.boolean(),
});

View file

@ -0,0 +1,24 @@
import { editOutcomeEventAllSchema } from "./index.js";
export const editOutcomeEventSchema_0_2_0 = editOutcomeEventAllSchema.pick({
// base
timestamp: true,
userId: true,
userAgent: true,
selectedProfileId: true,
eventName: true,
schema: true,
// other
prompt: true,
completion: true,
modelTitle: true,
modelProvider: true,
accepted: true,
});
export const editOutcomeEventSchema_0_2_0_noCode =
editOutcomeEventSchema_0_2_0.omit({
prompt: true,
completion: true,
});