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.
26 lines
630 B
TypeScript
26 lines
630 B
TypeScript
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;
|
|
};
|