@stack-spot/portal-network 0.149.0-beta.2 → 0.149.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,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
  */
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { attach, createHypothesis, defaults, deleteHypothesisById, deleteV1DocumentsByDocumentIdHypothesesAndHypothesisId, download, findHypothesisById, getAll, getById, list, list1, listAllDocumentsWithHypotheses, listHypothesis, upload } from '../api/discovery'
2
+ import { attach, createHypothesis, defaults, deleteHypothesisById, deleteV1DocumentsByDocumentIdHypothesesAndHypothesisId, download, findHypothesisById, getAll, getById, list, list1, listAllDocumentsWithHypotheses, listHypothesis, listVersions, upload } from '../api/discovery'
3
3
  import apis from '../apis.json'
4
4
  import { DefaultAPIError } from '../error/DefaultAPIError'
5
5
  import { baseDictionary } from '../error/dictionary/base'
@@ -68,6 +68,10 @@ class DiscoveryClient extends ReactQueryNetworkClient {
68
68
  * Download an document
69
69
  */
70
70
  downloadDocument = this.query(removeAuthorizationParam(download))
71
+ /**
72
+ * List versions of a document
73
+ */
74
+ listDocumentVersions = this.query(removeAuthorizationParam(listVersions))
71
75
  }
72
76
 
73
77
  export const discoveryClient = new DiscoveryClient()
@@ -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, HttpMethod, 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,14 +358,12 @@ 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
+ }
367
365
 
368
- export type AgentVisibilityLevel = AgentVisibilityLevelEnum | VisibilityLevelEnum
366
+ export type AgentVisibilityLevel = VisibilityLevel | 'BUILT-IN' | 'ALL'
369
367
 
370
368
  export interface AgentToolsOpenAPIPreview {
371
369
  name: string,