@@ -31,13 +31,15 @@ import { HelperVars } from "../autocomplete/util/HelperVars.js";
3131import { AutocompleteInput } from "../autocomplete/util/types.js" ;
3232import { myersDiff } from "../diff/myers.js" ;
3333import { modelSupportsNextEdit } from "../llm/autodetect.js" ;
34+ import { NEXT_EDIT_MODELS } from "../llm/constants.js" ;
3435import { countTokens } from "../llm/countTokens.js" ;
3536import { localPathOrUriToPath } from "../util/pathToUri.js" ;
3637import {
3738 INSTINCT_SYSTEM_PROMPT ,
3839 MERCURY_CODE_TO_EDIT_OPEN ,
3940 MERCURY_SYSTEM_PROMPT ,
4041 MODEL_WINDOW_SIZES ,
42+ UNIQUE_TOKEN ,
4143} from "./constants.js" ;
4244import { createDiff , DiffFormatType } from "./context/diffFormatting.js" ;
4345import {
@@ -392,9 +394,13 @@ export class NextEditProvider {
392394 this . ide . getWorkspaceDirs ( ) ,
393395 ] ) ;
394396
395- const modelName = helper . modelName . includes ( "mercury-coder-nextedit" )
396- ? "mercury-coder-nextedit"
397- : "instinct" ;
397+ const modelName = helper . modelName . includes (
398+ NEXT_EDIT_MODELS . MERCURY_CODER_NEXTEDIT ,
399+ )
400+ ? NEXT_EDIT_MODELS . MERCURY_CODER_NEXTEDIT
401+ : helper . modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER )
402+ ? NEXT_EDIT_MODELS . MERCURY_CODER
403+ : NEXT_EDIT_MODELS . INSTINCT ;
398404
399405 const { editableRegionStartLine, editableRegionEndLine } =
400406 opts ?. usingFullFileDiff
@@ -551,7 +557,10 @@ export class NextEditProvider {
551557 const modelName = helper . modelName ;
552558 let ctx : any ;
553559
554- if ( modelName . includes ( "mercury-coder-nextedit" ) ) {
560+ if (
561+ modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER ) ||
562+ modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER_NEXTEDIT )
563+ ) {
555564 ctx = {
556565 recentlyViewedCodeSnippets :
557566 snippetPayload . recentlyVisitedRangesSnippets . map ( ( snip ) => ( {
@@ -564,7 +573,7 @@ export class NextEditProvider {
564573 editDiffHistory : this . diffContext ,
565574 currentFilePath : helper . filepath ,
566575 } ;
567- } else if ( modelName . includes ( "instinct" ) ) {
576+ } else if ( modelName . includes ( NEXT_EDIT_MODELS . INSTINCT ) ) {
568577 // Calculate the window around the cursor position (25 lines above and below).
569578 const windowStart = Math . max ( 0 , helper . pos . line - 25 ) ;
570579 const windowEnd = Math . min (
@@ -608,9 +617,11 @@ export class NextEditProvider {
608617
609618 const systemPrompt : Prompt = {
610619 role : "system" ,
611- content : modelName . includes ( "mercury-coder-nextedit" )
612- ? MERCURY_SYSTEM_PROMPT
613- : INSTINCT_SYSTEM_PROMPT ,
620+ content :
621+ modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER ) ||
622+ modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER_NEXTEDIT )
623+ ? MERCURY_SYSTEM_PROMPT
624+ : INSTINCT_SYSTEM_PROMPT ,
614625 } ;
615626
616627 return [ systemPrompt , promptMetadata . prompt ] ;
@@ -677,7 +688,28 @@ export class NextEditProvider {
677688 const llm = await this . _prepareLlm ( ) ;
678689 if ( ! llm ) return undefined ;
679690
680- const msg : ChatMessage = await llm . chat ( prompts , token ) ;
691+ // TODO: Check for mercury models, and inject some unique tokens so that
692+ // the backend knows that mercury-coder is a next edit.
693+ // TODO: Capture the unique tokens in llm Inception.ts and apis Inception.ts
694+ // TODO: where does capabilities come in???
695+ // My best answer is that it's a non-mercury-specific way of determining if
696+ // the model supports next edit. If it does, then we can inject the unique tokens.
697+
698+ // Check for mercury models, and inject unique token for next edit.
699+ const modelName = helper . modelName ;
700+ if (
701+ modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER ) ||
702+ modelName . includes ( NEXT_EDIT_MODELS . MERCURY_CODER_NEXTEDIT )
703+ ) {
704+ // Inject the unique token to the last prompt's content.
705+ // TODO: Check if there is an actual modification of prompts.
706+ const lastPrompt = prompts [ prompts . length - 1 ] ;
707+ if ( lastPrompt && typeof lastPrompt . content === "string" ) {
708+ lastPrompt . content += UNIQUE_TOKEN ;
709+ }
710+ }
711+
712+ const msg : ChatMessage = await llm . chat ( [ prompts [ 1 ] ] , token ) ;
681713 console . log ( "message" ) ;
682714 console . log ( msg . content ) ;
683715
0 commit comments