export type PlaygroundToolCallBody = {arguments: string, id: string, name: string}; export type PlaygroundMessageBody = {content: unknown, reasoningContent?: (string | null) | undefined, role: string, toolCallId?: (string | null) | undefined, toolCalls?: Array | undefined}; export type PlaygroundColumnBody = {messages: Array, model?: (string | null) | undefined, params?: {[key: string]: unknown} | undefined, providerId: string, responseFormat: unknown, tools: unknown}; export type PlaygroundRowBody = {expectedOutput: unknown, input: unknown, metadata: unknown}; export type CreateApiApiOrgIdPlaygroundRunArgs = {org_id: string, body: {column: PlaygroundColumnBody, row?: PlaygroundRowBody | undefined}}; export type CreateApiApiOrgIdPlaygroundRunOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /api/{org_id}/playground/run */ export const createApiApiOrgIdPlaygroundRun = async (args: CreateApiApiOrgIdPlaygroundRunArgs, options: CreateApiApiOrgIdPlaygroundRunOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/playground/run${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.text() };