[ACS-8399] Integrate all changes with backend (#10163)

This commit is contained in:
jacekpluta
2024-09-03 09:29:32 +02:00
committed by Aleksander Sklorz
parent dcaa736a0c
commit a21dc4d6a0
11 changed files with 66 additions and 130 deletions

View File

@@ -13,9 +13,8 @@ Manages agents in Content Services.
### Methods ### Methods
- **getAgents**(mocked?: `boolean`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AgentPaging`](../../../lib/js-api/src/api/content-rest-api/docs/AgentsApi.md#agentpaging)`>`<br/> - **getAgents**(): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AgentPaging`](../../../lib/js-api/src/api/content-rest-api/docs/AgentsApi.md#agentpaging)`>`<br/>
Gets all agents. Gets all agents.
- _mocked:_ `boolean` - (Optional) Temporary parameter to mock agents. Should be removed when backend implemented. True by default.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AgentPaging`](../../../lib/js-api/src/api/content-rest-api/docs/AgentsApi.md#agentpaging)`>` - AgentPaging object containing the agents. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AgentPaging`](../../../lib/js-api/src/api/content-rest-api/docs/AgentsApi.md#agentpaging)`>` - AgentPaging object containing the agents.
## Details ## Details

View File

@@ -19,12 +19,10 @@ Manages search AI in Content Services.
- **ask**(question: [`QuestionRequest`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionrequest)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`QuestionModel`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionmodel)`>`<br/> - **ask**(question: [`QuestionRequest`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionrequest)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`QuestionModel`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionmodel)`>`<br/>
Ask a question to the AI. Ask a question to the AI.
- _question:_ [`QuestionRequest`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionrequest) - The question to ask. - _question:_ [`QuestionRequest`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionrequest) - The question to ask.
- _mocked:_ `boolean` - (Optional) temporary parameter to mock returned information about question. Should be removed when backend implemented. True by default.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`QuestionModel`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionmodel)`>` - QuestionModel object containing information about questions. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`QuestionModel`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionmodel)`>` - QuestionModel object containing information about questions.
- **getAnswer**(questionId: `string`, mocked?: `boolean`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerPaging`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerpaging)`>`<br/> - **getAnswer**(questionId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerPaging`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerpaging)`>`<br/>
Get an answer to specific question. Get an answer to specific question.
- _questionId:_ `string` - The ID of the question to get an answer for. - _questionId:_ `string` - The ID of the question to get an answer for.
- _mocked:_ `boolean` - (Optional) temporary parameter to mock answer on question. Should be removed when backend implemented. True by default.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerPaging`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerpaging)`>` - AiAnswerPaging object containing the answer. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerPaging`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerpaging)`>` - AiAnswerPaging object containing the answer.
- **checkSearchAvailability**(selectedNodesState: `SelectionState`, maxSelectedNodes: `number`): `string`<br/> - **checkSearchAvailability**(selectedNodesState: `SelectionState`, maxSelectedNodes: `number`): `string`<br/>
Check if using of search is possible (if all conditions are met). Check if using of search is possible (if all conditions are met).

View File

