export type GetApiApiDevicesAgentFileArgs = {file: 'remote.py' | 'requirements.txt'}; export type GetApiApiDevicesAgentFileOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download a device agent asset * * GET /api/devices/agent/{file} */ export const getApiApiDevicesAgentFile = async (args: GetApiApiDevicesAgentFileArgs, options: GetApiApiDevicesAgentFileOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/x-python") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/devices/agent/${encodeURIComponent(String(args.file))}${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 res.text() };