@vscode/chat-lib 0.0.3 → 0.0.5-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/_internal/extension/byok/node/openAIEndpoint.d.ts +10 -2
- package/dist/src/_internal/extension/byok/node/openAIEndpoint.d.ts.map +1 -1
- package/dist/src/_internal/extension/byok/node/openAIEndpoint.js +151 -13
- package/dist/src/_internal/extension/byok/node/openAIEndpoint.js.map +1 -1
- package/dist/src/_internal/extension/common/constants.d.ts +0 -1
- package/dist/src/_internal/extension/common/constants.d.ts.map +1 -1
- package/dist/src/_internal/extension/common/constants.js +0 -1
- package/dist/src/_internal/extension/common/constants.js.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nesConfigs.d.ts +0 -4
- package/dist/src/_internal/extension/inlineEdits/node/nesConfigs.d.ts.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.d.ts +4 -2
- package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.d.ts.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.js +15 -8
- package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.js.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.d.ts +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.d.ts.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.js +60 -94
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.js.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.d.ts +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.d.ts.map +1 -1
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.js +7 -3
- package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.js.map +1 -1
- package/dist/src/_internal/extension/prompt/node/chatMLFetcher.d.ts +3 -13
- package/dist/src/_internal/extension/prompt/node/chatMLFetcher.d.ts.map +1 -1
- package/dist/src/_internal/extension/prompt/node/chatMLFetcher.js +64 -30
- package/dist/src/_internal/extension/prompt/node/chatMLFetcher.js.map +1 -1
- package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts +36 -21
- package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts.map +1 -1
- package/dist/src/_internal/extension/xtab/common/promptCrafting.js +81 -53
- package/dist/src/_internal/extension/xtab/common/promptCrafting.js.map +1 -1
- package/dist/src/_internal/extension/xtab/common/xtabCurrentDocument.d.ts +16 -0
- package/dist/src/_internal/extension/xtab/common/xtabCurrentDocument.d.ts.map +1 -0
- package/dist/src/_internal/extension/xtab/common/xtabCurrentDocument.js +19 -0
- package/dist/src/_internal/extension/xtab/common/xtabCurrentDocument.js.map +1 -0
- package/dist/src/_internal/extension/xtab/node/xtabEndpoint.d.ts +1 -2
- package/dist/src/_internal/extension/xtab/node/xtabEndpoint.d.ts.map +1 -1
- package/dist/src/_internal/extension/xtab/node/xtabEndpoint.js +9 -11
- package/dist/src/_internal/extension/xtab/node/xtabEndpoint.js.map +1 -1
- package/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts +23 -6
- package/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts.map +1 -1
- package/dist/src/_internal/extension/xtab/node/xtabProvider.js +412 -153
- package/dist/src/_internal/extension/xtab/node/xtabProvider.js.map +1 -1
- package/dist/src/_internal/platform/authentication/common/authentication.d.ts.map +1 -1
- package/dist/src/_internal/platform/authentication/common/authentication.js +0 -2
- package/dist/src/_internal/platform/authentication/common/authentication.js.map +1 -1
- package/dist/src/_internal/platform/authentication/common/copilotToken.d.ts +2 -0
- package/dist/src/_internal/platform/authentication/common/copilotToken.d.ts.map +1 -1
- package/dist/src/_internal/platform/authentication/common/copilotToken.js +6 -0
- package/dist/src/_internal/platform/authentication/common/copilotToken.js.map +1 -1
- package/dist/src/_internal/platform/authentication/node/copilotTokenManager.d.ts +23 -2
- package/dist/src/_internal/platform/authentication/node/copilotTokenManager.d.ts.map +1 -1
- package/dist/src/_internal/platform/authentication/node/copilotTokenManager.js +79 -19
- package/dist/src/_internal/platform/authentication/node/copilotTokenManager.js.map +1 -1
- package/dist/src/_internal/platform/chat/common/chatMLFetcher.d.ts +2 -1
- package/dist/src/_internal/platform/chat/common/chatMLFetcher.d.ts.map +1 -1
- package/dist/src/_internal/platform/chat/common/chatMLFetcher.js +7 -1
- package/dist/src/_internal/platform/chat/common/chatMLFetcher.js.map +1 -1
- package/dist/src/_internal/platform/chat/common/commonTypes.d.ts.map +1 -1
- package/dist/src/_internal/platform/chat/common/commonTypes.js +5 -2
- package/dist/src/_internal/platform/chat/common/commonTypes.js.map +1 -1
- package/dist/src/_internal/platform/configuration/common/configurationService.d.ts +31 -18
- package/dist/src/_internal/platform/configuration/common/configurationService.d.ts.map +1 -1
- package/dist/src/_internal/platform/configuration/common/configurationService.js +48 -31
- package/dist/src/_internal/platform/configuration/common/configurationService.js.map +1 -1
- package/dist/src/_internal/platform/configuration/common/validator.d.ts +6 -0
- package/dist/src/_internal/platform/configuration/common/validator.d.ts.map +1 -1
- package/dist/src/_internal/platform/configuration/common/validator.js +41 -4
- package/dist/src/_internal/platform/configuration/common/validator.js.map +1 -1
- package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.d.ts +4 -4
- package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.js +15 -10
- package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.js.map +1 -1
- package/dist/src/_internal/platform/endpoint/common/endpointProvider.d.ts +31 -3
- package/dist/src/_internal/platform/endpoint/common/endpointProvider.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/common/endpointProvider.js +14 -0
- package/dist/src/_internal/platform/endpoint/common/endpointProvider.js.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/chatEndpoint.d.ts +6 -6
- package/dist/src/_internal/platform/endpoint/node/chatEndpoint.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/chatEndpoint.js +39 -28
- package/dist/src/_internal/platform/endpoint/node/chatEndpoint.js.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/domainServiceImpl.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/domainServiceImpl.js +2 -1
- package/dist/src/_internal/platform/endpoint/node/domainServiceImpl.js.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/responsesApi.d.ts +6 -0
- package/dist/src/_internal/platform/endpoint/node/responsesApi.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/responsesApi.js +184 -26
- package/dist/src/_internal/platform/endpoint/node/responsesApi.js.map +1 -1
- package/dist/src/_internal/platform/env/common/envService.d.ts +2 -0
- package/dist/src/_internal/platform/env/common/envService.d.ts.map +1 -1
- package/dist/src/_internal/platform/env/common/envService.js.map +1 -1
- package/dist/src/_internal/platform/env/common/nullEnvService.d.ts +1 -0
- package/dist/src/_internal/platform/env/common/nullEnvService.d.ts.map +1 -1
- package/dist/src/_internal/platform/env/common/nullEnvService.js +3 -0
- package/dist/src/_internal/platform/env/common/nullEnvService.js.map +1 -1
- package/dist/src/_internal/platform/github/common/githubAPI.d.ts +67 -0
- package/dist/src/_internal/platform/github/common/githubAPI.d.ts.map +1 -1
- package/dist/src/_internal/platform/github/common/githubAPI.js +120 -3
- package/dist/src/_internal/platform/github/common/githubAPI.js.map +1 -1
- package/dist/src/_internal/platform/github/common/githubService.d.ts +171 -1
- package/dist/src/_internal/platform/github/common/githubService.d.ts.map +1 -1
- package/dist/src/_internal/platform/github/common/githubService.js +34 -1
- package/dist/src/_internal/platform/github/common/githubService.js.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.d.ts +11 -0
- package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.d.ts.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.js +8 -1
- package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.js.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/inlineEditLogContext.js +2 -2
- package/dist/src/_internal/platform/inlineEdits/common/inlineEditLogContext.js.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.d.ts +20 -5
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.d.ts.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.js +21 -1
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.js.map +1 -1
- package/dist/src/_internal/platform/networking/common/fetch.d.ts +2 -1
- package/dist/src/_internal/platform/networking/common/fetch.d.ts.map +1 -1
- package/dist/src/_internal/platform/networking/common/fetch.js +1 -0
- package/dist/src/_internal/platform/networking/common/fetch.js.map +1 -1
- package/dist/src/_internal/platform/networking/common/fetcherService.d.ts +2 -0
- package/dist/src/_internal/platform/networking/common/fetcherService.d.ts.map +1 -1
- package/dist/src/_internal/platform/networking/common/fetcherService.js.map +1 -1
- package/dist/src/_internal/platform/networking/common/networking.d.ts +18 -7
- package/dist/src/_internal/platform/networking/common/networking.d.ts.map +1 -1
- package/dist/src/_internal/platform/networking/common/networking.js +6 -5
- package/dist/src/_internal/platform/networking/common/networking.js.map +1 -1
- package/dist/src/_internal/platform/networking/node/chatStream.d.ts.map +1 -1
- package/dist/src/_internal/platform/networking/node/chatStream.js +333 -3
- package/dist/src/_internal/platform/networking/node/chatStream.js.map +1 -1
- package/dist/src/_internal/platform/networking/node/stream.d.ts.map +1 -1
- package/dist/src/_internal/platform/networking/node/stream.js +6 -5
- package/dist/src/_internal/platform/networking/node/stream.js.map +1 -1
- package/dist/src/_internal/platform/openai/node/fetch.d.ts +4 -10
- package/dist/src/_internal/platform/openai/node/fetch.d.ts.map +1 -1
- package/dist/src/_internal/platform/openai/node/fetch.js +38 -15
- package/dist/src/_internal/platform/openai/node/fetch.js.map +1 -1
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.d.ts +2 -2
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.d.ts.map +1 -1
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.js +20 -2
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.js.map +1 -1
- package/dist/src/_internal/platform/telemetry/common/telemetryData.d.ts.map +1 -1
- package/dist/src/_internal/platform/telemetry/common/telemetryData.js +4 -2
- package/dist/src/_internal/platform/telemetry/common/telemetryData.js.map +1 -1
- package/dist/src/_internal/platform/tokenizer/node/tokenizer.d.ts.map +1 -1
- package/dist/src/_internal/platform/tokenizer/node/tokenizer.js +7 -6
- package/dist/src/_internal/platform/tokenizer/node/tokenizer.js.map +1 -1
- package/dist/src/_internal/util/common/cache.d.ts +1 -0
- package/dist/src/_internal/util/common/cache.d.ts.map +1 -1
- package/dist/src/_internal/util/common/cache.js +9 -0
- package/dist/src/_internal/util/common/cache.js.map +1 -1
- package/dist/src/_internal/util/common/notebooks.d.ts +1 -0
- package/dist/src/_internal/util/common/notebooks.d.ts.map +1 -1
- package/dist/src/_internal/util/common/notebooks.js +4 -0
- package/dist/src/_internal/util/common/notebooks.js.map +1 -1
- package/dist/src/_internal/util/common/tracing.d.ts +11 -0
- package/dist/src/_internal/util/common/tracing.d.ts.map +1 -1
- package/dist/src/_internal/util/common/tracing.js +5 -0
- package/dist/src/_internal/util/common/tracing.js.map +1 -1
- package/dist/src/main.d.ts +50 -9
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +87 -19
- package/dist/src/main.js.map +1 -1
- package/dist/src/package.json +434 -167
- package/package.json +3 -3
|
@@ -47,13 +47,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
47
47
|
};
|
|
48
48
|
var XtabProvider_1;
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.XtabProvider =
|
|
50
|
+
exports.XtabProvider = void 0;
|
|
51
|
+
exports.findMergeConflictMarkersRange = findMergeConflictMarkersRange;
|
|
52
|
+
const copilot_api_1 = require("@vscode/copilot-api");
|
|
51
53
|
const prompt_tsx_1 = require("@vscode/prompt-tsx");
|
|
54
|
+
const rawTypes_1 = require("@vscode/prompt-tsx/dist/base/output/rawTypes");
|
|
52
55
|
const chatMLFetcher_1 = require("../../../platform/chat/common/chatMLFetcher");
|
|
53
56
|
const commonTypes_1 = require("../../../platform/chat/common/commonTypes");
|
|
54
57
|
const globalStringUtils_1 = require("../../../platform/chat/common/globalStringUtils");
|
|
55
58
|
const configurationService_1 = require("../../../platform/configuration/common/configurationService");
|
|
56
59
|
const diffService_1 = require("../../../platform/diff/common/diffService");
|
|
60
|
+
const chatEndpoint_1 = require("../../../platform/endpoint/node/chatEndpoint");
|
|
57
61
|
const proxyXtabEndpoint_1 = require("../../../platform/endpoint/node/proxyXtabEndpoint");
|
|
58
62
|
const ignoreService_1 = require("../../../platform/ignore/common/ignoreService");
|
|
59
63
|
const xtabPromptOptions = __importStar(require("../../../platform/inlineEdits/common/dataTypes/xtabPromptOptions"));
|
|
@@ -66,12 +70,15 @@ const languageContextService_1 = require("../../../platform/languageServer/commo
|
|
|
66
70
|
const logService_1 = require("../../../platform/log/common/logService");
|
|
67
71
|
const simulationTestContext_1 = require("../../../platform/simulationTestContext/common/simulationTestContext");
|
|
68
72
|
const nullExperimentationService_1 = require("../../../platform/telemetry/common/nullExperimentationService");
|
|
73
|
+
const telemetry_1 = require("../../../platform/telemetry/common/telemetry");
|
|
69
74
|
const workspaceService_1 = require("../../../platform/workspace/common/workspaceService");
|
|
70
75
|
const async_1 = require("../../../util/common/async");
|
|
71
76
|
const errors = __importStar(require("../../../util/common/errors"));
|
|
72
77
|
const result_1 = require("../../../util/common/result");
|
|
78
|
+
const tokenizer_1 = require("../../../util/common/tokenizer");
|
|
73
79
|
const tracing_1 = require("../../../util/common/tracing");
|
|
74
80
|
const async_2 = require("../../../util/vs/base/common/async");
|
|
81
|
+
const cancellation_1 = require("../../../util/vs/base/common/cancellation");
|
|
75
82
|
const stopwatch_1 = require("../../../util/vs/base/common/stopwatch");
|
|
76
83
|
const lineEdit_1 = require("../../../util/vs/editor/common/core/edits/lineEdit");
|
|
77
84
|
const stringEdit_1 = require("../../../util/vs/editor/common/core/edits/stringEdit");
|
|
@@ -86,9 +93,9 @@ const ghNearbyNesProvider_1 = require("../../inlineEdits/common/ghNearbyNesProvi
|
|
|
86
93
|
const nearbyCursorInlineEditProvider_1 = require("../../inlineEdits/common/nearbyCursorInlineEditProvider");
|
|
87
94
|
const importFiltering_1 = require("../../inlineEdits/node/importFiltering");
|
|
88
95
|
const promptCrafting_1 = require("../common/promptCrafting");
|
|
96
|
+
const xtabCurrentDocument_1 = require("../common/xtabCurrentDocument");
|
|
89
97
|
const xtabEndpoint_1 = require("./xtabEndpoint");
|
|
90
98
|
const xtabUtils_1 = require("./xtabUtils");
|
|
91
|
-
exports.IGNORE_TEXT_BEFORE = /```[^\n]*\n/;
|
|
92
99
|
var ResponseTags;
|
|
93
100
|
(function (ResponseTags) {
|
|
94
101
|
ResponseTags.NO_CHANGE = {
|
|
@@ -106,7 +113,8 @@ var ResponseTags;
|
|
|
106
113
|
let XtabProvider = class XtabProvider {
|
|
107
114
|
static { XtabProvider_1 = this; }
|
|
108
115
|
static { this.ID = configurationService_1.XTabProviderId; }
|
|
109
|
-
|
|
116
|
+
static { this.computeTokens = (s) => Math.floor(s.length / 4); }
|
|
117
|
+
constructor(simulationCtx, instaService, workspaceService, diffService, configService, expService, logService, langCtxService, langDiagService, ignoreService, telemetryService) {
|
|
110
118
|
this.simulationCtx = simulationCtx;
|
|
111
119
|
this.instaService = instaService;
|
|
112
120
|
this.workspaceService = workspaceService;
|
|
@@ -117,6 +125,7 @@ let XtabProvider = class XtabProvider {
|
|
|
117
125
|
this.langCtxService = langCtxService;
|
|
118
126
|
this.langDiagService = langDiagService;
|
|
119
127
|
this.ignoreService = ignoreService;
|
|
128
|
+
this.telemetryService = telemetryService;
|
|
120
129
|
this.ID = XtabProvider_1.ID;
|
|
121
130
|
this.dependsOnSelection = true;
|
|
122
131
|
this.showNextEditPreference = "always" /* ShowNextEditPreference.Always */;
|
|
@@ -153,6 +162,9 @@ let XtabProvider = class XtabProvider {
|
|
|
153
162
|
if (!this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.InlineEditsAllowWhitespaceOnlyChanges, this.expService)) {
|
|
154
163
|
filters.push((edits) => statelessNextEditProviders_1.IgnoreWhitespaceOnlyChanges.filterEdit(activeDoc, edits));
|
|
155
164
|
}
|
|
165
|
+
if (this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsUndoInsertionFilteringEnabled, this.expService)) {
|
|
166
|
+
filters.push((edits) => (0, ghNearbyNesProvider_1.editWouldDeleteWhatWasJustInserted)(activeDoc, new lineEdit_1.LineEdit(edits)) ? [] : edits);
|
|
167
|
+
}
|
|
156
168
|
return filters.reduce((acc, filter) => filter(acc), edits);
|
|
157
169
|
}
|
|
158
170
|
async _provideNextEdit(request, pushEdit, logContext, cancellationToken) {
|
|
@@ -180,99 +192,132 @@ let XtabProvider = class XtabProvider {
|
|
|
180
192
|
}
|
|
181
193
|
}
|
|
182
194
|
async doGetNextEdit(request, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, retryState) {
|
|
183
|
-
|
|
195
|
+
return this.doGetNextEditWithSelection(request, (0, nearbyCursorInlineEditProvider_1.getOrDeduceSelectionFromLastEdit)(request.getActiveDocument()), pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, retryState);
|
|
196
|
+
}
|
|
197
|
+
async doGetNextEditWithSelection(request, selection, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, retryState) {
|
|
198
|
+
const tracer = this.tracer.sub('doGetNextEditWithSelection');
|
|
184
199
|
const activeDocument = request.getActiveDocument();
|
|
185
|
-
const selection = (0, nearbyCursorInlineEditProvider_1.getOrDeduceSelectionFromLastEdit)(activeDocument);
|
|
186
200
|
if (selection === null) {
|
|
187
201
|
return result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.Uncategorized(new Error('NoSelection')));
|
|
188
202
|
}
|
|
189
|
-
const
|
|
203
|
+
const promptOptions = this.determineModelConfiguration(activeDocument);
|
|
204
|
+
const endpoint = this.getEndpoint(promptOptions.modelName);
|
|
190
205
|
logContext.setEndpointInfo(typeof endpoint.urlOrRequestMetadata === 'string' ? endpoint.urlOrRequestMetadata : JSON.stringify(endpoint.urlOrRequestMetadata.type), endpoint.model);
|
|
191
206
|
telemetryBuilder.setModelName(endpoint.model);
|
|
192
|
-
const computeTokens = (s) => Math.floor(s.length / 4);
|
|
193
207
|
const cursorPosition = new position_1.Position(selection.endLineNumber, selection.endColumn);
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const currentFileContentLines = currentFileContent.getLines();
|
|
197
|
-
const cursorLineIdx = cursorPosition.lineNumber - 1 /* to convert to 0-based */;
|
|
198
|
-
const cursorLine = currentFileContentLines[cursorLineIdx];
|
|
208
|
+
const currentDocument = new xtabCurrentDocument_1.CurrentDocument(activeDocument.documentAfterEdits, cursorPosition);
|
|
209
|
+
const cursorLine = currentDocument.lines[currentDocument.cursorLineOffset];
|
|
199
210
|
const isCursorAtEndOfLine = cursorPosition.column === cursorLine.trimEnd().length;
|
|
200
211
|
if (isCursorAtEndOfLine) {
|
|
201
212
|
delaySession.setExtraDebounce(this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsExtraDebounceEndOfLine, this.expService));
|
|
202
213
|
}
|
|
203
214
|
telemetryBuilder.setIsCursorAtLineEnd(isCursorAtEndOfLine);
|
|
204
|
-
const areaAroundEditWindowLinesRange = this.computeAreaAroundEditWindowLinesRange(
|
|
205
|
-
const editWindowLinesRange = this.computeEditWindowLinesRange(
|
|
206
|
-
const cursorOriginalLinesOffset = Math.max(0,
|
|
207
|
-
const editWindowLastLineLength =
|
|
208
|
-
const editWindow =
|
|
209
|
-
const editWindowLines =
|
|
215
|
+
const areaAroundEditWindowLinesRange = this.computeAreaAroundEditWindowLinesRange(currentDocument);
|
|
216
|
+
const editWindowLinesRange = this.computeEditWindowLinesRange(currentDocument, request, retryState);
|
|
217
|
+
const cursorOriginalLinesOffset = Math.max(0, currentDocument.cursorLineOffset - editWindowLinesRange.start);
|
|
218
|
+
const editWindowLastLineLength = currentDocument.transformer.getLineLength(editWindowLinesRange.endExclusive);
|
|
219
|
+
const editWindow = currentDocument.transformer.getOffsetRange(new range_1.Range(editWindowLinesRange.start + 1, 1, editWindowLinesRange.endExclusive, editWindowLastLineLength + 1));
|
|
220
|
+
const editWindowLines = currentDocument.lines.slice(editWindowLinesRange.start, editWindowLinesRange.endExclusive);
|
|
210
221
|
// Expected: editWindow.substring(activeDocument.documentAfterEdits.value) === editWindowLines.join('\n')
|
|
211
|
-
const doesIncludeCursorTag = editWindowLines.some(line => line.includes(promptCrafting_1.
|
|
222
|
+
const doesIncludeCursorTag = editWindowLines.some(line => line.includes(promptCrafting_1.PromptTags.CURSOR));
|
|
212
223
|
const shouldRemoveCursorTagFromResponse = !doesIncludeCursorTag; // we'd like to remove the tag only if the original edit-window didn't include the tag
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const areaAroundCodeToEdit =
|
|
218
|
-
promptCrafting_1.AREA_AROUND_START_TAG,
|
|
219
|
-
...contentWithCursorLines.slice(areaAroundEditWindowLinesRange.start, editWindowLinesRange.start),
|
|
220
|
-
promptCrafting_1.CODE_TO_EDIT_START_TAG,
|
|
221
|
-
...editWindowWithCursorLines,
|
|
222
|
-
promptCrafting_1.CODE_TO_EDIT_END_TAG,
|
|
223
|
-
...contentWithCursorLines.slice(editWindowLinesRange.endExclusive, areaAroundEditWindowLinesRange.endExclusive),
|
|
224
|
-
promptCrafting_1.AREA_AROUND_END_TAG
|
|
225
|
-
].join('\n');
|
|
226
|
-
const promptOptions = this.determinePromptOptions(activeDocument);
|
|
227
|
-
const areaAroundCodeToEditForCurrentFile = promptOptions.currentFile.includeTags
|
|
228
|
-
? areaAroundCodeToEdit
|
|
229
|
-
: [
|
|
230
|
-
...contentWithCursorLines.slice(areaAroundEditWindowLinesRange.start, editWindowLinesRange.start),
|
|
231
|
-
...editWindowLines,
|
|
232
|
-
...contentWithCursorLines.slice(editWindowLinesRange.endExclusive, areaAroundEditWindowLinesRange.endExclusive),
|
|
233
|
-
].join('\n');
|
|
234
|
-
const { taggedCurrentFileContent, nLines: nLinesCurrentFile } = (0, promptCrafting_1.createTaggedCurrentFileContentUsingPagedClipping)(currentFileContentLines, areaAroundCodeToEditForCurrentFile, areaAroundEditWindowLinesRange, computeTokens, promptOptions.pagedClipping.pageSize, promptOptions.currentFile);
|
|
224
|
+
const taggedCurrentFileContentResult = this.constructTaggedFile(currentDocument, editWindowLinesRange, areaAroundEditWindowLinesRange, promptOptions, XtabProvider_1.computeTokens, { includeLineNumbers: false });
|
|
225
|
+
if (taggedCurrentFileContentResult.isError()) {
|
|
226
|
+
return result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.PromptTooLarge('currentFile'));
|
|
227
|
+
}
|
|
228
|
+
const { taggedCurrentFileR: { taggedCurrentFileContent, nLines: nLinesCurrentFile }, areaAroundCodeToEdit } = taggedCurrentFileContentResult.val;
|
|
235
229
|
telemetryBuilder.setNLinesOfCurrentFileInPrompt(nLinesCurrentFile);
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const langCtxPromise = this.getLanguageContext(request, delaySession, activeDocument, cursorPosition, logContext, cancellationToken);
|
|
240
|
-
if (promptOptions.languageContext.enabled) {
|
|
241
|
-
langCtx = await langCtxPromise;
|
|
242
|
-
}
|
|
243
|
-
if (recordingEnabled) {
|
|
244
|
-
logContext.setFileDiagnostics(this.langDiagService.getAllDiagnostics());
|
|
245
|
-
langCtxPromise.then(langCtxs => {
|
|
246
|
-
if (langCtxs) {
|
|
247
|
-
logContext.setLanguageContext(langCtxs);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
230
|
+
const langCtx = await this.getAndProcessLanguageContext(request, delaySession, activeDocument, cursorPosition, promptOptions, logContext, cancellationToken);
|
|
231
|
+
if (cancellationToken.isCancellationRequested) {
|
|
232
|
+
return result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.GotCancelled('afterLanguageContextAwait'));
|
|
251
233
|
}
|
|
252
|
-
const
|
|
234
|
+
const promptPieces = new promptCrafting_1.PromptPieces(currentDocument, editWindowLinesRange, areaAroundEditWindowLinesRange, activeDocument, request.xtabEditHistory, taggedCurrentFileContent, areaAroundCodeToEdit, langCtx, XtabProvider_1.computeTokens, promptOptions);
|
|
235
|
+
const userPrompt = (0, promptCrafting_1.getUserPrompt)(promptPieces);
|
|
253
236
|
const prediction = this.getPredictedOutput(editWindowLines, promptOptions.promptingStrategy);
|
|
254
|
-
const messages =
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
},
|
|
259
|
-
{ role: prompt_tsx_1.Raw.ChatRole.User, content: (0, globalStringUtils_1.toTextParts)(userPrompt) }
|
|
260
|
-
];
|
|
237
|
+
const messages = constructMessages({
|
|
238
|
+
systemMsg: this.pickSystemPrompt(promptOptions.promptingStrategy),
|
|
239
|
+
userMsg: userPrompt,
|
|
240
|
+
});
|
|
261
241
|
logContext.setPrompt(messages);
|
|
262
242
|
telemetryBuilder.setPrompt(messages);
|
|
243
|
+
const HARD_CHAR_LIMIT = 30000 * 4; // 30K tokens, assuming 4 chars per token -- we use approximation here because counting tokens exactly is time-consuming
|
|
244
|
+
const promptCharCount = charCount(messages);
|
|
245
|
+
if (promptCharCount > HARD_CHAR_LIMIT) {
|
|
246
|
+
return result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.PromptTooLarge('final'));
|
|
247
|
+
}
|
|
263
248
|
await this.debounce(delaySession, telemetryBuilder);
|
|
264
249
|
if (cancellationToken.isCancellationRequested) {
|
|
265
250
|
return result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.GotCancelled('afterDebounce'));
|
|
266
251
|
}
|
|
267
252
|
request.fetchIssued = true;
|
|
268
253
|
const cursorLineOffset = cursorPosition.column;
|
|
269
|
-
this.streamEdits(request, pushEdit, endpoint, messages, editWindow, editWindowLines, cursorOriginalLinesOffset, cursorLineOffset, editWindowLinesRange, prediction, {
|
|
254
|
+
this.streamEdits(request, pushEdit, endpoint, messages, editWindow, editWindowLines, cursorOriginalLinesOffset, cursorLineOffset, editWindowLinesRange, promptPieces, prediction, {
|
|
270
255
|
shouldRemoveCursorTagFromResponse,
|
|
271
256
|
promptingStrategy: promptOptions.promptingStrategy,
|
|
272
257
|
retryState,
|
|
273
258
|
}, delaySession, tracer, telemetryBuilder, logContext, cancellationToken);
|
|
274
259
|
return result_1.Result.ok(undefined);
|
|
275
260
|
}
|
|
261
|
+
constructTaggedFile(currentDocument, editWindowLinesRange, areaAroundEditWindowLinesRange, promptOptions, computeTokens, opts) {
|
|
262
|
+
const contentWithCursorAsLinesOriginal = (() => {
|
|
263
|
+
const addCursorTagEdit = stringEdit_1.StringEdit.single(stringEdit_1.StringReplacement.insert(currentDocument.cursorOffset, promptCrafting_1.PromptTags.CURSOR));
|
|
264
|
+
const contentWithCursor = addCursorTagEdit.applyOnText(currentDocument.content);
|
|
265
|
+
return contentWithCursor.getLines();
|
|
266
|
+
})();
|
|
267
|
+
const addLineNumbers = (lines) => lines.map((line, idx) => `${idx}| ${line}`);
|
|
268
|
+
const contentWithCursorAsLines = opts.includeLineNumbers
|
|
269
|
+
? addLineNumbers(contentWithCursorAsLinesOriginal)
|
|
270
|
+
: contentWithCursorAsLinesOriginal;
|
|
271
|
+
const editWindowWithCursorAsLines = contentWithCursorAsLines.slice(editWindowLinesRange.start, editWindowLinesRange.endExclusive);
|
|
272
|
+
const areaAroundCodeToEdit = [
|
|
273
|
+
promptCrafting_1.PromptTags.AREA_AROUND.start,
|
|
274
|
+
...contentWithCursorAsLines.slice(areaAroundEditWindowLinesRange.start, editWindowLinesRange.start),
|
|
275
|
+
promptCrafting_1.PromptTags.EDIT_WINDOW.start,
|
|
276
|
+
...editWindowWithCursorAsLines,
|
|
277
|
+
promptCrafting_1.PromptTags.EDIT_WINDOW.end,
|
|
278
|
+
...contentWithCursorAsLines.slice(editWindowLinesRange.endExclusive, areaAroundEditWindowLinesRange.endExclusive),
|
|
279
|
+
promptCrafting_1.PromptTags.AREA_AROUND.end
|
|
280
|
+
].join('\n');
|
|
281
|
+
const currentFileContentLines = opts.includeLineNumbers
|
|
282
|
+
? addLineNumbers(currentDocument.lines)
|
|
283
|
+
: currentDocument.lines;
|
|
284
|
+
let areaAroundCodeToEditForCurrentFile;
|
|
285
|
+
if (promptOptions.currentFile.includeTags) {
|
|
286
|
+
areaAroundCodeToEditForCurrentFile = areaAroundCodeToEdit;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
const editWindowLines = currentFileContentLines.slice(editWindowLinesRange.start, editWindowLinesRange.endExclusive);
|
|
290
|
+
areaAroundCodeToEditForCurrentFile = [
|
|
291
|
+
...contentWithCursorAsLines.slice(areaAroundEditWindowLinesRange.start, editWindowLinesRange.start),
|
|
292
|
+
...editWindowLines,
|
|
293
|
+
...contentWithCursorAsLines.slice(editWindowLinesRange.endExclusive, areaAroundEditWindowLinesRange.endExclusive),
|
|
294
|
+
].join('\n');
|
|
295
|
+
}
|
|
296
|
+
const taggedCurrentFileContentResult = (0, promptCrafting_1.createTaggedCurrentFileContentUsingPagedClipping)(currentFileContentLines, areaAroundCodeToEditForCurrentFile, areaAroundEditWindowLinesRange, computeTokens, promptOptions.pagedClipping.pageSize, promptOptions.currentFile);
|
|
297
|
+
return taggedCurrentFileContentResult.map(taggedCurrentFileR => ({
|
|
298
|
+
taggedCurrentFileR,
|
|
299
|
+
areaAroundCodeToEdit,
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
getAndProcessLanguageContext(request, delaySession, activeDocument, cursorPosition, promptOptions, logContext, cancellationToken) {
|
|
303
|
+
const recordingEnabled = this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsLogContextRecorderEnabled);
|
|
304
|
+
if (!promptOptions.languageContext.enabled && !recordingEnabled) {
|
|
305
|
+
return Promise.resolve(undefined);
|
|
306
|
+
}
|
|
307
|
+
const langCtxPromise = this.getLanguageContext(request, delaySession, activeDocument, cursorPosition, logContext, cancellationToken);
|
|
308
|
+
// if recording, add diagnostics for the file to the recording and hook up the language context promise to write to the recording
|
|
309
|
+
if (recordingEnabled) {
|
|
310
|
+
logContext.setFileDiagnostics(this.langDiagService.getAllDiagnostics());
|
|
311
|
+
langCtxPromise.then(langCtxs => {
|
|
312
|
+
if (langCtxs) {
|
|
313
|
+
logContext.setLanguageContext(langCtxs);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return promptOptions.languageContext.enabled
|
|
318
|
+
? langCtxPromise
|
|
319
|
+
: Promise.resolve(undefined);
|
|
320
|
+
}
|
|
276
321
|
async getLanguageContext(request, delaySession, activeDocument, cursorPosition, logContext, cancellationToken) {
|
|
277
322
|
try {
|
|
278
323
|
const textDoc = this.workspaceService.textDocuments.find(doc => doc.uri.toString() === activeDocument.id.uri);
|
|
@@ -335,8 +380,9 @@ let XtabProvider = class XtabProvider {
|
|
|
335
380
|
}
|
|
336
381
|
}
|
|
337
382
|
async streamEdits(request, pushEdit, endpoint, messages, editWindow, editWindowLines, cursorOriginalLinesOffset, cursorLineOffset, // cursor offset within the line it's in; 1-based
|
|
338
|
-
editWindowLineRange, prediction, opts, delaySession, parentTracer, telemetryBuilder, logContext, cancellationToken) {
|
|
383
|
+
editWindowLineRange, promptPieces, prediction, opts, delaySession, parentTracer, telemetryBuilder, logContext, cancellationToken) {
|
|
339
384
|
const tracer = parentTracer.sub('streamEdits');
|
|
385
|
+
const useFetcher = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.NextEditSuggestionsFetcher, this.expService) || undefined;
|
|
340
386
|
const fetchStreamSource = new chatMLFetcher_1.FetchStreamSource();
|
|
341
387
|
const fetchRequestStopWatch = new stopwatch_1.StopWatch();
|
|
342
388
|
let responseSoFar = '';
|
|
@@ -346,26 +392,35 @@ let XtabProvider = class XtabProvider {
|
|
|
346
392
|
telemetryBuilder.setFetchStartedAt();
|
|
347
393
|
logContext.setFetchStartTime();
|
|
348
394
|
// we must not await this promise because we want to stream edits as they come in
|
|
349
|
-
const fetchResultPromise = endpoint.
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
395
|
+
const fetchResultPromise = endpoint.makeChatRequest2({
|
|
396
|
+
debugName: XtabProvider_1.ID,
|
|
397
|
+
messages,
|
|
398
|
+
finishedCb: async (text, _, delta) => {
|
|
399
|
+
if (!firstTokenReceived.isSettled) {
|
|
400
|
+
firstTokenReceived.complete();
|
|
401
|
+
}
|
|
402
|
+
if (ttft === undefined) {
|
|
403
|
+
ttft = fetchRequestStopWatch.elapsed();
|
|
404
|
+
logContext.addLog(`TTFT ${ttft} ms`);
|
|
405
|
+
}
|
|
406
|
+
fetchStreamSource.update(text, delta);
|
|
407
|
+
responseSoFar = text;
|
|
408
|
+
logContext.setResponse(responseSoFar);
|
|
409
|
+
return undefined;
|
|
410
|
+
},
|
|
411
|
+
location: commonTypes_1.ChatLocation.Other,
|
|
412
|
+
source: undefined,
|
|
413
|
+
requestOptions: {
|
|
414
|
+
temperature: 0,
|
|
415
|
+
stream: true,
|
|
416
|
+
prediction,
|
|
417
|
+
},
|
|
418
|
+
userInitiatedRequest: undefined,
|
|
419
|
+
telemetryProperties: {
|
|
420
|
+
requestId: request.id,
|
|
421
|
+
},
|
|
422
|
+
useFetcher,
|
|
423
|
+
}, cancellationToken);
|
|
369
424
|
telemetryBuilder.setResponse(fetchResultPromise.then((response) => ({ response, ttft })));
|
|
370
425
|
logContext.setFullResponse(fetchResultPromise.then((response) => response.type === commonTypes_1.ChatFetchResponseType.Success ? response.value : undefined));
|
|
371
426
|
const fetchRes = await Promise.race([firstTokenReceived.p, fetchResultPromise]);
|
|
@@ -409,7 +464,7 @@ let XtabProvider = class XtabProvider {
|
|
|
409
464
|
logContext.addLog(trace);
|
|
410
465
|
tracer.trace(trace);
|
|
411
466
|
return opts.shouldRemoveCursorTagFromResponse
|
|
412
|
-
? v.replaceAll(promptCrafting_1.
|
|
467
|
+
? v.replaceAll(promptCrafting_1.PromptTags.CURSOR, '')
|
|
413
468
|
: v;
|
|
414
469
|
});
|
|
415
470
|
})();
|
|
@@ -432,7 +487,7 @@ let XtabProvider = class XtabProvider {
|
|
|
432
487
|
}
|
|
433
488
|
const trimmedLines = firstLine.value.trim();
|
|
434
489
|
if (trimmedLines === ResponseTags.NO_CHANGE.start) {
|
|
435
|
-
this.pushNoSuggestionsOrRetry(request, editWindow, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, opts.retryState);
|
|
490
|
+
await this.pushNoSuggestionsOrRetry(request, editWindow, promptPieces, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, opts.retryState);
|
|
436
491
|
return;
|
|
437
492
|
}
|
|
438
493
|
if (trimmedLines === ResponseTags.INSERT.start) {
|
|
@@ -518,12 +573,6 @@ let XtabProvider = class XtabProvider {
|
|
|
518
573
|
}
|
|
519
574
|
logContext.setResponse(responseSoFar);
|
|
520
575
|
for (const singleLineEdit of singleLineEdits) {
|
|
521
|
-
const lineEdit = new lineEdit_1.LineEdit([singleLineEdit]);
|
|
522
|
-
if ((0, ghNearbyNesProvider_1.editWouldDeleteWhatWasJustInserted)(request.getActiveDocument(), lineEdit)) {
|
|
523
|
-
this.trace(`filtering edit because it would undo previous insertion: ${singleLineEdit.toString()}`, logContext, tracer);
|
|
524
|
-
i++;
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
576
|
this.trace(`pushing edit #${i}:\n${singleLineEdit.toString()}`, logContext, tracer);
|
|
528
577
|
if (!hasBeenDelayed) { // delay only the first one
|
|
529
578
|
hasBeenDelayed = true;
|
|
@@ -542,7 +591,7 @@ let XtabProvider = class XtabProvider {
|
|
|
542
591
|
pushEdit(result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.NoSuggestions(request.documentBeforeEdits, editWindow)));
|
|
543
592
|
}
|
|
544
593
|
else {
|
|
545
|
-
this.pushNoSuggestionsOrRetry(request, editWindow, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, opts.retryState);
|
|
594
|
+
await this.pushNoSuggestionsOrRetry(request, editWindow, promptPieces, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, opts.retryState);
|
|
546
595
|
}
|
|
547
596
|
}
|
|
548
597
|
catch (err) {
|
|
@@ -552,29 +601,58 @@ let XtabProvider = class XtabProvider {
|
|
|
552
601
|
}
|
|
553
602
|
})();
|
|
554
603
|
}
|
|
555
|
-
pushNoSuggestionsOrRetry(request, editWindow, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, retryState) {
|
|
604
|
+
async pushNoSuggestionsOrRetry(request, editWindow, promptPieces, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, retryState) {
|
|
556
605
|
const allowRetryWithExpandedWindow = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderRetryWithNMoreLinesBelow, this.expService);
|
|
557
606
|
// if allowed to retry and not retrying already, flip the retry state and try again
|
|
558
607
|
if (allowRetryWithExpandedWindow && retryState === 0 /* RetryState.NotRetrying */ && request.expandedEditWindowNLines === undefined) {
|
|
559
|
-
this.doGetNextEdit(request, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, 1 /* RetryState.
|
|
608
|
+
this.doGetNextEdit(request, pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, 1 /* RetryState.Retrying */);
|
|
560
609
|
return;
|
|
561
610
|
}
|
|
611
|
+
const nextCursorLinePredictionEnabled = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsNextCursorPredictionEnabled, this.expService);
|
|
612
|
+
if (nextCursorLinePredictionEnabled && retryState === 0 /* RetryState.NotRetrying */) {
|
|
613
|
+
const nextCursorLineR = await this.predictNextCursorPosition(promptPieces);
|
|
614
|
+
if (nextCursorLineR.isError()) {
|
|
615
|
+
this.tracer.trace(`Predicted next cursor line error: ${nextCursorLineR.err.message}`);
|
|
616
|
+
telemetryBuilder.setNextCursorLineError(nextCursorLineR.err.message);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
const nextCursorLine = nextCursorLineR.val;
|
|
620
|
+
const lineDistanceFromCursorLine = nextCursorLine - promptPieces.currentDocument.cursorLineOffset;
|
|
621
|
+
telemetryBuilder.setNextCursorLineDistance(lineDistanceFromCursorLine);
|
|
622
|
+
this.tracer.trace(`Predicted next cursor line: ${nextCursorLine}`);
|
|
623
|
+
if (nextCursorLine >= promptPieces.currentDocument.lines.length) { // >= because the line index is zero-based
|
|
624
|
+
this.tracer.trace(`Predicted next cursor line error: exceedsDocumentLines`);
|
|
625
|
+
telemetryBuilder.setNextCursorLineError('exceedsDocumentLines');
|
|
626
|
+
}
|
|
627
|
+
else if (promptPieces.editWindowLinesRange.contains(nextCursorLine)) {
|
|
628
|
+
this.tracer.trace(`Predicted next cursor line error: withinEditWindow`);
|
|
629
|
+
telemetryBuilder.setNextCursorLineError('withinEditWindow');
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
this.doGetNextEditWithSelection(request, new range_1.Range(nextCursorLine + 1, 1, nextCursorLine + 1, 1), pushEdit, delaySession, logContext, cancellationToken, telemetryBuilder, 1 /* RetryState.Retrying */);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
562
637
|
pushEdit(result_1.Result.error(new statelessNextEditProvider_1.NoNextEditReason.NoSuggestions(request.documentBeforeEdits, editWindow)));
|
|
563
638
|
return;
|
|
564
639
|
}
|
|
565
|
-
computeAreaAroundEditWindowLinesRange(
|
|
640
|
+
computeAreaAroundEditWindowLinesRange(currentDocument) {
|
|
641
|
+
const cursorLine = currentDocument.cursorLineOffset;
|
|
566
642
|
const areaAroundStart = Math.max(0, cursorLine - promptCrafting_1.N_LINES_AS_CONTEXT);
|
|
567
|
-
const areaAroundEndExcl = Math.min(
|
|
643
|
+
const areaAroundEndExcl = Math.min(currentDocument.lines.length, cursorLine + promptCrafting_1.N_LINES_AS_CONTEXT + 1);
|
|
568
644
|
return new offsetRange_1.OffsetRange(areaAroundStart, areaAroundEndExcl);
|
|
569
645
|
}
|
|
570
|
-
computeEditWindowLinesRange(
|
|
646
|
+
computeEditWindowLinesRange(currentDocument, request, retryState) {
|
|
647
|
+
const currentDocLines = currentDocument.lines;
|
|
648
|
+
const cursorLineOffset = currentDocument.cursorLineOffset;
|
|
571
649
|
let nLinesAbove;
|
|
572
650
|
{
|
|
573
651
|
const useVaryingLinesAbove = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUseVaryingLinesAbove, this.expService);
|
|
574
652
|
if (useVaryingLinesAbove) {
|
|
575
653
|
nLinesAbove = 0; // default
|
|
576
654
|
for (let i = 0; i < 8; ++i) {
|
|
577
|
-
const lineIdx =
|
|
655
|
+
const lineIdx = cursorLineOffset - i;
|
|
578
656
|
if (lineIdx < 0) {
|
|
579
657
|
break;
|
|
580
658
|
}
|
|
@@ -605,18 +683,30 @@ let XtabProvider = class XtabProvider {
|
|
|
605
683
|
nLinesBelow = promptCrafting_1.N_LINES_BELOW; // default
|
|
606
684
|
}
|
|
607
685
|
}
|
|
608
|
-
if (retryState === 1 /* RetryState.
|
|
686
|
+
if (retryState === 1 /* RetryState.Retrying */) {
|
|
609
687
|
nLinesBelow += this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderRetryWithNMoreLinesBelow, this.expService) ?? 0;
|
|
610
688
|
}
|
|
611
|
-
|
|
612
|
-
|
|
689
|
+
let codeToEditStart = Math.max(0, cursorLineOffset - nLinesAbove);
|
|
690
|
+
let codeToEditEndExcl = Math.min(currentDocLines.length, cursorLineOffset + nLinesBelow + 1);
|
|
691
|
+
const maxMergeConflictLines = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabMaxMergeConflictLines, this.expService);
|
|
692
|
+
if (maxMergeConflictLines) {
|
|
693
|
+
const tentativeEditWindow = new offsetRange_1.OffsetRange(codeToEditStart, codeToEditEndExcl);
|
|
694
|
+
const mergeConflictRange = findMergeConflictMarkersRange(currentDocLines, tentativeEditWindow, maxMergeConflictLines);
|
|
695
|
+
if (mergeConflictRange) {
|
|
696
|
+
const onlyMergeConflictLines = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabOnlyMergeConflictLines, this.expService);
|
|
697
|
+
if (onlyMergeConflictLines) {
|
|
698
|
+
this.tracer.trace(`Expanding edit window to include ONLY merge conflict markers: ${mergeConflictRange.toString()}`);
|
|
699
|
+
codeToEditStart = mergeConflictRange.start;
|
|
700
|
+
codeToEditEndExcl = mergeConflictRange.endExclusive;
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
this.tracer.trace(`Expanding edit window to include merge conflict markers: ${mergeConflictRange.toString()}; edit window range [${codeToEditStart}, ${codeToEditEndExcl})`);
|
|
704
|
+
codeToEditEndExcl = Math.max(codeToEditEndExcl, mergeConflictRange.endExclusive);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
613
708
|
return new offsetRange_1.OffsetRange(codeToEditStart, codeToEditEndExcl);
|
|
614
709
|
}
|
|
615
|
-
static getBacktickSection(text) {
|
|
616
|
-
const textTrimmedStart = text.replace(/^\`\`\`[a-zA-Z]*\r?\n/, '');
|
|
617
|
-
const textTrimmedEnd = textTrimmedStart.replace(/(\r?\n)\`\`\`$/, '');
|
|
618
|
-
return textTrimmedEnd;
|
|
619
|
-
}
|
|
620
710
|
static mapChatFetcherErrorToNoNextEditReason(fetchError) {
|
|
621
711
|
switch (fetchError.type) {
|
|
622
712
|
case commonTypes_1.ChatFetchResponseType.Canceled:
|
|
@@ -640,48 +730,182 @@ let XtabProvider = class XtabProvider {
|
|
|
640
730
|
return new statelessNextEditProvider_1.NoNextEditReason.FetchFailure(errors.fromUnknown(fetchError));
|
|
641
731
|
}
|
|
642
732
|
}
|
|
643
|
-
|
|
733
|
+
determineModelConfiguration(activeDocument) {
|
|
644
734
|
if (this.forceUseDefaultModel) {
|
|
645
|
-
return xtabPromptOptions.DEFAULT_OPTIONS;
|
|
646
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
const promptingStrategy = this.determinePromptingStrategy({
|
|
649
|
-
isXtabUnifiedModel: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabUseUnifiedModel, this.expService),
|
|
650
|
-
isCodexV21NesUnified: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabCodexV21NesUnified, this.expService),
|
|
651
|
-
useSimplifiedPrompt: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUseSimplifiedPrompt, this.expService),
|
|
652
|
-
useXtab275Prompting: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUseXtab275Prompting, this.expService),
|
|
653
|
-
useNes41Miniv3Prompting: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabUseNes41Miniv3Prompting, this.expService),
|
|
654
|
-
});
|
|
655
735
|
return {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabCurrentFileMaxTokens, this.expService),
|
|
659
|
-
includeTags: promptingStrategy !== xtabPromptOptions.PromptingStrategy.UnifiedModel /* unified model doesn't use tags in current file */ && this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabIncludeTagsInCurrentFile, this.expService),
|
|
660
|
-
prioritizeAboveCursor: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabPrioritizeAboveCursor, this.expService)
|
|
661
|
-
},
|
|
662
|
-
pagedClipping: {
|
|
663
|
-
pageSize: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabPageSize, this.expService)
|
|
664
|
-
},
|
|
665
|
-
recentlyViewedDocuments: {
|
|
666
|
-
nDocuments: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabNRecentlyViewedDocuments, this.expService),
|
|
667
|
-
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabRecentlyViewedDocumentsMaxTokens, this.expService),
|
|
668
|
-
includeViewedFiles: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabIncludeViewedFiles, this.expService),
|
|
669
|
-
},
|
|
670
|
-
languageContext: this.determineLanguageContextOptions(activeDocument.languageId, {
|
|
671
|
-
enabled: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabLanguageContextEnabled, this.expService),
|
|
672
|
-
enabledLanguages: this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabLanguageContextEnabledLanguages),
|
|
673
|
-
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabLanguageContextMaxTokens, this.expService),
|
|
674
|
-
}),
|
|
675
|
-
diffHistory: {
|
|
676
|
-
nEntries: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffNEntries, this.expService),
|
|
677
|
-
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffMaxTokens, this.expService),
|
|
678
|
-
onlyForDocsInPrompt: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffOnlyForDocsInPrompt, this.expService),
|
|
679
|
-
useRelativePaths: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffUseRelativePaths, this.expService),
|
|
680
|
-
}
|
|
736
|
+
modelName: undefined,
|
|
737
|
+
...xtabPromptOptions.DEFAULT_OPTIONS,
|
|
681
738
|
};
|
|
682
739
|
}
|
|
740
|
+
const promptingStrategy = this.determinePromptingStrategy();
|
|
741
|
+
const sourcedModelConfig = {
|
|
742
|
+
modelName: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderModelName, this.expService),
|
|
743
|
+
promptingStrategy,
|
|
744
|
+
currentFile: {
|
|
745
|
+
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabCurrentFileMaxTokens, this.expService),
|
|
746
|
+
includeTags: promptingStrategy !== xtabPromptOptions.PromptingStrategy.UnifiedModel /* unified model doesn't use tags in current file */ && this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabIncludeTagsInCurrentFile, this.expService),
|
|
747
|
+
prioritizeAboveCursor: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabPrioritizeAboveCursor, this.expService)
|
|
748
|
+
},
|
|
749
|
+
pagedClipping: {
|
|
750
|
+
pageSize: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabPageSize, this.expService)
|
|
751
|
+
},
|
|
752
|
+
recentlyViewedDocuments: {
|
|
753
|
+
nDocuments: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabNRecentlyViewedDocuments, this.expService),
|
|
754
|
+
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabRecentlyViewedDocumentsMaxTokens, this.expService),
|
|
755
|
+
includeViewedFiles: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabIncludeViewedFiles, this.expService),
|
|
756
|
+
},
|
|
757
|
+
languageContext: this.determineLanguageContextOptions(activeDocument.languageId, {
|
|
758
|
+
enabled: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabLanguageContextEnabled, this.expService),
|
|
759
|
+
enabledLanguages: this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabLanguageContextEnabledLanguages),
|
|
760
|
+
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabLanguageContextMaxTokens, this.expService),
|
|
761
|
+
}),
|
|
762
|
+
diffHistory: {
|
|
763
|
+
nEntries: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffNEntries, this.expService),
|
|
764
|
+
maxTokens: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffMaxTokens, this.expService),
|
|
765
|
+
onlyForDocsInPrompt: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffOnlyForDocsInPrompt, this.expService),
|
|
766
|
+
useRelativePaths: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabDiffUseRelativePaths, this.expService),
|
|
767
|
+
},
|
|
768
|
+
includePostScript: true,
|
|
769
|
+
};
|
|
770
|
+
const localOverridingModelConfig = this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderModelConfiguration);
|
|
771
|
+
if (localOverridingModelConfig) {
|
|
772
|
+
return XtabProvider_1.overrideModelConfig(sourcedModelConfig, localOverridingModelConfig);
|
|
773
|
+
}
|
|
774
|
+
const expBasedModelConfig = this.overrideByStringModelConfig(sourcedModelConfig, configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderModelConfigurationString);
|
|
775
|
+
if (expBasedModelConfig) {
|
|
776
|
+
return expBasedModelConfig;
|
|
777
|
+
}
|
|
778
|
+
const defaultModelConfig = this.overrideByStringModelConfig(sourcedModelConfig, configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderDefaultModelConfigurationString);
|
|
779
|
+
if (defaultModelConfig) {
|
|
780
|
+
return defaultModelConfig;
|
|
781
|
+
}
|
|
782
|
+
return sourcedModelConfig;
|
|
683
783
|
}
|
|
684
|
-
|
|
784
|
+
overrideByStringModelConfig(originalModelConfig, configKey) {
|
|
785
|
+
const configString = this.configService.getExperimentBasedConfig(configKey, this.expService);
|
|
786
|
+
if (configString === undefined) {
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
let parsedConfig;
|
|
790
|
+
try {
|
|
791
|
+
parsedConfig = JSON.parse(configString);
|
|
792
|
+
}
|
|
793
|
+
catch (e) {
|
|
794
|
+
/* __GDPR__
|
|
795
|
+
"incorrectNesModelConfig" : {
|
|
796
|
+
"owner": "ulugbekna",
|
|
797
|
+
"comment": "Capture if model configuration string is invalid JSON.",
|
|
798
|
+
"configName": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Name of the configuration that failed to parse." },
|
|
799
|
+
"errorMessage": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Error message from JSON.parse." },
|
|
800
|
+
"configValue": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The invalid JSON string." }
|
|
801
|
+
}
|
|
802
|
+
*/
|
|
803
|
+
this.telemetryService.sendMSFTTelemetryEvent('incorrectNesModelConfig', { configName: configKey.id, errorMessage: errors.toString(errors.fromUnknown(e)), configValue: configString });
|
|
804
|
+
}
|
|
805
|
+
if (parsedConfig) {
|
|
806
|
+
return XtabProvider_1.overrideModelConfig(originalModelConfig, parsedConfig);
|
|
807
|
+
}
|
|
808
|
+
return undefined;
|
|
809
|
+
}
|
|
810
|
+
static overrideModelConfig(modelConfig, overridingConfig) {
|
|
811
|
+
return {
|
|
812
|
+
...modelConfig,
|
|
813
|
+
modelName: overridingConfig.modelName,
|
|
814
|
+
promptingStrategy: overridingConfig.promptingStrategy,
|
|
815
|
+
currentFile: {
|
|
816
|
+
...modelConfig.currentFile,
|
|
817
|
+
includeTags: overridingConfig.includeTagsInCurrentFile,
|
|
818
|
+
},
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
async predictNextCursorPosition(promptPieces) {
|
|
822
|
+
const tracer = this.tracer.sub('predictNextCursorPosition');
|
|
823
|
+
const systemMessage = 'Your task is to predict the next line number in the current file where the developer is most likely to make their next edit, using the provided context.';
|
|
824
|
+
const currentFileContentR = this.constructTaggedFile(promptPieces.currentDocument, promptPieces.editWindowLinesRange, promptPieces.areaAroundEditWindowLinesRange, {
|
|
825
|
+
...promptPieces.opts,
|
|
826
|
+
currentFile: {
|
|
827
|
+
...promptPieces.opts.currentFile,
|
|
828
|
+
includeTags: false,
|
|
829
|
+
}
|
|
830
|
+
}, XtabProvider_1.computeTokens, { includeLineNumbers: true });
|
|
831
|
+
if (currentFileContentR.isError()) {
|
|
832
|
+
tracer.trace(`Failed to construct tagged file: ${currentFileContentR.err}`);
|
|
833
|
+
return result_1.Result.fromString(currentFileContentR.err);
|
|
834
|
+
}
|
|
835
|
+
const { taggedCurrentFileR: { taggedCurrentFileContent }, areaAroundCodeToEdit } = currentFileContentR.val;
|
|
836
|
+
const newPromptPieces = new promptCrafting_1.PromptPieces(promptPieces.currentDocument, promptPieces.editWindowLinesRange, promptPieces.areaAroundEditWindowLinesRange, promptPieces.activeDoc, promptPieces.xtabHistory, taggedCurrentFileContent, areaAroundCodeToEdit, promptPieces.langCtx, XtabProvider_1.computeTokens, {
|
|
837
|
+
...promptPieces.opts,
|
|
838
|
+
includePostScript: false,
|
|
839
|
+
});
|
|
840
|
+
const userMessage = (0, promptCrafting_1.getUserPrompt)(newPromptPieces);
|
|
841
|
+
const messages = constructMessages({
|
|
842
|
+
systemMsg: systemMessage,
|
|
843
|
+
userMsg: userMessage
|
|
844
|
+
});
|
|
845
|
+
const modelName = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsNextCursorPredictionModelName, this.expService);
|
|
846
|
+
if (modelName === undefined) {
|
|
847
|
+
tracer.trace('Model name for cursor prediction is not defined; skipping prediction');
|
|
848
|
+
return result_1.Result.fromString('modelNameNotDefined');
|
|
849
|
+
}
|
|
850
|
+
const url = this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsNextCursorPredictionUrl);
|
|
851
|
+
const secretKey = this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsNextCursorPredictionApiKey);
|
|
852
|
+
const endpoint = this.instaService.createInstance(chatEndpoint_1.ChatEndpoint, {
|
|
853
|
+
id: modelName,
|
|
854
|
+
name: 'nes.nextCursorPosition',
|
|
855
|
+
urlOrRequestMetadata: url ? url : { type: copilot_api_1.RequestType.ProxyChatCompletions },
|
|
856
|
+
model_picker_enabled: false,
|
|
857
|
+
is_chat_default: false,
|
|
858
|
+
is_chat_fallback: false,
|
|
859
|
+
version: '',
|
|
860
|
+
capabilities: {
|
|
861
|
+
type: 'chat',
|
|
862
|
+
family: '',
|
|
863
|
+
tokenizer: tokenizer_1.TokenizerType.CL100K,
|
|
864
|
+
limits: undefined,
|
|
865
|
+
supports: {
|
|
866
|
+
parallel_tool_calls: false,
|
|
867
|
+
tool_calls: false,
|
|
868
|
+
streaming: true,
|
|
869
|
+
vision: false,
|
|
870
|
+
prediction: false,
|
|
871
|
+
thinking: false
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
});
|
|
875
|
+
const response = await endpoint.makeChatRequest2({
|
|
876
|
+
messages,
|
|
877
|
+
debugName: 'nes.nextCursorPosition',
|
|
878
|
+
finishedCb: undefined,
|
|
879
|
+
location: commonTypes_1.ChatLocation.Other,
|
|
880
|
+
requestOptions: secretKey ? {
|
|
881
|
+
secretKey,
|
|
882
|
+
} : undefined,
|
|
883
|
+
}, cancellation_1.CancellationToken.None);
|
|
884
|
+
if (response.type !== commonTypes_1.ChatFetchResponseType.Success) {
|
|
885
|
+
return result_1.Result.fromString(`fetchError:${response.type}`);
|
|
886
|
+
}
|
|
887
|
+
try {
|
|
888
|
+
const trimmed = response.value.trim();
|
|
889
|
+
const lineNumber = parseInt(trimmed, 10);
|
|
890
|
+
if (isNaN(lineNumber)) {
|
|
891
|
+
return result_1.Result.fromString(`gotNaN`);
|
|
892
|
+
}
|
|
893
|
+
if (lineNumber < 0) {
|
|
894
|
+
return result_1.Result.fromString(`negativeLineNumber`);
|
|
895
|
+
}
|
|
896
|
+
return result_1.Result.ok(lineNumber);
|
|
897
|
+
}
|
|
898
|
+
catch (err) {
|
|
899
|
+
tracer.trace(`Failed to parse predicted line number from response '${response.value}': ${err}`);
|
|
900
|
+
return result_1.Result.fromString(`failedToParseLine:"${response.value}". Error ${errors.fromUnknown(err).message}`);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
determinePromptingStrategy() {
|
|
904
|
+
const isXtabUnifiedModel = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabUseUnifiedModel, this.expService);
|
|
905
|
+
const isCodexV21NesUnified = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabCodexV21NesUnified, this.expService);
|
|
906
|
+
const useSimplifiedPrompt = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUseSimplifiedPrompt, this.expService);
|
|
907
|
+
const useXtab275Prompting = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUseXtab275Prompting, this.expService);
|
|
908
|
+
const useNes41Miniv3Prompting = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabUseNes41Miniv3Prompting, this.expService);
|
|
685
909
|
if (isXtabUnifiedModel) {
|
|
686
910
|
return xtabPromptOptions.PromptingStrategy.UnifiedModel;
|
|
687
911
|
}
|
|
@@ -723,18 +947,14 @@ let XtabProvider = class XtabProvider {
|
|
|
723
947
|
}
|
|
724
948
|
return { enabled, maxTokens };
|
|
725
949
|
}
|
|
726
|
-
getEndpoint() {
|
|
950
|
+
getEndpoint(configuredModelName) {
|
|
727
951
|
const url = this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUrl);
|
|
728
952
|
const apiKey = this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderApiKey);
|
|
729
953
|
const hasOverriddenUrlAndApiKey = url !== undefined && apiKey !== undefined;
|
|
730
|
-
const configuredModelName = this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderModelName, this.expService);
|
|
731
954
|
if (hasOverriddenUrlAndApiKey) {
|
|
732
955
|
return this.instaService.createInstance(xtabEndpoint_1.XtabEndpoint, url, apiKey, configuredModelName);
|
|
733
956
|
}
|
|
734
|
-
|
|
735
|
-
? undefined
|
|
736
|
-
: this.configService.getExperimentBasedConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderModelName, this.expService);
|
|
737
|
-
return (0, proxyXtabEndpoint_1.createProxyXtabEndpoint)(this.instaService, modelName);
|
|
957
|
+
return (0, proxyXtabEndpoint_1.createProxyXtabEndpoint)(this.instaService, configuredModelName);
|
|
738
958
|
}
|
|
739
959
|
getPredictedOutput(editWindowLines, promptingStrategy) {
|
|
740
960
|
return this.configService.getConfig(configurationService_1.ConfigKey.Internal.InlineEditsXtabProviderUsePrediction)
|
|
@@ -793,6 +1013,45 @@ exports.XtabProvider = XtabProvider = XtabProvider_1 = __decorate([
|
|
|
793
1013
|
__param(6, logService_1.ILogService),
|
|
794
1014
|
__param(7, languageContextProviderService_1.ILanguageContextProviderService),
|
|
795
1015
|
__param(8, languageDiagnosticsService_1.ILanguageDiagnosticsService),
|
|
796
|
-
__param(9, ignoreService_1.IIgnoreService)
|
|
1016
|
+
__param(9, ignoreService_1.IIgnoreService),
|
|
1017
|
+
__param(10, telemetry_1.ITelemetryService)
|
|
797
1018
|
], XtabProvider);
|
|
1019
|
+
/**
|
|
1020
|
+
* Finds the range of lines containing merge conflict markers within a specified edit window.
|
|
1021
|
+
*
|
|
1022
|
+
* @param lines - Array of strings representing the lines of text to search through
|
|
1023
|
+
* @param editWindowRange - The range within which to search for merge conflict markers
|
|
1024
|
+
* @param maxMergeConflictLines - Maximum number of lines to search for conflict markers
|
|
1025
|
+
* @returns An OffsetRange object representing the start and end of the conflict markers, or undefined if not found
|
|
1026
|
+
*/
|
|
1027
|
+
function findMergeConflictMarkersRange(lines, editWindowRange, maxMergeConflictLines) {
|
|
1028
|
+
for (let i = editWindowRange.start; i < Math.min(lines.length, editWindowRange.endExclusive); ++i) {
|
|
1029
|
+
if (!lines[i].startsWith('<<<<<<<')) {
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
// found start of merge conflict markers -- now find the end
|
|
1033
|
+
for (let j = i + 1; j < lines.length && (j - i) < maxMergeConflictLines; ++j) {
|
|
1034
|
+
if (lines[j].startsWith('>>>>>>>')) {
|
|
1035
|
+
return new offsetRange_1.OffsetRange(i, j + 1 /* because endExclusive */);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return undefined;
|
|
1040
|
+
}
|
|
1041
|
+
function constructMessages({ systemMsg, userMsg }) {
|
|
1042
|
+
return [
|
|
1043
|
+
{
|
|
1044
|
+
role: prompt_tsx_1.Raw.ChatRole.System,
|
|
1045
|
+
content: (0, globalStringUtils_1.toTextParts)(systemMsg)
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
role: prompt_tsx_1.Raw.ChatRole.User,
|
|
1049
|
+
content: (0, globalStringUtils_1.toTextParts)(userMsg)
|
|
1050
|
+
}
|
|
1051
|
+
];
|
|
1052
|
+
}
|
|
1053
|
+
function charCount(messages) {
|
|
1054
|
+
const promptCharCount = messages.reduce((total, msg) => total + msg.content.reduce((subtotal, part) => subtotal + (part.type === rawTypes_1.ChatCompletionContentPartKind.Text ? part.text.length : 0), 0), 0);
|
|
1055
|
+
return promptCharCount;
|
|
1056
|
+
}
|
|
798
1057
|
//# sourceMappingURL=xtabProvider.js.map
|