@stack-spot/portal-network 0.138.1 → 0.139.1-beta.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/agent-tools.d.ts +178 -4
  3. package/dist/api/agent-tools.d.ts.map +1 -1
  4. package/dist/api/agent-tools.js +98 -2
  5. package/dist/api/agent-tools.js.map +1 -1
  6. package/dist/api/dataIntegration.d.ts +183 -179
  7. package/dist/api/dataIntegration.d.ts.map +1 -1
  8. package/dist/api/dataIntegration.js +166 -161
  9. package/dist/api/dataIntegration.js.map +1 -1
  10. package/dist/client/agent-tools.d.ts +77 -0
  11. package/dist/client/agent-tools.d.ts.map +1 -1
  12. package/dist/client/agent-tools.js +134 -1
  13. package/dist/client/agent-tools.js.map +1 -1
  14. package/dist/client/agent.d.ts +2 -49
  15. package/dist/client/agent.d.ts.map +1 -1
  16. package/dist/client/agent.js +0 -63
  17. package/dist/client/agent.js.map +1 -1
  18. package/dist/client/ai.d.ts +7 -0
  19. package/dist/client/ai.d.ts.map +1 -1
  20. package/dist/client/ai.js +10 -1
  21. package/dist/client/ai.js.map +1 -1
  22. package/dist/client/data-integration.d.ts +12 -14
  23. package/dist/client/data-integration.d.ts.map +1 -1
  24. package/dist/client/data-integration.js +33 -3
  25. package/dist/client/data-integration.js.map +1 -1
  26. package/dist/client/types.d.ts +6 -3
  27. package/dist/client/types.d.ts.map +1 -1
  28. package/dist/error/FileUploadError.d.ts +6 -0
  29. package/dist/error/FileUploadError.d.ts.map +1 -0
  30. package/dist/error/FileUploadError.js +21 -0
  31. package/dist/error/FileUploadError.js.map +1 -0
  32. package/dist/index.d.ts +2 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +2 -1
  35. package/dist/index.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/api/agent-tools.ts +306 -4
  38. package/src/api/dataIntegration.ts +327 -307
  39. package/src/client/agent-tools.ts +103 -1
  40. package/src/client/agent.ts +1 -67
  41. package/src/client/ai.ts +5 -0
  42. package/src/client/data-integration.ts +29 -6
  43. package/src/client/types.ts +8 -4
  44. package/src/error/FileUploadError.ts +18 -0
  45. package/src/index.ts +2 -1
@@ -1,8 +1,13 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { defaults, getPublicToolKitsV1BuiltinToolkitGet, HttpValidationError } from '../api/agent-tools'
2
+ import { addFavoriteV1AgentsAgentIdFavoritePost, AgentVisibilityLevelEnum, createAgentV1AgentsPost, defaults, deleteAgentV1AgentsAgentIdDelete, getAgentV1AgentsAgentIdGet, getPublicToolKitsV1BuiltinToolkitGet, HttpValidationError, listAgentsV1AgentsGet, publishAgentV1AgentsAgentIdPublishPost, searchAgentsV1AgentsSearchPost, updateAgentV1AgentsAgentIdPut, VisibilityLevelEnum } from '../api/agent-tools'
3
3
  import apis from '../apis.json'
4
4
  import { StackspotAPIError } from '../error/StackspotAPIError'
5
5
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
6
+ import { removeAuthorizationParam } from '../utils/remove-authorization-param'
7
+ import { AgentResponseWithBuiltIn, AgentVisibilityLevel } from './types'
8
+ import { workspaceAiClient } from './workspace-ai'
9
+
10
+ const AGENT_DEFAULT_SLUG = 'stk_code_buddy'
6
11
 
