fix(agent): preserve runtime request context

OpenCode tools run in a child service, so they cannot read the Agent process-local session map. Hydrate a sanitized context through the authenticated internal bridge and centralize backend project headers to prevent context loss across both boundaries.
This commit is contained in:
2026-08-05 18:39:09 +08:00
parent a53839e157
commit 2dc37e3fd8
7 changed files with 291 additions and 19 deletions
+25
View File
@@ -0,0 +1,25 @@
import type { RuntimeSessionContext } from "../runtime/sessionContext.js";
type BackendContext = Pick<
RuntimeSessionContext,
"accessToken" | "projectId" | "traceId"
>;
export const buildBackendContextHeaders = (
context: BackendContext,
): Record<string, string> => {
const headers: Record<string, string> = {
Accept: "application/json",
"Content-Type": "application/json",
"X-Trace-Id": context.traceId,
};
if (context.accessToken) {
headers.Authorization = `Bearer ${context.accessToken}`;
}
if (context.projectId) {
headers["X-Project-Id"] = context.projectId;
}
return headers;
};