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
18 changes: 17 additions & 1 deletion packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,23 @@ NOTE: At any point in time through this workflow you should feel free to ask the
}
}

yield* plugin.trigger("experimental.chat.messages.transform", {}, { messages: msgs })
// Allow plugins to transform messages before LLM invocation
// (e.g., replace image attachments with text descriptions via Vision)
yield* plugin.trigger(
"pre_chat.messages.transform",
{
sessionID,
agent: agent.name,
model,
messages: msgs,
},
{ messages: structuredClone(msgs) },
)
yield* plugin.trigger(
"experimental.chat.messages.transform",
{ sessionID, agent: agent.name, model, messages: msgs },
{ messages: msgs },
)

const [skills, env, instructions, modelMsgs] = yield* Effect.all([
sys.skills(agent),
Expand Down
33 changes: 33 additions & 0 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,39 @@ export interface Hooks {
metadata: any
},
) => Promise<void>
/**
* Called before the LLM is invoked. Allows plugins to inspect and
* transform the messages array (e.g., strip images, add vision
* descriptions, modify system prompts).
*
* - `messages`: The full messages array including all parts
* - `output.messages`: Return a new array or mutate to transform messages.
* Remove `FilePart` objects with `image: true` to strip images.
* Replace with `TextPart` containing the vision description.
* - Runs BEFORE `experimental.chat.messages.transform`.
*/
"pre_chat.messages.transform"?: (
input: {
sessionID: string
agent: string
model: Model
messages: {
info: Message
parts: Part[]
}[]
},
output: {
messages: {
info: Message
parts: Part[]
}[]
},
) => Promise<void>
/**
* @deprecated Use `pre_chat.messages.transform` instead.
* This hook exists for backward compatibility but has empty input
* and does not receive messages.
*/
"experimental.chat.messages.transform"?: (
input: {},
output: {
Expand Down
Loading