@stack-spot/portal-network 0.138.0 → 0.139.0

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.
@@ -1,21 +1,22 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import
3
- {
2
+ import {
4
3
  addFavoriteV1KnowledgeSourcesSlugFavoritePost,
5
4
  defaults,
6
5
  deleteFavoriteV1KnowledgeSourcesSlugFavoriteDelete,
6
+ FileUploadType,
7
7
  getFileUploadStatusV1FileUploadFileUploadIdGet,
8
8
  getUploadFormV2V2FileUploadFormPost,
9
9
  listKsV1KnowledgeSourcesGet,
10
- saveChunkedFilesV1FileUploadFileUploadIdPost,
10
+ saveChunkedFilesV1FileUploadFileUploadIdKnowledgeObjectsPost,
11
11
  splitUploadedFileV1FileUploadFileUploadIdSplitPost,
12
12
  } from '../api/dataIntegration'
13
13
  import apis from '../apis.json'
14
14
  import { DefaultAPIError } from '../error/DefaultAPIError'
15
+ import { baseDictionary } from '../error/dictionary/base'
16
+ import { FileUploadError } from '../error/FileUploadError'
15
17
  import { StackspotAPIError } from '../error/StackspotAPIError'
16
18
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
17
19
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
18
- import { baseDictionary } from '../error/dictionary/base'
19
20
 
20
21
  class DataIntegrationClient extends ReactQueryNetworkClient {
21
22
  constructor() {
@@ -36,7 +37,7 @@ class DataIntegrationClient extends ReactQueryNetworkClient {
36
37
  /**
37
38
  * Save the splitted knowledge objects
38
39
  */
39
- saveKnowledgeObjects = this.mutation(removeAuthorizationParam(saveChunkedFilesV1FileUploadFileUploadIdPost))
40
+ saveKnowledgeObjects = this.mutation(removeAuthorizationParam(saveChunkedFilesV1FileUploadFileUploadIdKnowledgeObjectsPost))
40
41
  /**
41
42
  * Splits the file with the passed settings
42
43
  */
@@ -70,7 +71,29 @@ class DataIntegrationClient extends ReactQueryNetworkClient {
70
71
  /**
71
72
  * Removes the resource of type Knowledge Source from the list of favorites.
72
73
  */
73
- removeFavoriteKnowledgeSource = this.mutation(removeAuthorizationParam(deleteFavoriteV1KnowledgeSourcesSlugFavoriteDelete))
74
+ removeFavoriteKnowledgeSource = this.mutation(removeAuthorizationParam(deleteFavoriteV1KnowledgeSourcesSlugFavoriteDelete))
75
+
76
+ uploadFiles = this.mutation({
77
+ name: 'uploadFiles',
78
+ request: (abortSignal, params: { files: File[], type: FileUploadType }) => Promise.all(params.files.map(async (f) => {
79
+ try {
80
+ const { id, url, form } = await getUploadFormV2V2FileUploadFormPost({
81
+ authorization: '',
82
+ newFileUploadRequest: { file_name: f.name, target_type: params.type, target_id: '' },
83
+ }, { signal: abortSignal })
84
+ const formData = new FormData()
85
+ Object.entries(form).forEach(([key, value]) => {
86
+ formData.append(key, value)
87
+ })
88
+ formData.append('file', f)
89
+ const response = await fetch(url, { method: 'post', body: formData, signal: abortSignal })
90
+ if (!response.ok) throw new StackspotAPIError({ status: response.status, headers: response.headers, message: 'Failed to upload' })
91
+ return id
92
+ } catch (e: any) {
93
+ throw new FileUploadError(f.name, e)
94
+ }
95
+ })),
96
+ })
74
97
  }
75
98
 
76
99
  export const dataIntegrationClient = new DataIntegrationClient()
@@ -184,6 +184,7 @@ export interface FixedChatRequest extends ChatRequest {
184
184
  platform_version?: string,
185
185
  stackspot_ai_version?: string,
186
186
  os?: string,
187
+ upload_ids?: string[],
187
188
  },
188
189
  }
189
190
 
@@ -0,0 +1,18 @@
1
+ import { HttpValidationError } from '../api/ai'
2
+ import { StackspotAPIError } from './StackspotAPIError'
3
+
4
+ export class FileUploadError extends StackspotAPIError {
5
+ readonly fileName: string
6
+
7
+ constructor(fileName: string, error: any) {
8
+ super({
9
+ status: error.status,
10
+ headers: error.headers,
11
+ stack: error.stack,
12
+ message: error instanceof StackspotAPIError
13
+ ? error.message
14
+ : (error.data as HttpValidationError | undefined)?.detail?.map(d => d.msg)?.join('\n'),
15
+ })
16
+ this.fileName = fileName
17
+ }
18
+ }
package/src/index.ts CHANGED
@@ -13,13 +13,13 @@ export { cloudServicesClient } from './client/cloud-services'
13
13
  export { codeShiftClient } from './client/code-shift'
14
14
  export { contentClient } from './client/content'
15
15
  export { dataIntegrationClient } from './client/data-integration'
16
+ export { discoveryClient } from './client/discovery'
16
17
  export { eventBusClient } from './client/event-bus'
17
18
  export { genAiInferenceClient } from './client/gen-ai-inference'
18
19
  export { insightsClient } from './client/insights'
19
20
  export { notificationClient } from './client/notification'
20
21
  export { runtimeManagerClient } from './client/runtime-manager'
21
22
  export { secretsClient } from './client/secrets'
22
- export { discoveryClient } from './client/discovery'
23
23
  export * from './client/types'
24
24
  export { workflowClient } from './client/workflow'
25
25
  export { workspaceClient } from './client/workspace'
@@ -27,6 +27,7 @@ export { workspaceAiClient } from './client/workspace-ai'
27
27
  export { workspaceManagerClient } from './client/workspace-manager'
28
28
  export { workspaceSearchClient } from './client/workspace-search'
29
29
  export { DefaultAPIError } from './error/DefaultAPIError'
30
+ export { FileUploadError } from './error/FileUploadError'
30
31
  export { StackspotAPIError } from './error/StackspotAPIError'
31
32
  export { StreamCanceledError } from './error/StreamCanceledError'
32
33
  export { StreamError } from './error/StreamError'