export type GetApiApiAgentsIdAttributionArgs = {id: string, hours?: number | undefined, section?: string | undefined, privileged?: '1' | undefined, 'x-agent-name'?: string | undefined}; export type GetApiApiAgentsIdAttributionOptions = {baseUrl: string, sessionCookie?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get attribution report for an agent * * GET /api/agents/{id}/attribution * * Also accepts auth: apiKey */ export const getApiApiAgentsIdAttribution = async (args: GetApiApiAgentsIdAttributionArgs, options: GetApiApiAgentsIdAttributionOptions) => { const {baseUrl, fetch: fetchFn = fetch, sessionCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.hours != null) query.append("hours", String(args.hours)) if (args.section != null) query.append("section", String(args.section)) if (args.privileged != null) query.append("privileged", String(args.privileged)) if (args['x-agent-name'] != null) headers.set("x-agent-name", String(args['x-agent-name'])) if (sessionCookie !== undefined) cookies.push("__Host-mc-session=" + encodeURIComponent(sessionCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/api/agents/${encodeURIComponent(String(args.id))}/attribution${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };