@neuralinnovations/dataisland-sdk 0.0.1-dev8 → 0.0.1-dev9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npm.yml +11 -0
- package/.github/workflows/tests.yml +4 -0
- package/.github/workflows/version.yml +5 -1
- package/README.md +36 -3
- package/docs/classes/BasicCredential.md +1 -1
- package/docs/classes/BearerCredential.md +1 -1
- package/docs/classes/Chat.md +34 -6
- package/docs/classes/Chats.md +87 -1
- package/docs/classes/CredentialBase.md +1 -1
- package/docs/classes/DataIslandApp.md +1 -1
- package/docs/classes/DebugCredential.md +1 -1
- package/docs/classes/DefaultCredential.md +1 -1
- package/docs/classes/DisposableContainer.md +1 -1
- package/docs/classes/EventDispatcher.md +1 -1
- package/docs/classes/File.md +1 -1
- package/docs/classes/Files.md +2 -2
- package/docs/classes/FilesPage.md +1 -1
- package/docs/classes/Group.md +19 -1
- package/docs/classes/Groups.md +27 -3
- package/docs/classes/Lifetime.md +1 -1
- package/docs/classes/Organization.md +37 -1
- package/docs/classes/Organizations.md +1 -1
- package/docs/classes/UserProfile.md +1 -1
- package/docs/classes/Workspace.md +1 -1
- package/docs/classes/Workspaces.md +6 -2
- package/docs/enums/ChatAnswerType.md +22 -0
- package/docs/enums/ChatsEvent.md +1 -1
- package/docs/enums/FilesEvent.md +1 -1
- package/docs/enums/GroupEvent.md +3 -1
- package/docs/enums/OrganizationsEvent.md +1 -1
- package/docs/enums/UserEvent.md +1 -1
- package/docs/enums/WorkspaceEvent.md +1 -1
- package/docs/enums/WorkspacesEvent.md +1 -1
- package/docs/interfaces/Disposable.md +1 -1
- package/docs/interfaces/Event.md +1 -1
- package/docs/interfaces/EventSubscriber.md +1 -1
- package/docs/interfaces/Input.md +1 -1
- package/docs/modules.md +5 -3
- package/package.json +6 -2
- package/src/dataIslandApp.ts +2 -2
- package/src/dto/chatResponse.ts +54 -55
- package/src/dto/workspacesResponse.ts +2 -2
- package/src/index.ts +13 -13
- package/src/internal/app.impl.ts +2 -2
- package/src/services/organizationService.ts +2 -2
- package/src/services/userProfileService.ts +2 -2
- package/src/storages/chats/answer.impl.ts +163 -0
- package/src/storages/chats/answer.ts +42 -0
- package/src/storages/chats/chat.impl.ts +87 -0
- package/src/storages/chats/chat.ts +38 -0
- package/src/storages/chats/chats.impl.ts +142 -0
- package/src/storages/chats/chats.ts +47 -0
- package/src/storages/{file.impl.ts → files/file.impl.ts} +5 -5
- package/src/storages/{file.ts → files/file.ts} +1 -1
- package/src/storages/{files.impl.ts → files/files.impl.ts} +6 -6
- package/src/storages/{files.ts → files/files.ts} +2 -2
- package/src/storages/{groups.impl.ts → groups/groups.impl.ts} +86 -97
- package/src/storages/groups/groups.ts +101 -0
- package/src/storages/{organization.impl.ts → organizations/organization.impl.ts} +34 -7
- package/src/storages/{organization.ts → organizations/organization.ts} +13 -2
- package/src/storages/{organizations.impl.ts → organizations/organizations.impl.ts} +10 -4
- package/src/storages/{organizations.ts → organizations/organizations.ts} +1 -1
- package/src/storages/{userProfile.impl.ts → user/userProfile.impl.ts} +1 -1
- package/src/storages/{userProfile.ts → user/userProfile.ts} +1 -1
- package/src/storages/{workspace.impl.ts → workspaces/workspace.impl.ts} +7 -7
- package/src/storages/{workspace.ts → workspaces/workspace.ts} +3 -3
- package/src/storages/{workspaces.impl.ts → workspaces/workspaces.impl.ts} +11 -11
- package/src/storages/{workspaces.ts → workspaces/workspaces.ts} +2 -2
- package/test/chats.test.ts +48 -0
- package/test/organization.test.ts +13 -1
- package/test/setup.ts +7 -0
- package/docs/enums/ChatAnswer.md +0 -22
- package/src/storages/chat.ts +0 -21
- package/src/storages/chats.ts +0 -17
- package/src/storages/groups.ts +0 -43
- /package/src/storages/{filesPage.ts → files/filesPage.ts} +0 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
[@neuralinnovations/dataisland-sdk - v0.0.1-dev9](../../README.md) / [Exports](../modules.md) / ChatAnswerType
|
2
|
+
|
3
|
+
# Enumeration: ChatAnswerType
|
4
|
+
|
5
|
+
## Table of contents
|
6
|
+
|
7
|
+
### Enumeration Members
|
8
|
+
|
9
|
+
- [LONG](ChatAnswerType.md#long)
|
10
|
+
- [SHORT](ChatAnswerType.md#short)
|
11
|
+
|
12
|
+
## Enumeration Members
|
13
|
+
|
14
|
+
### LONG
|
15
|
+
|
16
|
+
• **LONG** = ``"long"``
|
17
|
+
|
18
|
+
___
|
19
|
+
|
20
|
+
### SHORT
|
21
|
+
|
22
|
+
• **SHORT** = ``"short"``
|
package/docs/enums/ChatsEvent.md
CHANGED
package/docs/enums/FilesEvent.md
CHANGED
package/docs/enums/GroupEvent.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
[@neuralinnovations/dataisland-sdk - v0.0.1-
|
1
|
+
[@neuralinnovations/dataisland-sdk - v0.0.1-dev9](../../README.md) / [Exports](../modules.md) / GroupEvent
|
2
2
|
|
3
3
|
# Enumeration: GroupEvent
|
4
4
|
|
5
|
+
Group event.
|
6
|
+
|
5
7
|
## Table of contents
|
6
8
|
|
7
9
|
### Enumeration Members
|
package/docs/enums/UserEvent.md
CHANGED
package/docs/interfaces/Event.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[@neuralinnovations/dataisland-sdk - v0.0.1-
|
1
|
+
[@neuralinnovations/dataisland-sdk - v0.0.1-dev9](../../README.md) / [Exports](../modules.md) / EventSubscriber
|
2
2
|
|
3
3
|
# Interface: EventSubscriber\<EventType, DataType\>
|
4
4
|
|
package/docs/interfaces/Input.md
CHANGED
package/docs/modules.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
[@neuralinnovations/dataisland-sdk - v0.0.1-
|
1
|
+
[@neuralinnovations/dataisland-sdk - v0.0.1-dev9](../README.md) / Exports
|
2
2
|
|
3
|
-
# @neuralinnovations/dataisland-sdk - v0.0.1-
|
3
|
+
# @neuralinnovations/dataisland-sdk - v0.0.1-dev9
|
4
4
|
|
5
5
|
## Table of contents
|
6
6
|
|
7
7
|
### Enumerations
|
8
8
|
|
9
|
-
- [
|
9
|
+
- [ChatAnswerType](enums/ChatAnswerType.md)
|
10
10
|
- [ChatsEvent](enums/ChatsEvent.md)
|
11
11
|
- [FilesEvent](enums/FilesEvent.md)
|
12
12
|
- [GroupEvent](enums/GroupEvent.md)
|
@@ -86,6 +86,8 @@ ___
|
|
86
86
|
|
87
87
|
Ƭ **GroupId**: `string`
|
88
88
|
|
89
|
+
Group id.
|
90
|
+
|
89
91
|
___
|
90
92
|
|
91
93
|
### OrganizationId
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@neuralinnovations/dataisland-sdk",
|
3
|
-
"version": "0.0.1-
|
3
|
+
"version": "0.0.1-dev9",
|
4
4
|
"description": "SDK for DataIsland project",
|
5
5
|
"licenses": [
|
6
6
|
{
|
@@ -8,12 +8,16 @@
|
|
8
8
|
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
9
9
|
}
|
10
10
|
],
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "https://github.com/NeuralInnovations/dataisland-client-js-sdk.git"
|
14
|
+
},
|
11
15
|
"publishConfig": {
|
12
16
|
"access": "public"
|
13
17
|
},
|
14
18
|
"scripts": {
|
15
19
|
"build": "tsc",
|
16
|
-
"test": "jest",
|
20
|
+
"test": "jest --runInBand",
|
17
21
|
"lint": "eslint --ext .ts,.tsx src test",
|
18
22
|
"lint:fix": "eslint --fix --ext .ts,.tsx src test",
|
19
23
|
"docs": "typedoc --disableSources --includeVersion --plugin typedoc-plugin-markdown --out docs src/index.ts && node scripts/docs/index.js"
|
package/src/dataIslandApp.ts
CHANGED
@@ -2,8 +2,8 @@ import type { Lifetime } from "./disposable"
|
|
2
2
|
import type { CredentialBase } from "./credentials"
|
3
3
|
import { Context } from "./context"
|
4
4
|
import type { Constructor } from "./internal/registry"
|
5
|
-
import { Organizations } from "./storages/organizations"
|
6
|
-
import { UserProfile } from "./storages/userProfile"
|
5
|
+
import { Organizations } from "./storages/organizations/organizations"
|
6
|
+
import { UserProfile } from "./storages/user/userProfile"
|
7
7
|
|
8
8
|
/**
|
9
9
|
* DataIsland App instance.
|
package/src/dto/chatResponse.ts
CHANGED
@@ -1,88 +1,87 @@
|
|
1
|
-
|
2
1
|
export interface SourceDto {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
id: string;
|
3
|
+
name: string;
|
4
|
+
url: string;
|
5
|
+
content: string;
|
6
|
+
page: number;
|
8
7
|
}
|
9
8
|
|
10
9
|
export interface AnswerDto {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
id: string;
|
11
|
+
chatId: string;
|
12
|
+
question: string;
|
13
|
+
context: string;
|
14
|
+
sources: SourceDto[];
|
15
|
+
timestamp: number;
|
17
16
|
}
|
18
17
|
|
19
18
|
export interface ChatDto {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
id: string;
|
20
|
+
name: string;
|
21
|
+
createdAt: number;
|
22
|
+
modifiedAt: number;
|
23
|
+
userId: string;
|
24
|
+
organizationId: string;
|
25
|
+
workspaceId: string;
|
26
|
+
answers: AnswerDto[];
|
28
27
|
}
|
29
28
|
|
30
29
|
export interface ChatListResponse {
|
31
|
-
|
30
|
+
chats: ChatDto[]
|
32
31
|
}
|
33
32
|
|
34
33
|
export enum AnswerStatus {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
RUNNING = 0,
|
35
|
+
SUCCESS = 1,
|
36
|
+
CANCELED = 2,
|
37
|
+
FAIL = 3,
|
39
38
|
}
|
40
39
|
|
41
|
-
export interface AnswerStepDto{
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
export interface AnswerStepDto {
|
41
|
+
id: string;
|
42
|
+
type: StepType;
|
43
|
+
status: StepStatus;
|
44
|
+
start_at: string;
|
45
|
+
end_at: string;
|
46
|
+
tokens: string[];
|
47
|
+
sources: SourceDto[];
|
49
48
|
}
|
50
49
|
|
51
50
|
export interface FetchAnswerResponse {
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
id: string;
|
52
|
+
status: AnswerStatus;
|
53
|
+
steps: AnswerStepDto[];
|
55
54
|
}
|
56
55
|
|
57
56
|
export interface FetchTokensResponse {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
id: string;
|
58
|
+
step_id: string;
|
59
|
+
step_status: number;
|
60
|
+
step_tokens: string[];
|
62
61
|
}
|
63
62
|
|
64
63
|
export interface AnswerSourcesResponse {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
chat_uid: string;
|
65
|
+
uid: string;
|
66
|
+
step_id: string;
|
67
|
+
sources: SourceDto[];
|
69
68
|
}
|
70
69
|
|
71
70
|
export enum StepStatus {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
RUNNING = 0,
|
72
|
+
SUCCESS = 1,
|
73
|
+
FAIL = 2,
|
74
|
+
CANCELED = 3,
|
76
75
|
}
|
77
76
|
|
78
77
|
export enum StepType {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
PREPARE = 0,
|
79
|
+
SOURCES = 1,
|
80
|
+
GENERATE_ANSWER = 6,
|
81
|
+
FINALIZE_RESULT = 9,
|
82
|
+
DONE = 10,
|
84
83
|
}
|
85
|
-
|
84
|
+
|
86
85
|
export class StepTypeInfo {
|
87
86
|
public static hasTokens(type: StepType): boolean {
|
88
87
|
switch (type) {
|
@@ -101,4 +100,4 @@ export class StepTypeInfo {
|
|
101
100
|
}
|
102
101
|
return false
|
103
102
|
}
|
104
|
-
}
|
103
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { WorkspaceId } from "../storages/workspaces"
|
2
|
-
import { FileId } from "../storages/file"
|
1
|
+
import { WorkspaceId } from "../storages/workspaces/workspaces"
|
2
|
+
import { FileId } from "../storages/files/file"
|
3
3
|
|
4
4
|
export interface WorkspaceProfileDto {
|
5
5
|
name: string
|
package/src/index.ts
CHANGED
@@ -7,17 +7,17 @@ export * from "./events"
|
|
7
7
|
export * from "./disposable"
|
8
8
|
export * from "./credentials"
|
9
9
|
export * from "./dataIslandApp"
|
10
|
-
export * from "./storages/organizations"
|
11
|
-
export * from "./storages/organization"
|
12
|
-
export * from "./storages/workspaces"
|
13
|
-
export * from "./storages/workspace"
|
14
|
-
export * from "./storages/groups"
|
15
|
-
export * from "./storages/userProfile"
|
16
|
-
export * from "./storages/files"
|
17
|
-
export * from "./storages/file"
|
18
|
-
export * from "./storages/filesPage"
|
19
|
-
export * from "./storages/chats"
|
20
|
-
export * from "./storages/chat"
|
10
|
+
export * from "./storages/organizations/organizations"
|
11
|
+
export * from "./storages/organizations/organization"
|
12
|
+
export * from "./storages/workspaces/workspaces"
|
13
|
+
export * from "./storages/workspaces/workspace"
|
14
|
+
export * from "./storages/groups/groups"
|
15
|
+
export * from "./storages/user/userProfile"
|
16
|
+
export * from "./storages/files/files"
|
17
|
+
export * from "./storages/files/file"
|
18
|
+
export * from "./storages/files/filesPage"
|
19
|
+
export * from "./storages/chats/chats"
|
20
|
+
export * from "./storages/chats/chat"
|
21
21
|
|
22
22
|
const _appsNotReady = new Map<string, Promise<DataIslandApp>>()
|
23
23
|
const _appsReady = new Map<string, DataIslandApp>()
|
@@ -88,5 +88,5 @@ export async function dataIslandApp(
|
|
88
88
|
return await appPromise
|
89
89
|
}
|
90
90
|
|
91
|
-
export { File } from "./storages/file"
|
92
|
-
export { FilesPage } from "./storages/filesPage"
|
91
|
+
export { File } from "./storages/files/file"
|
92
|
+
export { FilesPage } from "./storages/files/filesPage"
|
package/src/internal/app.impl.ts
CHANGED
@@ -17,8 +17,8 @@ import {
|
|
17
17
|
} from "../commands/startCommandHandler"
|
18
18
|
import { UserProfileService } from "../services/userProfileService"
|
19
19
|
import { OrganizationService } from "../services/organizationService"
|
20
|
-
import { Organizations } from "../storages/organizations"
|
21
|
-
import { UserProfile } from "../storages/userProfile"
|
20
|
+
import { Organizations } from "../storages/organizations/organizations"
|
21
|
+
import { UserProfile } from "../storages/user/userProfile"
|
22
22
|
import { isUnitTest, UnitTest } from "../unitTest"
|
23
23
|
|
24
24
|
export class DataIslandAppImpl extends DataIslandApp {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Service } from "./service"
|
2
|
-
import { Organizations } from "../storages/organizations"
|
2
|
+
import { Organizations } from "../storages/organizations/organizations"
|
3
3
|
import { OrganizationDto, UserSettings } from "../dto/userInfoResponse"
|
4
|
-
import { OrganizationsImpl } from "../storages/organizations.impl"
|
4
|
+
import { OrganizationsImpl } from "../storages/organizations/organizations.impl"
|
5
5
|
|
6
6
|
export class OrganizationService extends Service {
|
7
7
|
private _impl?: OrganizationsImpl
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Service } from "./service"
|
2
2
|
import { RpcService } from "./rpcService"
|
3
|
-
import { UserProfile } from "../storages/userProfile"
|
3
|
+
import { UserProfile } from "../storages/user/userProfile"
|
4
4
|
import { UserInfoResponse } from "../dto/userInfoResponse"
|
5
5
|
import { OrganizationService } from "./organizationService"
|
6
|
-
import { UserProfileImpl } from "../storages/userProfile.impl"
|
6
|
+
import { UserProfileImpl } from "../storages/user/userProfile.impl"
|
7
7
|
import { ResponseUtils } from "./responseUtils"
|
8
8
|
|
9
9
|
export class UserProfileService extends Service {
|
@@ -0,0 +1,163 @@
|
|
1
|
+
import { Context } from "../../context"
|
2
|
+
import {
|
3
|
+
AnswerDto,
|
4
|
+
AnswerStatus,
|
5
|
+
AnswerStepDto,
|
6
|
+
FetchAnswerResponse,
|
7
|
+
FetchTokensResponse,
|
8
|
+
SourceDto,
|
9
|
+
StepType
|
10
|
+
} from "../../dto/chatResponse"
|
11
|
+
import { ResponseUtils } from "../../services/responseUtils"
|
12
|
+
import { RpcService } from "../../services/rpcService"
|
13
|
+
import { Answer, AnswerId } from "./answer"
|
14
|
+
import { Chat } from "./chat"
|
15
|
+
|
16
|
+
export class AnswerImpl extends Answer {
|
17
|
+
private _content?: AnswerDto
|
18
|
+
|
19
|
+
private _steps?: AnswerStepDto[]
|
20
|
+
private _status?: AnswerStatus
|
21
|
+
private _id?: AnswerId
|
22
|
+
|
23
|
+
constructor(
|
24
|
+
private readonly chat: Chat,
|
25
|
+
private readonly context: Context) {
|
26
|
+
super()
|
27
|
+
}
|
28
|
+
|
29
|
+
async initFromData(answer: AnswerDto): Promise<AnswerImpl> {
|
30
|
+
this._content = answer
|
31
|
+
this._id = answer.id
|
32
|
+
|
33
|
+
// fetch answer
|
34
|
+
await this.fetch()
|
35
|
+
|
36
|
+
return this
|
37
|
+
}
|
38
|
+
|
39
|
+
async initFromId(id: AnswerId): Promise<AnswerImpl> {
|
40
|
+
this._id = id
|
41
|
+
|
42
|
+
// fetch answer
|
43
|
+
await this.fetch()
|
44
|
+
|
45
|
+
return this
|
46
|
+
}
|
47
|
+
|
48
|
+
get id(): string {
|
49
|
+
return <string>this._id
|
50
|
+
}
|
51
|
+
|
52
|
+
get status(): AnswerStatus {
|
53
|
+
return <AnswerStatus>this._status
|
54
|
+
}
|
55
|
+
|
56
|
+
private getStep(type: StepType): AnswerStepDto | undefined {
|
57
|
+
return this._steps?.find(step => step.type === type)
|
58
|
+
}
|
59
|
+
|
60
|
+
async sources(type: StepType): Promise<SourceDto[]> {
|
61
|
+
// fetch answer
|
62
|
+
await this.fetch()
|
63
|
+
// get step
|
64
|
+
const step = this.getStep(type)
|
65
|
+
|
66
|
+
// check step
|
67
|
+
if (!step) {
|
68
|
+
throw new Error(`Step with type ${type.toString()} is not found, answer: ${this.id}, organization: ${this.chat.organization.id}`)
|
69
|
+
}
|
70
|
+
|
71
|
+
// get sources
|
72
|
+
const response = await this.context
|
73
|
+
.resolve(RpcService)
|
74
|
+
?.requestBuilder("api/v1/Chats/answer/sources")
|
75
|
+
.searchParam("chat_uid", this.chat.id)
|
76
|
+
.searchParam("uid", this.id)
|
77
|
+
.searchParam("step_id", step.id)
|
78
|
+
.sendGet()
|
79
|
+
|
80
|
+
// check response status
|
81
|
+
if (ResponseUtils.isFail(response)) {
|
82
|
+
await ResponseUtils.throwError(`Failed to get sources for ${type.toString()}, answer: ${this.id}, organization: ${this.chat.organization.id}`, response)
|
83
|
+
}
|
84
|
+
|
85
|
+
// parse sources from the server's response
|
86
|
+
const sources = (await response!.json()).sources as SourceDto[]
|
87
|
+
|
88
|
+
return sources
|
89
|
+
}
|
90
|
+
|
91
|
+
async fetch(): Promise<void> {
|
92
|
+
// fetch answer from position 0
|
93
|
+
const position = 0
|
94
|
+
// fetch answer
|
95
|
+
const response = await this.context
|
96
|
+
.resolve(RpcService)
|
97
|
+
?.requestBuilder("api/v1/Chats/answer/fetch")
|
98
|
+
.searchParam("chatId", this.chat.id)
|
99
|
+
.searchParam("questionId", this.id)
|
100
|
+
.searchParam("position", position.toString())
|
101
|
+
.sendGet()
|
102
|
+
|
103
|
+
// check response status
|
104
|
+
if (ResponseUtils.isFail(response)) {
|
105
|
+
await ResponseUtils.throwError(`Failed to fetch answer ${this.id}`, response)
|
106
|
+
}
|
107
|
+
|
108
|
+
// parse answer from the server's response
|
109
|
+
const answer = (await response!.json()) as FetchAnswerResponse
|
110
|
+
|
111
|
+
// update answer
|
112
|
+
this._status = <AnswerStatus>answer.status
|
113
|
+
this._steps = <AnswerStepDto[]>answer.steps
|
114
|
+
}
|
115
|
+
|
116
|
+
async fetchTokens(type: StepType, token_start_at: number): Promise<FetchTokensResponse> {
|
117
|
+
// fetch answer
|
118
|
+
await this.fetch()
|
119
|
+
// get step
|
120
|
+
const step = this.getStep(type)
|
121
|
+
|
122
|
+
// check step
|
123
|
+
if (!step) {
|
124
|
+
throw new Error(`Step with type ${type.toString()} is not found`)
|
125
|
+
}
|
126
|
+
|
127
|
+
// get tokens
|
128
|
+
const response = await this.context
|
129
|
+
.resolve(RpcService)
|
130
|
+
?.requestBuilder("api/v1/Chats/answer/fetch/tokens")
|
131
|
+
.searchParam("chat_uid", this.chat.id)
|
132
|
+
.searchParam("uid", this.id)
|
133
|
+
.searchParam("step_id", step.id)
|
134
|
+
.searchParam("token_start_at", token_start_at.toString())
|
135
|
+
.sendGet()
|
136
|
+
|
137
|
+
// check response status
|
138
|
+
if (ResponseUtils.isFail(response)) {
|
139
|
+
await ResponseUtils.throwError(`Failed to get sources for ${type.toString()}`, response)
|
140
|
+
}
|
141
|
+
|
142
|
+
// parse tokens from the server's response
|
143
|
+
const tokens = (await response!.json()) as FetchTokensResponse
|
144
|
+
|
145
|
+
return tokens
|
146
|
+
}
|
147
|
+
|
148
|
+
async cancel(): Promise<void> {
|
149
|
+
// send request to the server
|
150
|
+
const response = await this.context
|
151
|
+
.resolve(RpcService)
|
152
|
+
?.requestBuilder("api/v1/Chats/answer/cancel")
|
153
|
+
.sendPutJson({
|
154
|
+
chat_id: this.chat.id,
|
155
|
+
uid: this.id
|
156
|
+
})
|
157
|
+
|
158
|
+
// check response status
|
159
|
+
if (ResponseUtils.isFail(response)) {
|
160
|
+
await ResponseUtils.throwError("Failed to cancel a question", response)
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import {
|
2
|
+
AnswerStatus,
|
3
|
+
FetchTokensResponse,
|
4
|
+
SourceDto,
|
5
|
+
StepType
|
6
|
+
} from "../../dto/chatResponse"
|
7
|
+
|
8
|
+
export type AnswerId = string
|
9
|
+
export type StepId = string
|
10
|
+
|
11
|
+
export abstract class Answer {
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Answer id.
|
15
|
+
*/
|
16
|
+
abstract get id(): AnswerId
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Answer status.
|
20
|
+
*/
|
21
|
+
abstract get status(): AnswerStatus
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Answer sources.
|
25
|
+
*/
|
26
|
+
abstract sources(type: StepType): Promise<SourceDto[]>
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Fetch answer.
|
30
|
+
*/
|
31
|
+
abstract fetch(): Promise<void>
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Fetch answer.
|
35
|
+
*/
|
36
|
+
abstract fetchTokens(type: StepType, tokenStartAt: number): Promise<FetchTokensResponse>
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Cancel answer
|
40
|
+
*/
|
41
|
+
abstract cancel(): Promise<void>
|
42
|
+
}
|