@stack-spot/portal-network 0.146.2-beta.0 → 0.147.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 (43) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/agent-tools.d.ts +524 -29
  3. package/dist/api/agent-tools.d.ts.map +1 -1
  4. package/dist/api/agent-tools.js +276 -11
  5. package/dist/api/agent-tools.js.map +1 -1
  6. package/dist/client/agent-tools.d.ts +92 -51
  7. package/dist/client/agent-tools.d.ts.map +1 -1
  8. package/dist/client/agent-tools.js +44 -72
  9. package/dist/client/agent-tools.js.map +1 -1
  10. package/dist/client/agent.d.ts +49 -2
  11. package/dist/client/agent.d.ts.map +1 -1
  12. package/dist/client/agent.js +63 -0
  13. package/dist/client/agent.js.map +1 -1
  14. package/dist/client/ai.d.ts +30 -37
  15. package/dist/client/ai.d.ts.map +1 -1
  16. package/dist/client/ai.js +1 -10
  17. package/dist/client/ai.js.map +1 -1
  18. package/dist/client/cloud-account.d.ts +5 -5
  19. package/dist/client/cloud-platform-horizon.d.ts +20 -20
  20. package/dist/client/cloud-platform.d.ts +28 -28
  21. package/dist/client/cloud-runtimes.d.ts +21 -21
  22. package/dist/client/code-shift.d.ts +37 -37
  23. package/dist/client/content.d.ts +6 -6
  24. package/dist/client/data-integration.d.ts +19 -8
  25. package/dist/client/data-integration.d.ts.map +1 -1
  26. package/dist/client/data-integration.js +13 -4
  27. package/dist/client/data-integration.js.map +1 -1
  28. package/dist/client/discovery.d.ts +6 -6
  29. package/dist/client/gen-ai-inference.d.ts +9 -9
  30. package/dist/client/types.d.ts +12 -5
  31. package/dist/client/types.d.ts.map +1 -1
  32. package/dist/client/workflow.d.ts +10 -10
  33. package/dist/client/workspace-ai.d.ts +15 -15
  34. package/dist/utils/StreamedJson.js +2 -2
  35. package/dist/utils/StreamedJson.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/api/agent-tools.ts +843 -30
  38. package/src/client/agent-tools.ts +41 -86
  39. package/src/client/agent.ts +67 -1
  40. package/src/client/ai.ts +0 -5
  41. package/src/client/data-integration.ts +27 -19
  42. package/src/client/types.ts +14 -7
  43. package/src/utils/StreamedJson.tsx +2 -2
@@ -1,13 +1,10 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { addFavoriteV1AgentsAgentIdFavoritePost, AgentVisibilityLevelEnum, createAgentV1AgentsPost, defaults, deleteAgentV1AgentsAgentIdDelete, getAgentV1AgentsAgentIdGet, getPublicToolKitsV1BuiltinToolkitGet, HttpValidationError, listAgentsV1AgentsGet, publishAgentV1AgentsAgentIdPublishPost, searchAgentsV1AgentsSearchPost, updateAgentV1AgentsAgentIdPut, VisibilityLevelEnum } from '../api/agent-tools'
2
+ import { createToolkitToolsV1ToolkitsToolkitIdToolsPost, createToolkitV1ToolkitsPost, defaults, deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete, deleteToolkitV1ToolkitsToolkitIdDelete, editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut, getPublicToolKitsV1BuiltinToolkitGet, getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet, getToolkitV1ToolkitsToolkitIdGet, HttpValidationError, listToolkitsV1ToolkitsGet, updateToolkitV1ToolkitsToolkitIdPatch } 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
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'
7
+ import { AgentToolsOpenAPIPreview } from './types'
11
8
 
12
9
  class AgentToolsClient extends ReactQueryNetworkClient {
13
10
  constructor() {
@@ -19,106 +16,64 @@ class AgentToolsClient extends ReactQueryNetworkClient {
19
16
  status: error.status,
20
17
  headers: error.headers,
21
18
  stack: error.stack,
22
- message: (error.data as HttpValidationError | undefined)?.detail?.map(d => d.msg)?.join('\n'),
19
+ // @ts-ignore API documentation is wrong
20
+ message: (error.data as HttpValidationError | undefined)?.details?.map(d => d.msg)?.join('\n'),
23
21
  })
24
22
  }
25
23
 
26
24
  tools = this.query(getPublicToolKitsV1BuiltinToolkitGet)
27
25
 
28
26
  /**
29
- * Create agent
27
+ * Get list of Toolkits
30
28
  */
31
- createAgent = this.mutation(removeAuthorizationParam(createAgentV1AgentsPost))
32
-
29
+ toolkits = this.query(removeAuthorizationParam(listToolkitsV1ToolkitsGet))
33
30
  /**
34
- * Delete agent
31
+ * Get a toolkit by Id
35
32
  */
36
- deleteAgent = this.mutation(deleteAgentV1AgentsAgentIdDelete)
37
-
33
+ toolkitById = this.query(removeAuthorizationParam(getToolkitV1ToolkitsToolkitIdGet))
38
34
  /**
39
- * Updates an agent
35
+ * Create a toolkit
40
36
  */
41
- updateAgent = this.mutation(updateAgentV1AgentsAgentIdPut)
42
-
37
+ createToolkit = this.mutation(removeAuthorizationParam(createToolkitV1ToolkitsPost))
43
38
  /**
44
- * Favorite an agent
45
- */
46
- favoriteAgent = this.mutation(addFavoriteV1AgentsAgentIdFavoritePost)
47
-
39
+ * Update a toolkit
40
+ */
41
+ updateToolkit = this.mutation(removeAuthorizationParam(updateToolkitV1ToolkitsToolkitIdPatch))
48
42
  /**
49
- * Publish an agent
50
- */
51
- publishAgent = this.mutation(publishAgentV1AgentsAgentIdPublishPost)
52
-
53
- /**
54
- * List agents
43
+ * Delete a toolkit
55
44
  */
56
- agents = this.infiniteQuery(removeAuthorizationParam(listAgentsV1AgentsGet))
57
-
58
- /**
59
- * Gets agent by id
45
+ deleteToolkit = this.mutation(removeAuthorizationParam(deleteToolkitV1ToolkitsToolkitIdDelete))
46
+ /**
47
+ * Get Tool from Toolkit
60
48
  */
61
- agent = this.query(removeAuthorizationParam(getAgentV1AgentsAgentIdGet))
62
-
63
- /**
64
- * Gets agents by ids
49
+ toolFromToolkit = this.query(removeAuthorizationParam(getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet))
50
+ /**
51
+ * Add tool on Toolkit
65
52
  */
66
- agentsByIds = this.query(removeAuthorizationParam(searchAgentsV1AgentsSearchPost))
67
-
68
- /**
69
- * Gets the default agent slug
53
+ addToolOnToolkit = this.mutation(removeAuthorizationParam(createToolkitToolsV1ToolkitsToolkitIdToolsPost))
54
+ /**
55
+ * Edit tool on Toolkit
70
56
  */
71
- agentDefaultSlug = AGENT_DEFAULT_SLUG
72
-
73
- /**
74
- * Gets the default agent
57
+ editToolOnToolkit = this.mutation(removeAuthorizationParam(editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut))
58
+ /**
59
+ * Delete tool from Toolkit
75
60
  */
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.
61
+ deleteToolFromToolkit = this.mutation(removeAuthorizationParam(deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete))
62
+ /**
63
+ * Previews an uploaded open api file.
91
64
  */
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
65
+ previewUploadedAPI = this.query({
66
+ name: 'previewUploadedAPI',
67
+ request: async (signal, params: { fileUploadId: string }) => {
68
+ const url = `/v1/toolkits/tools/preview/${encodeURIComponent(params.fileUploadId)}`
69
+ const events = await this.stream(url, { signal })
70
+ const result: AgentToolsOpenAPIPreview[] = []
71
+ for await (const event of events) {
72
+ if (event.data) {
73
+ result.push(JSON.parse(event.data))
74
+ }
75
+ }
76
+ return result
122
77
  },
123
78
  })
124
79
  }
@@ -1,8 +1,12 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { defaults, deleteV1AgentByAgentIdFavorite, getV1AgentByAgentId, getV1Agents, getV1PublicAgentByAgentId, getV1PublicAgents, postV1AgentByAgentIdFavorite, postV1AgentsTrial, putV1AgentByAgentId } from '../api/agent'
2
+ import { defaults, deleteV1AgentByAgentIdFavorite, getV1AgentByAgentId, getV1Agents, getV1PublicAgentByAgentId, getV1PublicAgents, postV1AgentByAgentIdFavorite, postV1AgentsTrial, putV1AgentByAgentId, VisibilityLevel } 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'
6
10
 
7
11
  interface AgentError {
8
12
  code?: string,
@@ -28,6 +32,56 @@ class AgentClient extends ReactQueryNetworkClient {
28
32
  })
29
33
  }
30
34
 
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
+
31
85
  /**
32
86
  * Gets an agent by id
33
87
  */
@@ -38,6 +92,18 @@ class AgentClient extends ReactQueryNetworkClient {
38
92
  : getV1AgentByAgentId({ ...variables }, { signal }),
39
93
  })
40
94
 
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
+
41
107
  /**
42
108
  * List commons agents
43
109
  */
package/src/client/ai.ts CHANGED
@@ -33,7 +33,6 @@ import {
33
33
  quickCommandsRunV2V2QuickCommandsSlugStepsStepSlugRunPost,
34
34
  resetKnowledgeObjectsV1KnowledgeSourcesSlugObjectsDelete,
35
35
  runFetchStepV1QuickCommandsSlugStepsStepSlugFetchRunPost,
36
- searchKnowledgeSourcesV1KnowledgeSourcesSearchPost,
37
36
  updateQuickCommandV1QuickCommandsSlugPatch,
38
37
  updateTitleV1ConversationsConversationIdPatch,
39
38
  vectorizeCustomKnowledgeSourceV1KnowledgeSourcesSlugCustomPost,
@@ -135,10 +134,6 @@ class AIClient extends ReactQueryNetworkClient {
135
134
  * Gets a knowledge source document by the slug of the parent knowledge source and the document id.
136
135
  */
137
136
  knowledgeSourceDocument = this.query(removeAuthorizationParam(findKnowledgeObjectByCustomIdV1KnowledgeSourcesSlugObjectsCustomIdGet))
138
- /**
139
- * Lists knowledge sources matching the provided IDs.
140
- */
141
- searchKnowledgeSources = this.query(removeAuthorizationParam(searchKnowledgeSourcesV1KnowledgeSourcesSearchPost))
142
137
  /**
143
138
  * Gets the chat history. This is a paginated resource.
144
139
  */
@@ -9,6 +9,7 @@ import {
9
9
  listKsV1KnowledgeSourcesGet,
10
10
  saveChunkedFilesDeprecatedV1FileUploadFileUploadIdPost,
11
11
  saveChunkedFilesV1FileUploadFileUploadIdKnowledgeObjectsPost,
12
+ splitUploadedFilePreviewV1FileUploadFileUploadIdSplitPreviewSplitStrategyGet,
12
13
  splitUploadedFileV1FileUploadFileUploadIdSplitPost,
13
14
  } from '../api/dataIntegration'
14
15
  import apis from '../apis.json'
@@ -65,7 +66,12 @@ class DataIntegrationClient extends ReactQueryNetworkClient {
65
66
  'Accept': 'text/event-stream',
66
67
  },
67
68
  signal: options?.signal,
68
- })}
69
+ })
70
+ }
71
+ /**
72
+ * Generate a preview with splitted objects
73
+ */
74
+ previewFromSplit = this.query(removeAuthorizationParam(splitUploadedFilePreviewV1FileUploadFileUploadIdSplitPreviewSplitStrategyGet))
69
75
  /**
70
76
  * List of knowledge sources
71
77
  */
