File size: 664 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * hostSdk/fetch.ts — auth-aware fetch wrapper for plugins.
 *
 * Reuses `buildAuthHeaders()` which already injects `Authorization`
 * and `X-Agent-Id` from the agent store. Plugin callers pass an API path
 * (e.g. "/console/chat") and get back a normal Response.
 */
import { getApiUrl } from "../../api/config";
import { buildAuthHeaders } from "../../api/authHeaders";

export async function hostFetch(
  path: string,
  init?: RequestInit,
): Promise<Response> {
  const headers: Record<string, string> = {
    ...buildAuthHeaders(),
    ...((init?.headers as Record<string, string>) ?? {}),
  };
  return fetch(getApiUrl(path), { ...init, headers });
}