@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.
Files changed (76) hide show
  1. package/.github/workflows/publish-npm.yml +11 -0
  2. package/.github/workflows/tests.yml +4 -0
  3. package/.github/workflows/version.yml +5 -1
  4. package/README.md +36 -3
  5. package/docs/classes/BasicCredential.md +1 -1
  6. package/docs/classes/BearerCredential.md +1 -1
  7. package/docs/classes/Chat.md +34 -6
  8. package/docs/classes/Chats.md +87 -1
  9. package/docs/classes/CredentialBase.md +1 -1
  10. package/docs/classes/DataIslandApp.md +1 -1
  11. package/docs/classes/DebugCredential.md +1 -1
  12. package/docs/classes/DefaultCredential.md +1 -1
  13. package/docs/classes/DisposableContainer.md +1 -1
  14. package/docs/classes/EventDispatcher.md +1 -1
  15. package/docs/classes/File.md +1 -1
  16. package/docs/classes/Files.md +2 -2
  17. package/docs/classes/FilesPage.md +1 -1
  18. package/docs/classes/Group.md +19 -1
  19. package/docs/classes/Groups.md +27 -3
  20. package/docs/classes/Lifetime.md +1 -1
  21. package/docs/classes/Organization.md +37 -1
  22. package/docs/classes/Organizations.md +1 -1
  23. package/docs/classes/UserProfile.md +1 -1
  24. package/docs/classes/Workspace.md +1 -1
  25. package/docs/classes/Workspaces.md +6 -2
  26. package/docs/enums/ChatAnswerType.md +22 -0
  27. package/docs/enums/ChatsEvent.md +1 -1
  28. package/docs/enums/FilesEvent.md +1 -1
  29. package/docs/enums/GroupEvent.md +3 -1
  30. package/docs/enums/OrganizationsEvent.md +1 -1
  31. package/docs/enums/UserEvent.md +1 -1
  32. package/docs/enums/WorkspaceEvent.md +1 -1
  33. package/docs/enums/WorkspacesEvent.md +1 -1
  34. package/docs/interfaces/Disposable.md +1 -1
  35. package/docs/interfaces/Event.md +1 -1
  36. package/docs/interfaces/EventSubscriber.md +1 -1
  37. package/docs/interfaces/Input.md +1 -1
  38. package/docs/modules.md +5 -3
  39. package/package.json +6 -2
  40. package/src/dataIslandApp.ts +2 -2
  41. package/src/dto/chatResponse.ts +54 -55
  42. package/src/dto/workspacesResponse.ts +2 -2
  43. package/src/index.ts +13 -13
  44. package/src/internal/app.impl.ts +2 -2
  45. package/src/services/organizationService.ts +2 -2
  46. package/src/services/userProfileService.ts +2 -2
  47. package/src/storages/chats/answer.impl.ts +163 -0
  48. package/src/storages/chats/answer.ts +42 -0
  49. package/src/storages/chats/chat.impl.ts +87 -0
  50. package/src/storages/chats/chat.ts +38 -0
  51. package/src/storages/chats/chats.impl.ts +142 -0
  52. package/src/storages/chats/chats.ts +47 -0
  53. package/src/storages/{file.impl.ts → files/file.impl.ts} +5 -5
  54. package/src/storages/{file.ts → files/file.ts} +1 -1
  55. package/src/storages/{files.impl.ts → files/files.impl.ts} +6 -6
  56. package/src/storages/{files.ts → files/files.ts} +2 -2
  57. package/src/storages/{groups.impl.ts → groups/groups.impl.ts} +86 -97
  58. package/src/storages/groups/groups.ts +101 -0
  59. package/src/storages/{organization.impl.ts → organizations/organization.impl.ts} +34 -7
  60. package/src/storages/{organization.ts → organizations/organization.ts} +13 -2
  61. package/src/storages/{organizations.impl.ts → organizations/organizations.impl.ts} +10 -4
  62. package/src/storages/{organizations.ts → organizations/organizations.ts} +1 -1
  63. package/src/storages/{userProfile.impl.ts → user/userProfile.impl.ts} +1 -1
  64. package/src/storages/{userProfile.ts → user/userProfile.ts} +1 -1
  65. package/src/storages/{workspace.impl.ts → workspaces/workspace.impl.ts} +7 -7
  66. package/src/storages/{workspace.ts → workspaces/workspace.ts} +3 -3
  67. package/src/storages/{workspaces.impl.ts → workspaces/workspaces.impl.ts} +11 -11
  68. package/src/storages/{workspaces.ts → workspaces/workspaces.ts} +2 -2
  69. package/test/chats.test.ts +48 -0
  70. package/test/organization.test.ts +13 -1
  71. package/test/setup.ts +7 -0
  72. package/docs/enums/ChatAnswer.md +0 -22
  73. package/src/storages/chat.ts +0 -21
  74. package/src/storages/chats.ts +0 -17
  75. package/src/storages/groups.ts +0 -43
  76. /package/src/storages/{filesPage.ts → files/filesPage.ts} +0 -0
@@ -0,0 +1,87 @@
1
+ import { Chat, ChatAnswerType } from "./chat"
2
+ import { Disposable } from "../../disposable"
3
+ import { Answer } from "./answer"
4
+ import { ChatDto } from "../../dto/chatResponse"
5
+ import { Context } from "../../context"
6
+ import { AnswerImpl } from "./answer.impl"
7
+ import { RpcService } from "../../services/rpcService"
8
+ import { ResponseUtils } from "../../services/responseUtils"
9
+ import { Organization } from "../organizations/organization"
10
+
11
+ export class ChatImpl extends Chat implements Disposable {
12
+ private _isDisposed: boolean = false
13
+ private readonly _answers: Answer[] = []
14
+
15
+ private _content?: ChatDto
16
+
17
+ constructor(
18
+ private readonly context: Context,
19
+ public readonly organization: Organization
20
+ ) {
21
+ super()
22
+ }
23
+
24
+ async initFrom(chat: ChatDto): Promise<ChatImpl> {
25
+ this._content = chat
26
+
27
+ // init answers
28
+ for (const ans of chat.answers) {
29
+ // create answer implementation
30
+ const answer = await new AnswerImpl(this, this.context).initFromData(ans)
31
+
32
+ // add answer to the collection
33
+ this._answers.push(answer)
34
+ }
35
+
36
+ return this
37
+ }
38
+
39
+ get id(): string {
40
+ return <string>this._content?.id
41
+ }
42
+
43
+ get name(): string {
44
+ return <string>this._content?.name
45
+ }
46
+
47
+ get collection(): readonly Answer[] {
48
+ return this._answers
49
+ }
50
+
51
+ get isDisposed(): boolean {
52
+ return this._isDisposed
53
+ }
54
+
55
+ async ask(message: string, answerType: ChatAnswerType): Promise<Answer> {
56
+ // send request to the server
57
+ const response = await this.context
58
+ .resolve(RpcService)
59
+ ?.requestBuilder("api/v1/Chats/question")
60
+ .sendPutJson({
61
+ chatId: this.id,
62
+ questionMessage: message,
63
+ isLongAnswer: (answerType === ChatAnswerType.LONG)
64
+ })
65
+
66
+ // check response status
67
+ if (ResponseUtils.isFail(response)) {
68
+ await ResponseUtils.throwError(`Failed to ask a question, organization: ${this.organization.id}`, response)
69
+ }
70
+
71
+ // parse answer id from the server's response
72
+ const id = (await response!.json()).id
73
+
74
+ // create answer implementation
75
+ const answer = await new AnswerImpl(this, this.context).initFromId(id)
76
+
77
+ // add answer to the collection
78
+ this._answers.push(answer)
79
+
80
+ return answer
81
+ }
82
+
83
+ dispose(): void {
84
+ this._isDisposed = true
85
+ }
86
+
87
+ }
@@ -0,0 +1,38 @@
1
+ import { Answer } from "./answer"
2
+ import { Organization } from "../organizations/organization"
3
+
4
+ export type ChatId = string
5
+
6
+ export enum ChatAnswerType {
7
+ SHORT = "short",
8
+ LONG = "long"
9
+ }
10
+
11
+ export abstract class Chat {
12
+
13
+ /**
14
+ * Organization.
15
+ */
16
+ abstract get organization(): Organization
17
+
18
+ /**
19
+ * Chat id.
20
+ */
21
+ abstract get id(): ChatId
22
+
23
+ /**
24
+ * Chat name.
25
+ */
26
+ abstract get name(): string
27
+
28
+ /**
29
+ * Answers list.
30
+ */
31
+ abstract get collection(): ReadonlyArray<Answer>
32
+
33
+ /**
34
+ * Ask new question in chat.
35
+ */
36
+ abstract ask(message: string, answerType: ChatAnswerType): Promise<Answer>
37
+ }
38
+
@@ -0,0 +1,142 @@
1
+ import { Context } from "../../context"
2
+ import { ChatDto, ChatListResponse } from "../../dto/chatResponse"
3
+ import { ResponseUtils } from "../../services/responseUtils"
4
+ import { RpcService } from "../../services/rpcService"
5
+ import { OrganizationImpl } from "../organizations/organization.impl"
6
+ import { OrganizationId } from "../organizations/organizations"
7
+ import { Chat } from "./chat"
8
+ import { ChatImpl } from "./chat.impl"
9
+ import { Chats, ChatsEvent } from "./chats"
10
+
11
+ export class ChatsImpl extends Chats {
12
+ private readonly _chats: Chat[] = []
13
+
14
+ constructor(
15
+ public readonly organization: OrganizationImpl,
16
+ private readonly context: Context
17
+ ) {
18
+ super()
19
+ }
20
+
21
+ async initFrom(organizationId: OrganizationId): Promise<void> {
22
+ // init chats from the server's response
23
+ const limit = 100
24
+ const page = 0
25
+ const response = await this.context
26
+ .resolve(RpcService)
27
+ ?.requestBuilder("api/v1/Chats/list")
28
+ .searchParam("organizationId", organizationId)
29
+ .searchParam("limit", limit.toString())
30
+ .searchParam("page", page.toString())
31
+ .sendGet()
32
+
33
+ // check response status
34
+ if (ResponseUtils.isFail(response)) {
35
+ await ResponseUtils.throwError(
36
+ `Chats list org id:${organizationId}, page:${page}, limit:${limit}, failed`,
37
+ response
38
+ )
39
+ }
40
+
41
+ // parse chats from the server's response
42
+ const chats = (await response!.json()) as ChatListResponse
43
+
44
+ // init chats
45
+ for (const cht of chats.chats) {
46
+ // create chat implementation
47
+ const chat = await new ChatImpl(this.context, this.organization).initFrom(cht)
48
+
49
+ // add chat to the collection
50
+ this._chats.push(chat)
51
+
52
+ // dispatch event
53
+ this.dispatch({
54
+ type: ChatsEvent.ADDED,
55
+ data: chat
56
+ })
57
+ }
58
+
59
+ }
60
+
61
+ get collection(): readonly Chat[] {
62
+ return this._chats
63
+ }
64
+
65
+ get(id: string): Chat {
66
+ return <Chat>this.tryGet(id)
67
+ }
68
+
69
+ tryGet(id: string): Chat | undefined {
70
+ return this._chats.find(chat => chat.id === id)
71
+ }
72
+
73
+ async create(): Promise<Chat> {
74
+
75
+ // send create request to the server
76
+ const response = await this.context
77
+ .resolve(RpcService)
78
+ ?.requestBuilder("api/v1/Chats")
79
+ .sendPostJson({ organizationId: this.organization.id })
80
+
81
+ // check response status
82
+ if (ResponseUtils.isFail(response)) {
83
+ await ResponseUtils.throwError(`Failed to create chat, organization: ${this.organization.id}`, response)
84
+ }
85
+
86
+ // parse workspace from the server's response
87
+ const content = (await response!.json()).chat as ChatDto
88
+
89
+ // create workspace implementation
90
+ const chat = new ChatImpl(this.context, this.organization)
91
+ await chat.initFrom(content)
92
+
93
+ // add chat to the collection
94
+ this._chats.push(chat)
95
+
96
+ // dispatch event
97
+ this.dispatch({
98
+ type: ChatsEvent.ADDED,
99
+ data: chat
100
+ })
101
+
102
+ return chat
103
+ }
104
+
105
+ async delete(id: string): Promise<void> {
106
+ // get chat by id
107
+ const chat = <ChatImpl>this.tryGet(id)
108
+
109
+ // check if chat is found
110
+ if (!chat) {
111
+ throw new Error(`Chat ${id} is not found, organization: ${this.organization.id}`)
112
+ }
113
+
114
+ // send delete request to the server
115
+ const response = await this.context
116
+ .resolve(RpcService)
117
+ ?.requestBuilder("api/v1/Chats")
118
+ .searchParam("id", id)
119
+ .sendDelete()
120
+
121
+ // check response status
122
+ if (ResponseUtils.isFail(response)) {
123
+ await ResponseUtils.throwError(
124
+ `Failed to delete chat: ${id}, organization: ${this.organization.id}`,
125
+ response
126
+ )
127
+ }
128
+
129
+ // remove chat from the collection
130
+ const index = this._chats.indexOf(<ChatImpl>chat)
131
+ if (index < 0) {
132
+ throw new Error(`Chat ${id} is not found, organization: ${this.organization.id}`)
133
+ }
134
+ this._chats.splice(index, 1)
135
+
136
+ // dispatch event
137
+ this.dispatch({
138
+ type: ChatsEvent.REMOVED,
139
+ data: chat
140
+ })
141
+ }
142
+ }
@@ -0,0 +1,47 @@
1
+ import { EventDispatcher } from "../../events"
2
+ import { Chat, ChatId } from "./chat"
3
+ import { Organization } from "../organizations/organization"
4
+
5
+ export enum ChatsEvent {
6
+ ADDED = "added",
7
+ REMOVED = "removed"
8
+ }
9
+
10
+ /**
11
+ * Chats storage.
12
+ */
13
+ export abstract class Chats extends EventDispatcher<ChatsEvent, Chat> {
14
+
15
+ /**
16
+ * Organization.
17
+ */
18
+ abstract get organization(): Organization
19
+
20
+ /**
21
+ * Chats list.
22
+ */
23
+ abstract get collection(): ReadonlyArray<Chat>
24
+
25
+ /**
26
+ * Create new chat.
27
+ */
28
+ abstract create(): Promise<Chat>
29
+
30
+ /**
31
+ * Get chat by id.
32
+ * @param id
33
+ */
34
+ abstract get(id: ChatId): Chat
35
+
36
+ /**
37
+ * Try to get chat by id.
38
+ * @param id
39
+ */
40
+ abstract tryGet(id: ChatId): Chat | undefined
41
+
42
+ /**
43
+ * Delete chat.
44
+ * @param id
45
+ */
46
+ abstract delete(id: ChatId): Promise<void>
47
+ }
@@ -1,8 +1,8 @@
1
- import { Context } from "../context"
2
- import { Disposable } from "../disposable"
3
- import { FileDto, FileProgressDto } from "../dto/workspacesResponse"
4
- import { RpcService } from "../services/rpcService"
5
- import { ResponseUtils } from "../services/responseUtils"
1
+ import { Context } from "../../context"
2
+ import { Disposable } from "../../disposable"
3
+ import { FileDto, FileProgressDto } from "../../dto/workspacesResponse"
4
+ import { RpcService } from "../../services/rpcService"
5
+ import { ResponseUtils } from "../../services/responseUtils"
6
6
  import { File } from "./file"
7
7
 
8
8
  export class FileImpl extends File implements Disposable {
@@ -1,4 +1,4 @@
1
- import { FileProgressDto } from "../dto/workspacesResponse"
1
+ import { FileProgressDto } from "../../dto/workspacesResponse"
2
2
 
3
3
  export type FileId = string
4
4
 
@@ -1,11 +1,11 @@
1
- import { Context } from "../context"
2
- import { Disposable } from "../disposable"
3
- import { FileDto, FileListResponse } from "../dto/workspacesResponse"
4
- import { RpcService } from "../services/rpcService"
1
+ import { Context } from "../../context"
2
+ import { Disposable } from "../../disposable"
3
+ import { FileDto, FileListResponse } from "../../dto/workspacesResponse"
4
+ import { RpcService } from "../../services/rpcService"
5
5
  import { FileImpl } from "./file.impl"
6
6
  import { Files, FilesEvent, UploadFile } from "./files"
7
- import { WorkspaceImpl } from "./workspace.impl"
8
- import { ResponseUtils } from "../services/responseUtils"
7
+ import { WorkspaceImpl } from "../workspaces/workspace.impl"
8
+ import { ResponseUtils } from "../../services/responseUtils"
9
9
  import { File } from "./file"
10
10
  import { FilesPage } from "./filesPage"
11
11
 
@@ -1,4 +1,4 @@
1
- import { EventDispatcher } from "../events"
1
+ import { EventDispatcher } from "../../events"
2
2
  import { File, FileId } from "./file"
3
3
  import { FilesPage } from "./filesPage"
4
4
 
@@ -20,7 +20,7 @@ export type UploadFile = globalThis.File
20
20
  */
21
21
  export abstract class Files extends EventDispatcher<FilesEvent, File> {
22
22
  /**
23
- * Get file by id.
23
+ * Upload file.
24
24
  */
25
25
  abstract upload(file: UploadFile): Promise<File>
26
26