add chat.headers hook, adjust codex and copilot plugins to use it

This commit is contained in:
Aiden Cline
2026-01-21 15:09:56 -06:00
parent 17a5f75b54
commit c89f6e7ac6
4 changed files with 45 additions and 11 deletions

View File

@@ -53,6 +53,7 @@ export namespace LLM {
.tag("sessionID", input.sessionID)
.tag("small", (input.small ?? false).toString())
.tag("agent", input.agent.name)
.tag("mode", input.agent.mode)
l.info("stream", {
modelID: input.model.id,
providerID: input.model.providerID,
@@ -131,6 +132,20 @@ export namespace LLM {
},
)
const { headers } = await Plugin.trigger(
"chat.headers",
{
sessionID: input.sessionID,
agent: input.agent,
model: input.model,
provider,
message: input.user,
},
{
headers: {},
},
)
const maxOutputTokens = isCodex
? undefined
: ProviderTransform.maxOutputTokens(
@@ -198,13 +213,6 @@ export namespace LLM {
maxOutputTokens,
abortSignal: input.abort,
headers: {
...(isCodex
? {
originator: "opencode",
"User-Agent": `opencode/${Installation.VERSION} (${os.platform()} ${os.release()}; ${os.arch()})`,
session_id: input.sessionID,
}
: undefined),
...(input.model.providerID.startsWith("opencode")
? {
"x-opencode-project": Instance.project.id,
@@ -218,6 +226,7 @@ export namespace LLM {
}
: undefined),
...input.model.headers,
...headers,
},
maxRetries: input.retries ?? 0,
messages: [