export type PlaygroundCopilotRequest = {prompt: string, system: string, app_id: string}; export type CreateApiV1PlaygroundCopilotArgs = {body: PlaygroundCopilotRequest}; export type CreateApiV1PlaygroundCopilotOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Copilot Request * * POST /v1/playground/copilot */ export const createApiV1PlaygroundCopilot = async (args: CreateApiV1PlaygroundCopilotArgs, options: CreateApiV1PlaygroundCopilotOptions) => { const {baseUrl, 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(/\/+$/, '')}/v1/playground/copilot${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 };