export type CreateApiAgentsLaunchSyncArgs = {'X-Phantombuster-Org'?: string | undefined, body: {id: string, argument?: (string | Record) | undefined, arguments?: (string | Record) | undefined, bonusArgument?: (string | Record) | undefined, saveArgument?: boolean | undefined, saveArguments?: boolean | undefined, manualLaunch?: boolean | undefined, maxInstanceCount?: number | undefined, includeLogs?: boolean | undefined, persistedVolumeKey?: (string | null) | undefined}}; export type CreateApiAgentsLaunchSyncOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Launches an agent and streams execution status in real-time using NDJSON format. The stream begins with a start message exposing the containerId (so clients can reconnect via /containers/attach on disconnect) and then includes heartbeat messages, execution summary, and error messages if any occur. Optionally includes log lines when the includeLogs body parameter is set to true. * * POST /agents/launch-sync */ export const createApiAgentsLaunchSync = async (args: CreateApiAgentsLaunchSyncArgs, options?: CreateApiAgentsLaunchSyncOptions) => { const {baseUrl = "https://api.phantombuster.com/api/v2", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/x-ndjson") if (args['X-Phantombuster-Org'] != null) headers.set("X-Phantombuster-Org", String(args['X-Phantombuster-Org'])) if (apiKeyAuth !== undefined) headers.set("X-Phantombuster-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/agents/launch-sync${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };