Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/messages/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Logger } from "../logger"
import type { PluginConfig } from "../config"
import { loadPrompt } from "../prompts"
import { extractParameterKey, buildToolIdList, createSyntheticUserMessage } from "./utils"
import { getLastUserMessage } from "../shared-utils"
import { getLastUserMessage, findUserVariant } from "../shared-utils"

const getNudgeString = (config: PluginConfig): string => {
const discardEnabled = config.tools.discard.enabled
Expand Down Expand Up @@ -125,5 +125,6 @@ export const insertPruneToolContext = (
if (!lastUserMessage) {
return
}
messages.push(createSyntheticUserMessage(lastUserMessage, prunableToolsContent))
const variant = findUserVariant(messages)
messages.push(createSyntheticUserMessage(lastUserMessage, prunableToolsContent, variant))
}
4 changes: 3 additions & 1 deletion lib/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { UserMessage } from "@opencode-ai/sdk"
const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345"
const SYNTHETIC_PART_ID = "prt_01234567890123456789012345"

export const createSyntheticUserMessage = (baseMessage: WithParts, content: string): WithParts => {
export const createSyntheticUserMessage = (baseMessage: WithParts, content: string, variant?: string): WithParts => {
const userInfo = baseMessage.info as UserMessage
return {
info: {
Expand All @@ -19,6 +19,8 @@ export const createSyntheticUserMessage = (baseMessage: WithParts, content: stri
providerID: userInfo.model.providerID,
modelID: userInfo.model.modelID,
},
// @opencode-ai/sdk doesn't yet ship a variant type
...(variant !== undefined && { variant }),
},
parts: [
{
Expand Down
13 changes: 13 additions & 0 deletions lib/shared-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ export const getLastUserMessage = (messages: WithParts[]): WithParts | null => {
}
return null
}

export const findUserVariant = (messages: WithParts[]): string | undefined => {
for (let i = messages.length - 1; i >= 0; i--) {
const msg = messages[i]
if (msg.info.role === "user") {
const variant = (msg.info as any).variant
if (variant !== undefined && variant !== null) {
return variant
}
}
}
return undefined
}