Skip to content

Commit 5a6fa80

Browse files
committed
refactor: always use assistant+tool injection, skip for GitHub Copilot when last message is user role
1 parent f2866a8 commit 5a6fa80

File tree

2 files changed

+9
-48
lines changed

2 files changed

+9
-48
lines changed

lib/messages/inject.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
extractParameterKey,
88
buildToolIdList,
99
createSyntheticAssistantMessageWithToolPart,
10-
createSyntheticUserMessage,
1110
} from "./utils"
1211
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns"
1312
import { getLastUserMessage } from "../shared-utils"
@@ -143,22 +142,15 @@ export const insertPruneToolContext = (
143142
const isGitHubCopilot =
144143
providerID === "github-copilot" || providerID === "github-copilot-enterprise"
145144

146-
logger.info("Injecting prunable-tools list", {
147-
providerID,
148-
isGitHubCopilot,
149-
injectionType: isGitHubCopilot ? "assistant-with-tool-part" : "user-message",
150-
})
151-
152-
const variant = state.variant ?? (lastUserMessage.info as UserMessage).variant
153145
if (isGitHubCopilot) {
154-
messages.push(
155-
createSyntheticAssistantMessageWithToolPart(
156-
lastUserMessage,
157-
prunableToolsContent,
158-
variant,
159-
),
160-
)
161-
} else {
162-
messages.push(createSyntheticUserMessage(lastUserMessage, prunableToolsContent, variant))
146+
const lastMessage = messages[messages.length - 1]
147+
if (lastMessage?.info?.role === "user") {
148+
return
149+
}
163150
}
151+
152+
const variant = state.variant ?? userInfo.variant
153+
messages.push(
154+
createSyntheticAssistantMessageWithToolPart(lastUserMessage, prunableToolsContent, variant),
155+
)
164156
}

lib/messages/utils.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,6 @@ const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345"
77
const SYNTHETIC_PART_ID = "prt_01234567890123456789012345"
88
const SYNTHETIC_CALL_ID = "call_01234567890123456789012345"
99

10-
export const createSyntheticUserMessage = (
11-
baseMessage: WithParts,
12-
content: string,
13-
variant?: string,
14-
): WithParts => {
15-
const userInfo = baseMessage.info as UserMessage
16-
return {
17-
info: {
18-
id: SYNTHETIC_MESSAGE_ID,
19-
sessionID: userInfo.sessionID,
20-
role: "user",
21-
time: { created: Date.now() },
22-
agent: userInfo.agent || "code",
23-
model: {
24-
providerID: userInfo.model.providerID,
25-
modelID: userInfo.model.modelID,
26-
},
27-
...(variant !== undefined && { variant }),
28-
},
29-
parts: [
30-
{
31-
id: SYNTHETIC_PART_ID,
32-
sessionID: userInfo.sessionID,
33-
messageID: SYNTHETIC_MESSAGE_ID,
34-
type: "text",
35-
text: content,
36-
},
37-
],
38-
}
39-
}
40-
4110
export const createSyntheticAssistantMessageWithToolPart = (
4211
baseMessage: WithParts,
4312
content: string,

0 commit comments

Comments
 (0)