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),