7
12
  class AgentToolsClient extends ReactQueryNetworkClient {
8
13
  constructor() {
@@ -19,6 +24,103 @@ class AgentToolsClient extends ReactQueryNetworkClient {
19
24
  }
20
25
 
21
26
  tools = this.query(getPublicToolKitsV1BuiltinToolkitGet)
27
+
28
+ /**
29
+ * Create agent
30
+ */
31
+ createAgent = this.mutation(removeAuthorizationParam(createAgentV1AgentsPost))
32
+
33
+ /**
34
+ * Delete agent
35
+ */
36
+ deleteAgent = this.mutation(deleteAgentV1AgentsAgentIdDelete)
37
+
38
+ /**
39
+ * Updates an agent
40
+ */
41
+ updateAgent = this.mutation(updateAgentV1AgentsAgentIdPut)
42
+
43
+ /**
44
+ * Favorite an agent
45
+ */
46
+ favoriteAgent = this.mutation(addFavoriteV1AgentsAgentIdFavoritePost)
47
+
48
+ /**
49
+ * Publish an agent
50
+ */
51
+ publishAgent = this.mutation(publishAgentV1AgentsAgentIdPublishPost)
52
+
53
+ /**
54
+ * List agents
55
+ */
56
+ agents = this.infiniteQuery(removeAuthorizationParam(listAgentsV1AgentsGet))
57
+
58
+ /**
59
+ * Gets agent by id
60
+ */
61
+ agent = this.query(removeAuthorizationParam(getAgentV1AgentsAgentIdGet))
62
+
63
+ /**
64
+ * Gets agents by ids
65
+ */
66
+ agentsByIds = this.query(removeAuthorizationParam(searchAgentsV1AgentsSearchPost))
67
+
68
+ /**
69
+ * Gets the default agent slug
70
+ */
71
+ agentDefaultSlug = AGENT_DEFAULT_SLUG
72
+
73
+ /**
74
+ * Gets the default agent
75
+ */
76
+ agentDefault = this.query({
77
+ name: 'agentDefault',
78
+ request: async (signal) => {
79
+ const agentDefault = await listAgentsV1AgentsGet(
80
+ { visibility: 'built_in', slug: this.agentDefaultSlug, authorization: '' }, { signal },
81
+ )
82
+
83
+ const agentId = agentDefault.at(0)?.id
84
+ const agent = agentId ? await this.agent.query({ agentId }) : undefined
85
+ return agent
86
+ },
87
+ })
88
+
89
+ /**
90
+ * List agents filtered by visibility.
91
+ */
92
+ allAgents = this.query({
93
+ name: 'allAgents',
94
+ request: async (signal, variables: { visibilities: (AgentVisibilityLevel | 'all')[] }) => {
95
+ const allVisibilities = ['account', 'built_in', 'favorite', 'personal', 'shared', 'workspace'] as const
96
+ const visibilities = variables.visibilities.includes('all')
97
+ ? allVisibilities
98
+ : variables.visibilities as Array<AgentVisibilityLevelEnum | VisibilityLevelEnum>
99
+
100
+ const shouldFetchWorkspaceAgents = visibilities.includes('workspace')
101
+
102
+ const workspaceAgentsPromise = shouldFetchWorkspaceAgents
103
+ ? workspaceAiClient.workspacesContentsByType.query({ contentType: 'agent' })
104
+ : Promise.resolve([])
105
+
106
+ const [workspaceAgents, ...agentsByVisibility] = await Promise.all([
107
+ workspaceAgentsPromise,
108
+ ...visibilities.map((visibility) => listAgentsV1AgentsGet({ visibility, authorization: '' }, { signal })),
109
+ ])
110
+
111
+ const workspaceAgentsWithSpaceName = workspaceAgents.flatMap(({ agents, space_name }) =>
112
+ agents?.map((agent) => ({ ...agent, spaceName: space_name, builtIn: false }))) as AgentResponseWithBuiltIn[]
113
+
114
+ const allAgents: AgentResponseWithBuiltIn[] = workspaceAgentsWithSpaceName ?? []
115
+
116
+ agentsByVisibility.forEach(agents => allAgents.push(...agents.map(agent => ({
117
+ ...agent,
118
+ builtIn: agent?.visibility_level === 'built_in',
119
+ }))))
120
+
121
+ return allAgents
122
+ },
123
+ })
22
124
  }
23
125
 
24
126
  export const agentToolsClient = new AgentToolsClient()
@@ -1,12 +1,8 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { defaults, deleteV1AgentByAgentIdFavorite, getV1AgentByAgentId, getV1Agents, getV1PublicAgentByAgentId, getV1PublicAgents, postV1AgentByAgentIdFavorite, postV1AgentsTrial, putV1AgentByAgentId, VisibilityLevel } from '../api/agent'
2
+ import { defaults, deleteV1AgentByAgentIdFavorite, getV1AgentByAgentId, getV1Agents, getV1PublicAgentByAgentId, getV1PublicAgents, postV1AgentByAgentIdFavorite, postV1AgentsTrial, putV1AgentByAgentId } from '../api/agent'
3
3
  import apis from '../apis.json'
4
4
  import { StackspotAPIError } from '../error/StackspotAPIError'
5
5
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
6
- import { AgentResponseWithBuiltIn, AgentVisibilityLevel } from './types'
7
- import { workspaceAiClient } from './workspace-ai'
8
-
9
- export const isAgentDefault = (agentSlug?: string) => agentSlug === 'stk_code_buddy'
10
6
 
11
7
  interface AgentError {
12
8
  code?: string,
@@ -32,56 +28,6 @@ class AgentClient extends ReactQueryNetworkClient {
32
28
  })
33
29
  }
34
30
 
35
- /**
36
- * List agents filtered by visibility.
37
- */
38
- allAgents = this.query({
39
- name: 'allAgents',
40
- request: async (signal, variables: { visibilities: AgentVisibilityLevel[] }) => {
41
- const visibilities: VisibilityLevel[] = variables.visibilities.includes('ALL')
42
- ? ['PERSONAL', 'SHARED', 'WORKSPACE', 'ACCOUNT', 'FAVORITE']
43
- : variables.visibilities.filter((visibility) => visibility !== 'BUILT-IN' && visibility !== 'ALL') as VisibilityLevel[]
44
-
45
- const shouldIncludeBuiltInAgent = variables.visibilities.includes('ALL') || variables.visibilities.includes('BUILT-IN')
46
- const shouldFetchBuiltInAgent = shouldIncludeBuiltInAgent || variables.visibilities.includes('FAVORITE')
47
- const shouldFetchWorkspaceAgents = variables.visibilities.includes('ALL') || variables.visibilities.includes('WORKSPACE')
48
-
49
- const publicAgentsPromise = shouldFetchBuiltInAgent ? getV1PublicAgents({}, { signal }) : Promise.resolve([])
50
- const workspaceAgentsPromise = shouldFetchWorkspaceAgents
51
- ? workspaceAiClient.workspacesContentsByType.query({ contentType: 'agent' })
52
- : Promise.resolve([])
53
-
54
- const [publicAgents, workspaceAgents, ...agentsByVisibility] = await Promise.all([
55
- publicAgentsPromise,
56
- workspaceAgentsPromise,
57
- ...visibilities.map((visibility) => getV1Agents({ visibility }, { signal })),
58
- ])
59
-
60
- const workspaceAgentsWithSpaceName = workspaceAgents?.flatMap(({ agents, space_name }) =>
61
- agents?.map((agent) => ({
62
- ...agent,
63
- spaceName: space_name,
64
- builtIn: publicAgents?.some(publicAgent => publicAgent.id === agent.id),
65
- }))) as AgentResponseWithBuiltIn[]
66
-
67
- const allAgents: AgentResponseWithBuiltIn[] = workspaceAgentsWithSpaceName || []
68
-
69
- if (shouldIncludeBuiltInAgent) {
70
- const builtInsAgents = publicAgents?.map((agent) => ({ ...agent, builtIn: true, visibility_level: 'BUILT-IN' }))
71
- allAgents.push(...builtInsAgents)
72
- }
73
-
74
- agentsByVisibility.forEach(agents => {
75
- allAgents.push(...agents.map(agent => ({
76
- ...agent,
77
- builtIn: publicAgents?.some(publicAgent => publicAgent.id === agent.id),
78
- })))
79
- })
80
-
81
- return allAgents
82
- },
83
- })
84
-
85
31
  /**
86
32
  * Gets an agent by id
87
33
  */
@@ -92,18 +38,6 @@ class AgentClient extends ReactQueryNetworkClient {
92
38
  : getV1AgentByAgentId({ ...variables }, { signal }),
93
39
  })
94
40
 
