mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 22:32:28 +00:00
add chat.headers hook, adjust codex and copilot plugins to use it
This commit is contained in:
@@ -6,7 +6,6 @@ const CLIENT_ID = "Ov23li8tweQw6odWQebz"
|
||||
// Add a small safety buffer when polling to avoid hitting the server
|
||||
// slightly too early due to clock skew / timer drift.
|
||||
const OAUTH_POLLING_SAFETY_MARGIN_MS = 3000 // 3 seconds
|
||||
|
||||
function normalizeDomain(url: string) {
|
||||
return url.replace(/^https?:\/\//, "").replace(/\/$/, "")
|
||||
}
|
||||
@@ -19,6 +18,7 @@ function getUrls(domain: string) {
|
||||
}
|
||||
|
||||
export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
const sdk = input.client
|
||||
return {
|
||||
auth: {
|
||||
provider: "github-copilot",
|
||||
@@ -83,11 +83,11 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
})
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"x-initiator": isAgent ? "agent" : "user",
|
||||
...(init?.headers as Record<string, string>),
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
Authorization: `Bearer ${info.refresh}`,
|
||||
"Openai-Intent": "conversation-edits",
|
||||
"X-Initiator": isAgent ? "agent" : "user",
|
||||
}
|
||||
|
||||
if (isVision) {
|
||||
@@ -265,5 +265,19 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
},
|
||||
],
|
||||
},
|
||||
"chat.headers": async (input, output) => {
|
||||
if (!input.model.providerID.includes("github-copilot")) return
|
||||
const session = await sdk.session
|
||||
.get({
|
||||
path: {
|
||||
id: input.sessionID,
|
||||
},
|
||||
throwOnError: true,
|
||||
})
|
||||
.catch(() => undefined)
|
||||
if (!session || !session.data.parentID) return
|
||||
// TODO: mark subagent sessions as agent initiated once copilot gives ok
|
||||
// output.headers["x-initiator"] = "agent"
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user