diff --git a/core/core.ts b/core/core.ts index 882b2f3c5..f69ce527a 100644 --- a/core/core.ts +++ b/core/core.ts @@ -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; diff --git a/core/data/log.ts b/core/data/log.ts index b6e0c0852..f754e07fc 100644 --- a/core/data/log.ts +++ b/core/data/log.ts @@ -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; + ideInfoPromise?: Promise; 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, + eventName: string, + schema: string, + zodSchema: ZodObject, + ): Promise> { + 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, diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 3598e06ea..a7cd16e5b 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -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]; diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index aac537d93..6a6da6de0 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -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; diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 55027c041..3fa115fb9 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -338,6 +338,7 @@ export function Chat() { ideMessenger.post("edit/sendPrompt", { prompt, range: codeToEdit[0] as RangeInFileWithContents, + selectedModelTitle, }); dispatch(submitEdit(prompt)); diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index da52c1af2..7e2e1659b 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -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); } } diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 3d41c664f..c6435382a 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -43,7 +43,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< content: renderContextItems(toolOutput), toolCallId, }; - + debugger; dispatch(streamUpdate([newMessage])); dispatch( addContextItemsAtIndex({ diff --git a/packages/config-yaml/src/schemas/data/editOutcome/index.ts b/packages/config-yaml/src/schemas/data/editOutcome/index.ts new file mode 100644 index 000000000..ec902364c --- /dev/null +++ b/packages/config-yaml/src/schemas/data/editOutcome/index.ts @@ -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(), +}); diff --git a/packages/config-yaml/src/schemas/data/editOutcome/v0.2.0.ts b/packages/config-yaml/src/schemas/data/editOutcome/v0.2.0.ts new file mode 100644 index 000000000..88d867fbd --- /dev/null +++ b/packages/config-yaml/src/schemas/data/editOutcome/v0.2.0.ts @@ -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, + });