export type CreateApiApiV1ContextWebhookArgs = {body: {event: 'context.add' | 'context.async.add.started' | 'context.async.add.in-progress' | 'context.async.add.failed' | 'context.async.add.completed' | 'context.search' | 'context.steer' | 'context.delete' | 'context.view' | 'context.memory.add' | 'context.memory.delete' | 'context.memory.update', organization_id: string, user_id?: string | undefined, data?: Record | undefined}}; export type CreateApiApiV1ContextWebhookOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Context processor webhook endpoint * * POST /api/v1/context/webhook */ export const createApiApiV1ContextWebhook = async (args: CreateApiApiV1ContextWebhookArgs, options?: CreateApiApiV1ContextWebhookOptions) => { const {baseUrl = "https://platform-backend.getalchemystai.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/context/webhook${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 };