mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[ACS-8399] Integrate all changes with backend (#10163)
This commit is contained in:
committed by
Aleksander Sklorz
parent
dcaa736a0c
commit
a21dc4d6a0
@@ -13,9 +13,8 @@ Manages agents in Content Services.
|
||||
|
||||
### 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.
|
||||
- _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.
|
||||
|
||||
## Details
|
||||
|
@@ -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 a question to the AI.
|
||||
- _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.
|
||||
- **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.
|
||||
- _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.
|
||||
- **checkSearchAvailability**(selectedNodesState: `SelectionState`, maxSelectedNodes: `number`): `string`<br/>
|
||||
Check if using of search is possible (if all conditions are met).
|
||||
|
@@ -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[] = [
|
||||
{
|
||||
@@ -71,7 +71,6 @@ describe('AgentService', () => {
|
||||
agentService = TestBed.inject(AgentService);
|
||||
apiService = TestBed.inject(AlfrescoApiService);
|
||||
agentsApi = new AgentsApi(apiService.getInstance());
|
||||
agentService.mocked = false;
|
||||
|
||||
spyOn(agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
|
||||
spyOn(agentService.agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
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 { BehaviorSubject, forkJoin, from, Observable, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
@@ -26,7 +26,6 @@ import { switchMap } from 'rxjs/operators';
|
||||
})
|
||||
export class AgentService {
|
||||
private _agentsApi: AgentsApi;
|
||||
private _mocked = true;
|
||||
private agents = new BehaviorSubject<AgentWithAvatar[]>([]);
|
||||
|
||||
get agentsApi(): AgentsApi {
|
||||
@@ -34,10 +33,6 @@ export class AgentService {
|
||||
return this._agentsApi;
|
||||
}
|
||||
|
||||
set mocked(mocked: boolean) {
|
||||
this._mocked = mocked;
|
||||
}
|
||||
|
||||
agents$ = this.agents.asObservable();
|
||||
|
||||
constructor(private apiService: AlfrescoApiService) {}
|
||||
@@ -53,12 +48,13 @@ export class AgentService {
|
||||
if (agentsList.length) {
|
||||
return of(agentsList);
|
||||
}
|
||||
return this.getMockedAgents().pipe(
|
||||
return from(this.agentsApi.getAgents()).pipe(
|
||||
switchMap((paging) => {
|
||||
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] }));
|
||||
this.agents.next(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.
|
||||
*
|
||||
@@ -115,8 +71,6 @@ export class AgentService {
|
||||
* @returns string with an image.
|
||||
*/
|
||||
getAgentAvatar(agentId: string): Observable<string> {
|
||||
return this._mocked
|
||||
? 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));
|
||||
return from(this._agentsApi.getAgentAvatar(agentId));
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,6 @@ describe('SearchAiService', () => {
|
||||
imports: [ContentTestingModule]
|
||||
});
|
||||
service = TestBed.inject(SearchAiService);
|
||||
service.mocked = false;
|
||||
});
|
||||
|
||||
describe('ask', () => {
|
||||
@@ -38,12 +37,13 @@ describe('SearchAiService', () => {
|
||||
const question: QuestionModel = {
|
||||
question: 'some question',
|
||||
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 = {
|
||||
question: 'some question',
|
||||
nodeIds: ['node id1', 'node id 2']
|
||||
nodeIds: ['nodeId1', 'nodeId2'],
|
||||
agentId: 'some id'
|
||||
};
|
||||
|
||||
service.ask(questionRequest).subscribe((questionResponse) => {
|
||||
|
@@ -18,8 +18,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AiAnswerPaging, QuestionModel, QuestionRequest, SearchAiApi } from '@alfresco/js-api';
|
||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { BehaviorSubject, from, Observable } from 'rxjs';
|
||||
import { SelectionState } from '@alfresco/adf-extensions';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { SearchAiInputState } from '../models/search-ai-input-state';
|
||||
@@ -32,23 +31,15 @@ export class SearchAiService {
|
||||
active: false
|
||||
});
|
||||
private _searchAiApi: SearchAiApi;
|
||||
private _mocked = true;
|
||||
|
||||
get searchAiApi(): SearchAiApi {
|
||||
this._searchAiApi = this._searchAiApi ?? new SearchAiApi(this.apiService.getInstance());
|
||||
return this._searchAiApi;
|
||||
}
|
||||
|
||||
set mocked(mocked: boolean) {
|
||||
this._mocked = mocked;
|
||||
}
|
||||
|
||||
toggleSearchAiInput$ = this.toggleSearchAiInput.asObservable();
|
||||
|
||||
constructor(
|
||||
private apiService: AlfrescoApiService,
|
||||
private translateService: TranslateService
|
||||
) {}
|
||||
constructor(private apiService: AlfrescoApiService, private translateService: TranslateService) {}
|
||||
|
||||
/**
|
||||
* Update the state of the search AI input.
|
||||
@@ -66,13 +57,7 @@ export class SearchAiService {
|
||||
* @returns QuestionModel object containing information about questions.
|
||||
*/
|
||||
ask(question: QuestionRequest): Observable<QuestionModel> {
|
||||
return this._mocked
|
||||
? of({
|
||||
question: 'Some question',
|
||||
questionId: 'some id',
|
||||
restrictionQuery: 'Some restriction query'
|
||||
})
|
||||
: from(this.searchAiApi.ask([question])).pipe(map((questions) => questions[0]));
|
||||
return from(this.searchAiApi.ask([question]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,37 +67,7 @@ export class SearchAiService {
|
||||
* @returns AiAnswerPaging object containing the answer.
|
||||
*/
|
||||
getAnswer(questionId: string): Observable<AiAnswerPaging> {
|
||||
return this._mocked
|
||||
? 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));
|
||||
return from(this.searchAiApi.getAnswer(questionId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -27,17 +27,18 @@ export class SearchAiApi extends BaseApi {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
ask(questions: QuestionRequest[]): Promise<QuestionModel[]> {
|
||||
return this.get({
|
||||
path: 'questions',
|
||||
ask(questions: QuestionRequest[]): Promise<QuestionModel> {
|
||||
const agentId = questions[0].agentId;
|
||||
return this.post({
|
||||
path: `agents/${agentId}/questions`,
|
||||
bodyParam: questions.map((questionRequest) => ({
|
||||
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> {
|
||||
return this.get({
|
||||
path: 'answers',
|
||||
queryParams: {
|
||||
questionId
|
||||
}
|
||||
path: `questions/${questionId}/answers`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,8 @@ const searchAiApi = new SearchAiApi(alfrescoApi);
|
||||
|
||||
searchAiApi.ask([{
|
||||
question: 'Some question',
|
||||
restrictionQuery: 'Some restriction query'
|
||||
restrictionQuery: 'Some restriction query',
|
||||
agentId: 'Some agent id'
|
||||
}]).then((questionInformation) => {
|
||||
console.log('API called successfully. Returned data: ' + questionInformation);
|
||||
});
|
||||
@@ -147,10 +148,18 @@ searchAiApi.getAnswer('some question id').then((answer) => {
|
||||
**Properties**
|
||||
|
||||
| Name | Type |
|
||||
|----------------------|--------|
|
||||
|----------------------|------------------|
|
||||
| **question** | string |
|
||||
| **questionId** | string |
|
||||
| **restrictionQuery** | string |
|
||||
| **restrictionQuery** | RestrictionQuery |
|
||||
|
||||
## RestrictionQuery
|
||||
|
||||
**Properties**
|
||||
|
||||
| Name | Type |
|
||||
|--------------|----------|
|
||||
| **nodesIds** | string[] |
|
||||
|
||||
## QuestionRequest
|
||||
|
||||
@@ -160,3 +169,4 @@ searchAiApi.getAnswer('some question id').then((answer) => {
|
||||
|--------------|----------|
|
||||
| **question** | string |
|
||||
| **nodeIds** | string[] |
|
||||
| **agentId** | string |
|
||||
|
@@ -15,8 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { RestrictionQuery } from './restrictionQuery';
|
||||
|
||||
export interface QuestionModel {
|
||||
question: string;
|
||||
questionId: string;
|
||||
restrictionQuery: string;
|
||||
question: string;
|
||||
restrictionQuery: RestrictionQuery;
|
||||
}
|
||||
|
@@ -18,4 +18,5 @@
|
||||
export interface QuestionRequest {
|
||||
question: string;
|
||||
nodeIds: string[];
|
||||
agentId: string;
|
||||
}
|
||||
|
@@ -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[];
|
||||
}
|
Reference in New Issue
Block a user