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:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user