export type PipelineState = 'not_loaded' | 'loading' | 'loaded' | 'load_failed' | 'startup_failed' | 'failed'; export type ResourcePodInfo = {pod_name: string, pod_ip: string, node_name: string, state: PipelineState}; export type CreateApiV4ResourcesArgs = {body: ResourcePodInfo}; export type CreateApiV4ResourcesOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Set Pod Info * * POST /v4/resources * * Also accepts auth: HTTPBearer */ export const createApiV4Resources = async (args: CreateApiV4ResourcesArgs, options?: CreateApiV4ResourcesOptions) => { const {baseUrl = "https://www.mystic.ai", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v4/resources${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 undefined };