@@ -45,7 +45,7 @@ const agentPagingObjectMock: AgentPaging = {
} }
}; };
const avatarAgentMock = 'https://res.cloudinary.com/hyld/image/upload/f_auto,c_fill,g_auto,w_1400,h_730/v1/h2/hero/blue-shirt-woman'; const avatarAgentMock = '';
const agentWithAvatarListMock: AgentWithAvatar[] = [ const agentWithAvatarListMock: AgentWithAvatar[] = [
{ {
@@ -71,7 +71,6 @@ describe('AgentService', () => {
agentService = TestBed.inject(AgentService); agentService = TestBed.inject(AgentService);
apiService = TestBed.inject(AlfrescoApiService); apiService = TestBed.inject(AlfrescoApiService);
agentsApi = new AgentsApi(apiService.getInstance()); agentsApi = new AgentsApi(apiService.getInstance());
agentService.mocked = false;
spyOn(agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock)); spyOn(agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
spyOn(agentService.agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock)); spyOn(agentService.agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));

View File

@@ -16,7 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AgentPaging, AgentsApi, AgentWithAvatar } from '@alfresco/js-api'; import { AgentsApi, AgentWithAvatar } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { BehaviorSubject, forkJoin, from, Observable, of } from 'rxjs'; import { BehaviorSubject, forkJoin, from, Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators'; import { switchMap } from 'rxjs/operators';
@@ -26,7 +26,6 @@ import { switchMap } from 'rxjs/operators';
}) })
export class AgentService { export class AgentService {
private _agentsApi: AgentsApi; private _agentsApi: AgentsApi;
private _mocked = true;
private agents = new BehaviorSubject<AgentWithAvatar[]>([]); private agents = new BehaviorSubject<AgentWithAvatar[]>([]);
get agentsApi(): AgentsApi { get agentsApi(): AgentsApi {
@@ -34,10 +33,6 @@ export class AgentService {
return this._agentsApi; return this._agentsApi;
} }
set mocked(mocked: boolean) {
this._mocked = mocked;
}
agents$ = this.agents.asObservable(); agents$ = this.agents.asObservable();
constructor(private apiService: AlfrescoApiService) {} constructor(private apiService: AlfrescoApiService) {}
@@ -53,12 +48,13 @@ export class AgentService {
if (agentsList.length) { if (agentsList.length) {
return of(agentsList); return of(agentsList);
} }
return this.getMockedAgents().pipe( return from(this.agentsApi.getAgents()).pipe(
switchMap((paging) => { switchMap((paging) => {
const agents = paging.list.entries.map((agentEntry) => agentEntry.entry); const agents = paging.list.entries.map((agentEntry) => agentEntry.entry);
return forkJoin([of(agents), ...agents.map((agent) => this.getAgentAvatar(agent.id))]); // TODO: fetch avatars https://hyland.atlassian.net/browse/ACS-8695
return forkJoin({ agents: of(agents), avatars: forkJoin(agents.map(() => of(``))) });
}), }),
switchMap(([agents, ...avatars]: [AgentWithAvatar[], string]) => { switchMap(({ agents, avatars }) => {
const agentsWithAvatar = agents.map((agent, index) => ({ ...agent, avatar: avatars[index] })); const agentsWithAvatar = agents.map((agent, index) => ({ ...agent, avatar: avatars[index] }));
this.agents.next(agentsWithAvatar); this.agents.next(agentsWithAvatar);
return of(agentsWithAvatar); return of(agentsWithAvatar);
@@ -68,46 +64,6 @@ export class AgentService {
); );
} }
/**
* Gets all agents.
*
* @returns AgentPaging object containing the agents.
*/
private getMockedAgents(): Observable<AgentPaging> {
return this._mocked
? of({
list: {
entries: [
{
entry: {
id: '1',
name: 'HR Agent',
description:
'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
}
},
{
entry: {
id: '2',
name: 'Policy Agent',
description:
'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
}
},
{
entry: {
id: '3',
name: 'Rules & Rates Agent',
description:
'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
}
}
]
}
})
: from(this.agentsApi.getAgents());
}
/** /**
* Gets agent avatar by agent id. * Gets agent avatar by agent id.
* *
@@ -115,8 +71,6 @@ export class AgentService {
* @returns string with an image. * @returns string with an image.
*/ */
getAgentAvatar(agentId: string): Observable<string> { getAgentAvatar(agentId: string): Observable<string> {
return this._mocked return from(this._agentsApi.getAgentAvatar(agentId));
? of('https://res.cloudinary.com/hyld/image/upload/f_auto,c_fill,g_auto,w_1400,h_730/v1/h2/hero/blue-shirt-woman')
: from(this._agentsApi.getAgentAvatar(agentId));
} }
} }

View File

@@ -30,7 +30,6 @@ describe('SearchAiService', () => {
imports: [ContentTestingModule] imports: [ContentTestingModule]
}); });
service = TestBed.inject(SearchAiService); service = TestBed.inject(SearchAiService);
service.mocked = false;
}); });
describe('ask', () => { describe('ask', () => {
@@ -38,12 +37,13 @@ describe('SearchAiService', () => {
const question: QuestionModel = { const question: QuestionModel = {
question: 'some question', question: 'some question',
questionId: 'some id', questionId: 'some id',
restrictionQuery: 'node id1,node id 2' restrictionQuery: { nodesIds: ['nodeId1', 'nodeId2'] }
}; };
spyOn(service.searchAiApi, 'ask').and.returnValue(Promise.resolve([question])); spyOn(service.searchAiApi, 'ask').and.returnValue(Promise.resolve(question));
const questionRequest: QuestionRequest = { const questionRequest: QuestionRequest = {
question: 'some question', question: 'some question',
nodeIds: ['node id1', 'node id 2'] nodeIds: ['nodeId1', 'nodeId2'],
agentId: 'some id'
}; };
service.ask(questionRequest).subscribe((questionResponse) => { service.ask(questionRequest).subscribe((questionResponse) => {

View File

@@ -18,8 +18,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AiAnswerPaging, QuestionModel, QuestionRequest, SearchAiApi } from '@alfresco/js-api'; import { AiAnswerPaging, QuestionModel, QuestionRequest, SearchAiApi } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { BehaviorSubject, from, Observable, of } from 'rxjs'; import { BehaviorSubject, from, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { SelectionState } from '@alfresco/adf-extensions'; import { SelectionState } from '@alfresco/adf-extensions';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { SearchAiInputState } from '../models/search-ai-input-state'; import { SearchAiInputState } from '../models/search-ai-input-state';
@@ -32,23 +31,15 @@ export class SearchAiService {
active: false active: false
}); });
private _searchAiApi: SearchAiApi; private _searchAiApi: SearchAiApi;
private _mocked = true;
get searchAiApi(): SearchAiApi { get searchAiApi(): SearchAiApi {
this._searchAiApi = this._searchAiApi ?? new SearchAiApi(this.apiService.getInstance()); this._searchAiApi = this._searchAiApi ?? new SearchAiApi(this.apiService.getInstance());
return this._searchAiApi; return this._searchAiApi;
} }
set mocked(mocked: boolean) {
this._mocked = mocked;
}
toggleSearchAiInput$ = this.toggleSearchAiInput.asObservable(); toggleSearchAiInput$ = this.toggleSearchAiInput.asObservable();
constructor( constructor(private apiService: AlfrescoApiService, private translateService: TranslateService) {}
private apiService: AlfrescoApiService,
private translateService: TranslateService
) {}
/** /**
* Update the state of the search AI input. * Update the state of the search AI input.
@@ -66,13 +57,7 @@ export class SearchAiService {
* @returns QuestionModel object containing information about questions. * @returns QuestionModel object containing information about questions.
*/ */
ask(question: QuestionRequest): Observable<QuestionModel> { ask(question: QuestionRequest): Observable<QuestionModel> {
return this._mocked return from(this.searchAiApi.ask([question]));
? of({
question: 'Some question',
questionId: 'some id',
restrictionQuery: 'Some restriction query'
})
: from(this.searchAiApi.ask([question])).pipe(map((questions) => questions[0]));
} }
/** /**
@@ -82,37 +67,7 @@ export class SearchAiService {
* @returns AiAnswerPaging object containing the answer. * @returns AiAnswerPaging object containing the answer.
*/ */
getAnswer(questionId: string): Observable<AiAnswerPaging> { getAnswer(questionId: string): Observable<AiAnswerPaging> {
return this._mocked return from(this.searchAiApi.getAnswer(questionId));
? of({
list: {
pagination: {
count: 1,
hasMoreItems: false,
totalItems: 1,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
answer: 'Some answer',
questionId: 'some id',
references: [
{
referenceId: '45a84919-d654-4669-a849-19d6548669e9',
referenceText: 'some type'
},
{
referenceId: '45a84919-d654-4669-a849-19d6548669e9',
referenceText: 'some type'
}
]
}
}
]
}
})
: from(this.searchAiApi.getAnswer(questionId));
} }
/** /**

View File

@@ -27,17 +27,18 @@ export class SearchAiApi extends BaseApi {
/** /**
* Ask a question to the AI. * Ask a question to the AI.
* *
* @param questions The questions to ask. * @param questions QuestionRequest array containing questions to ask.
* @returns QuestionModel object containing information about questions. * @returns QuestionModel object containing information about questions.
*/ */
ask(questions: QuestionRequest[]): Promise<QuestionModel[]> { ask(questions: QuestionRequest[]): Promise<QuestionModel> {
return this.get({ const agentId = questions[0].agentId;
path: 'questions', return this.post({
path: `agents/${agentId}/questions`,
bodyParam: questions.map((questionRequest) => ({ bodyParam: questions.map((questionRequest) => ({
question: questionRequest.question, question: questionRequest.question,
restrictionQuery: questionRequest.nodeIds.join(',') restrictionQuery: { nodesIds: questionRequest.nodeIds }
})) }))
}); }).then((response) => response.entry);
} }
/** /**
@@ -48,10 +49,7 @@ export class SearchAiApi extends BaseApi {
*/ */
getAnswer(questionId: string): Promise<AiAnswerPaging> { getAnswer(questionId: string): Promise<AiAnswerPaging> {
return this.get({ return this.get({
path: 'answers', path: `questions/${questionId}/answers`
queryParams: {
questionId
}
}); });
} }
} }

View File

@@ -30,7 +30,8 @@ const searchAiApi = new SearchAiApi(alfrescoApi);
searchAiApi.ask([{ searchAiApi.ask([{
question: 'Some question', question: 'Some question',
restrictionQuery: 'Some restriction query' restrictionQuery: 'Some restriction query',
agentId: 'Some agent id'
}]).then((questionInformation) => { }]).then((questionInformation) => {
console.log('API called successfully. Returned data: ' + questionInformation); console.log('API called successfully. Returned data: ' + questionInformation);
}); });
@@ -146,11 +147,19 @@ searchAiApi.getAnswer('some question id').then((answer) => {
**Properties** **Properties**
| Name | Type | | Name | Type |
|----------------------|--------| |----------------------|------------------|
| **question** | string | | **question** | string |
| **questionId** | string | | **questionId** | string |
| **restrictionQuery** | string | | **restrictionQuery** | RestrictionQuery |
## RestrictionQuery
**Properties**
| Name | Type |
|--------------|----------|
| **nodesIds** | string[] |
## QuestionRequest ## QuestionRequest
@@ -160,3 +169,4 @@ searchAiApi.getAnswer('some question id').then((answer) => {
|--------------|----------| |--------------|----------|
| **question** | string | | **question** | string |
| **nodeIds** | string[] | | **nodeIds** | string[] |
| **agentId** | string |

View File

@@ -15,8 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { RestrictionQuery } from './restrictionQuery';
export interface QuestionModel { export interface QuestionModel {
question: string;
questionId: string; questionId: string;
restrictionQuery: string; question: string;
restrictionQuery: RestrictionQuery;
} }

View File

@@ -18,4 +18,5 @@
export interface QuestionRequest { export interface QuestionRequest {
question: string; question: string;
nodeIds: string[]; nodeIds: string[];
agentId: string;
} }

View File

@@ -0,0 +1,20 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface RestrictionQuery {
nodesIds: string[];
}