95
- /**
96
- * Gets the default agent
97
- */
98
- agentDefault = this.query({
99
- name: 'agentDefault',
100
- request: async (signal) => {
101
- const publicAgents = await getV1PublicAgents({}, { signal })
102
- const agentDefault = publicAgents.find((agent) => isAgentDefault(agent.slug))
103
- return agentDefault ? { ...agentDefault, builtIn: true } : undefined
104
- },
105
- })
106
-
107
41
  /**
108
42
  * List commons agents
109
43
  */
package/src/client/ai.ts CHANGED
@@ -31,6 +31,7 @@ import {
31
31
  QuickCommandsExecutionRequest,
32
32
  quickCommandsRunV2V2QuickCommandsSlugStepsStepSlugRunPost,
33
33
  resetKnowledgeObjectsV1KnowledgeSourcesSlugObjectsDelete,
34
+ searchKnowledgeSourcesV1KnowledgeSourcesSearchPost,
34
35
  updateQuickCommandV1QuickCommandsSlugPatch,
35
36
  updateTitleV1ConversationsConversationIdPatch,
36
37
  vectorizeCustomKnowledgeSourceV1KnowledgeSourcesSlugCustomPost,
@@ -127,6 +128,10 @@ class AIClient extends ReactQueryNetworkClient {
127
128
  * Gets a knowledge source document by the slug of the parent knowledge source and the document id.
128
129
  */
129
130
  knowledgeSourceDocument = this.query(removeAuthorizationParam(findKnowledgeObjectByCustomIdV1KnowledgeSourcesSlugObjectsCustomIdGet))
131
+ /**
132
+ * Lists knowledge sources matching the provided IDs.
133
+ */
134
+ searchKnowledgeSources = this.query(removeAuthorizationParam(searchKnowledgeSourcesV1KnowledgeSourcesSearchPost))
130
135
  /**
131
136
  * Gets the chat history. This is a paginated resource.
132
137
  */
@@ -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()
@@ -1,6 +1,6 @@
1
1
  import { RequestOpts } from '@oazapfts/runtime'
2
2
  import { AccountScmInfoSaveRequest, AccountScmInfoUpdateRequest, AccountScmStatusResponse, GroupsFromResourceResponse, MembersFromResourceResponse } from '../api/account'
3
- import { AgentResponse, VisibilityLevel } from '../api/agent'
3
+ import { AgentVisibilityLevelEnum, ListAgentResponse, VisibilityLevelEnum } from '../api/agent-tools'
4
4
  import { ChatRequest, ChatResponse3, ContentDependencyResponse, ConversationHistoryResponse, ConversationResponse, DependencyResponse } from '../api/ai'
5
5
  import { ConnectAccountRequestV2, ManagedAccountProvisionRequest } from '../api/cloudAccount'
6
6
  import { AllocationCostRequest, AllocationCostResponse, ChargePeriod, getAllocationCostFilters, ManagedService, ServiceResource } from '../api/cloudServices'
@@ -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
 
@@ -218,6 +219,7 @@ export interface WorkspaceAiMembersPermissions {
218
219
  totalPages: number,
219
220
  }
220
221
 
222
+
221
223
  export interface WorkspaceAiGroupsPermissions extends GroupsFromResourceResponse {
222
224
  actions: Action[],
223
225
  }
@@ -356,9 +358,11 @@ export type FixVariables<
356
358
 
357
359
  export type ReplaceResult<T extends (...args: any[]) => Promise<any>, Fix> = (...args: Parameters<T>) => Promise<Fix>
358
360
 
359
- export interface AgentResponseWithBuiltIn extends AgentResponse {
361
+ export interface AgentResponseWithBuiltIn extends Omit<ListAgentResponse, 'conversation_starter' | 'avatar'> {
360
362
  builtIn?: boolean,
361
363
  spaceName?: string,
362
- }
364
+ conversation_starter?: string[] | null,
365
+ avatar?: string | null | undefined,
366
+ }
363
367
 
364
- export type AgentVisibilityLevel = VisibilityLevel | 'BUILT-IN' | 'ALL'
368
+ export type AgentVisibilityLevel = AgentVisibilityLevelEnum | VisibilityLevelEnum
@@ -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'