@@ -81,24 +87,26 @@ class DataIntegrationClient extends ReactQueryNetworkClient {
81
87
 
82
88
  uploadFiles = this.mutation({
83
89
  name: 'uploadFiles',
84
- request: (abortSignal, params: { files: File[], type: FileUploadType }) => Promise.all(params.files.map(async (f) => {
85
- try {
86
- const { id, url, form } = await getUploadFormV2V2FileUploadFormPost({
87
- authorization: '',
88
- newFileUploadRequest: { file_name: f.name, target_type: params.type, target_id: '' },
89
- }, { signal: abortSignal })
90
- const formData = new FormData()
91
- Object.entries(form).forEach(([key, value]) => {
92
- formData.append(key, value)
93
- })
94
- formData.append('file', f)
95
- const response = await fetch(url, { method: 'post', body: formData, signal: abortSignal })
96
- if (!response.ok) throw new StackspotAPIError({ status: response.status, headers: response.headers, message: 'Failed to upload' })
97
- return id
98
- } catch (e: any) {
99
- throw new FileUploadError(f.name, e)
100
- }
101
- })),
90
+ request: (abortSignal, params: { files: File[], type: FileUploadType, targetId?: string }) => (
91
+ Promise.all(params.files.map(async (f) => {
92
+ try {
93
+ const { id, url, form } = await getUploadFormV2V2FileUploadFormPost({
94
+ authorization: '',
95
+ newFileUploadRequest: { file_name: f.name, target_type: params.type, target_id: params.targetId ?? '' },
96
+ }, { signal: abortSignal })
97
+ const formData = new FormData()
98
+ Object.entries(form).forEach(([key, value]) => {
99
+ formData.append(key, value)
100
+ })
101
+ formData.append('file', f)
102
+ const response = await fetch(url, { method: 'post', body: formData, signal: abortSignal })
103
+ if (!response.ok) throw new StackspotAPIError({ status: response.status, headers: response.headers, message: 'Failed to upload' })
104
+ return id
105
+ } catch (e: any) {
106
+ throw new FileUploadError(f.name, e)
107
+ }
108
+ }))
109
+ ),
102
110
  })
103
111
  }
104
112
 
@@ -1,6 +1,7 @@
1
1
  import { RequestOpts } from '@oazapfts/runtime'
2
2
  import { AccountScmInfoSaveRequest, AccountScmInfoUpdateRequest, AccountScmStatusResponse, GroupsFromResourceResponse, MembersFromResourceResponse } from '../api/account'
3
- import { AgentVisibilityLevelEnum, ListAgentResponse, VisibilityLevelEnum } from '../api/agent-tools'
3
+ import { AgentResponse, VisibilityLevel } from '../api/agent'
4
+ import { HttpMethod } from '../api/agent-tools'
4
5
  import { ChatRequest, ChatResponse3, ContentDependencyResponse, ConversationHistoryResponse, ConversationResponse, DependencyResponse } from '../api/ai'
5
6
  import { ConnectAccountRequestV2, ManagedAccountProvisionRequest } from '../api/cloudAccount'
6
7
  import { AllocationCostRequest, AllocationCostResponse, ChargePeriod, getAllocationCostFilters, ManagedService, ServiceResource } from '../api/cloudServices'
@@ -219,7 +220,6 @@ export interface WorkspaceAiMembersPermissions {
219
220
  totalPages: number,
220
221
  }
221
222
 
222
-
223
223
  export interface WorkspaceAiGroupsPermissions extends GroupsFromResourceResponse {
224
224
  actions: Action[],
225
225
  }
@@ -358,11 +358,18 @@ export type FixVariables<
358
358
 
359
359
  export type ReplaceResult<T extends (...args: any[]) => Promise<any>, Fix> = (...args: Parameters<T>) => Promise<Fix>
360
360
 
361
- export interface AgentResponseWithBuiltIn extends Omit<ListAgentResponse, 'conversation_starter' | 'avatar'> {
361
+ export interface AgentResponseWithBuiltIn extends AgentResponse {
362
362
  builtIn?: boolean,
363
363
  spaceName?: string,
364
- conversation_starter?: string[] | null,
365
- avatar?: string | null | undefined,
366
- }
364
+ }
365
+
366
+ export type AgentVisibilityLevel = VisibilityLevel | 'BUILT-IN' | 'ALL'
367
367
 
368
- export type AgentVisibilityLevel = AgentVisibilityLevelEnum | VisibilityLevelEnum
368
+ export interface AgentToolsOpenAPIPreview {
369
+ name: string,
370
+ description: string,
371
+ method: HttpMethod,
372
+ url: string,
373
+ parameters?: Record<string, any>,
374
+ request_body?: Record<string, any>,
375
+ }
@@ -92,8 +92,8 @@ export class StreamedJson<T> {
92
92
  else if (typeof source[k] === 'string') target[k] += source[k]
93
93
  else if (Array.isArray(source[k])) target[k].push(...source[k])
94
94
  else if (typeof source[k] === 'number') parseFloat(target[k] + source[k])
95
- else if (typeof source[k] === 'object') this.merge(source[k], target[k])
96
- else target[k] = source[k]
95
+ else if (source[k] && typeof source[k] === 'object') this.merge(source[k], target[k])
96
+ else if (source[k]) target[k] = source[k]
97
97
  })
98
98
  }
99
99