From 2040fff8cbcd2c590e64f62ffe248f34fbb65c3f Mon Sep 17 00:00:00 2001 From: Danny Gauthier Date: Mon, 28 Oct 2024 15:30:23 -0400 Subject: [PATCH] feat(answerAPI): insight generate endpoint --- packages/headless/src/api/knowledge/stream-answer-api.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/headless/src/api/knowledge/stream-answer-api.ts b/packages/headless/src/api/knowledge/stream-answer-api.ts index a13184555db..cef45084a5c 100644 --- a/packages/headless/src/api/knowledge/stream-answer-api.ts +++ b/packages/headless/src/api/knowledge/stream-answer-api.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { EventSourceMessage, fetchEventSource, @@ -17,6 +18,7 @@ import {SearchAppState} from '../../state/search-app-state.js'; import { ConfigurationSection, GeneratedAnswerSection, + InsightConfigurationSection, } from '../../state/state-sections.js'; import {getFacets} from '../../utils/facet-utils.js'; import {GeneratedAnswerCitation} from '../generated-answer/generated-answer-event-payload.js'; @@ -30,6 +32,7 @@ export type StateNeededByAnswerAPI = { answer: ReturnType; } & ConfigurationSection & Partial & + InsightConfigurationSection & GeneratedAnswerSection; export interface GeneratedAnswerStream { @@ -176,15 +179,17 @@ export const answerApi = answerSlice.injectEndpoints({ * It cannot use the inferred state used by Redux, thus the casting. * https://redux-toolkit.js.org/rtk-query/usage-with-typescript#typing-dispatch-and-getstate */ - const {configuration, generatedAnswer} = + const {configuration, generatedAnswer, insightConfiguration} = getState() as unknown as StateNeededByAnswerAPI; const {organizationId, environment, accessToken} = configuration; const platformEndpoint = getOrganizationEndpoint( organizationId, environment ); + const insightGenerateEndpoint = `${platformEndpoint}/rest/organizations/${organizationId}/insight/v1/configs/${insightConfiguration.insightId}/answer/${generatedAnswer.answerConfigurationId}/generate`; + const generateEndpoint = `${platformEndpoint}/rest/organizations/${organizationId}/answer/v1/configs/${generatedAnswer.answerConfigurationId}/generate`; await fetchEventSource( - `${platformEndpoint}/rest/organizations/${organizationId}/answer/v1/configs/${generatedAnswer.answerConfigurationId}/generate`, + insightConfiguration ? insightGenerateEndpoint : generateEndpoint, { method: 'POST', body: JSON.stringify(args),