@stack-spot/portal-network 0.148.0 → 0.149.0-beta.2

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,10 +1,13 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { createToolkitToolsV1ToolkitsToolkitIdToolsPost, createToolkitV1ToolkitsPost, defaults, deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete, deleteToolkitV1ToolkitsToolkitIdDelete, editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut, getPublicToolKitsV1BuiltinToolkitGet, getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet, getToolkitV1ToolkitsToolkitIdGet, HttpValidationError, listToolkitsV1ToolkitsGet, updateToolkitV1ToolkitsToolkitIdPatch } from '../api/agent-tools'
2
+ import { addFavoriteV1AgentsAgentIdFavoritePost, AgentVisibilityLevelEnum, createAgentV1AgentsPost, createToolkitToolsV1ToolkitsToolkitIdToolsPost, createToolkitV1ToolkitsPost, defaults, deleteAgentV1AgentsAgentIdDelete, deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete, deleteToolkitV1ToolkitsToolkitIdDelete, editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut, getAgentV1AgentsAgentIdGet, getPublicToolKitsV1BuiltinToolkitGet, getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet, getToolkitV1ToolkitsToolkitIdGet, HttpValidationError, listAgentsV1AgentsGet, listToolkitsV1ToolkitsGet, publishAgentV1AgentsAgentIdPublishPost, searchAgentsV1AgentsSearchPost, updateAgentV1AgentsAgentIdPut, updateToolkitV1ToolkitsToolkitIdPatch, 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
6
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
7
- import { AgentToolsOpenAPIPreview } from './types'
7
+ import { AgentResponseWithBuiltIn, AgentToolsOpenAPIPreview, AgentVisibilityLevel } from './types'
8
+ import { workspaceAiClient } from './workspace-ai'
9
+
10
+ const AGENT_DEFAULT_SLUG = 'stk_code_buddy'
8
11
 
9
12
  class AgentToolsClient extends ReactQueryNetworkClient {
10
13
  constructor() {
@@ -21,11 +24,107 @@ class AgentToolsClient extends ReactQueryNetworkClient {
21
24
  })
22
25
  }
23
26
 
24
- tools = this.query(getPublicToolKitsV1BuiltinToolkitGet)
27
+ tools = this.query(removeAuthorizationParam(getPublicToolKitsV1BuiltinToolkitGet))
28
+
29
+ /**
30
+ * Create agent
31
+ */
32
+ createAgent = this.mutation(removeAuthorizationParam(createAgentV1AgentsPost))
33
+
34
+ /**
35
+ * Delete agent
36
+ */
37
+ deleteAgent = this.mutation(deleteAgentV1AgentsAgentIdDelete)
38
+
39
+ /**
40
+ * Updates an agent
41
+ */
42
+ updateAgent = this.mutation(updateAgentV1AgentsAgentIdPut)
43
+
44
+ /**
45
+ * Favorite an agent
46
+ */
47
+ favoriteAgent = this.mutation(addFavoriteV1AgentsAgentIdFavoritePost)
25
48
 
26
49
  /**
27
- * Get list of Toolkits
50
+ * Publish an agent
51
+ */
52
+ publishAgent = this.mutation(publishAgentV1AgentsAgentIdPublishPost)
53
+
54
+ /**
55
+ * List agents
56
+ */
57
+ agents = this.infiniteQuery(removeAuthorizationParam(listAgentsV1AgentsGet))
58
+
59
+ /**
60
+ * Gets agent by id
61
+ */
62
+ agent = this.query(removeAuthorizationParam(getAgentV1AgentsAgentIdGet))
63
+
64
+ /**
65
+ * Gets agents by ids
66
+ */
67
+ agentsByIds = this.query(removeAuthorizationParam(searchAgentsV1AgentsSearchPost))
68
+
69
+ /**
70
+ * Gets the default agent slug
71
+ */
72
+ agentDefaultSlug = AGENT_DEFAULT_SLUG
73
+
74
+ /**
75
+ * Gets the default agent
28
76
  */
77
+ agentDefault = this.query({
78
+ name: 'agentDefault',
79
+ request: async (signal) => {
80
+ const agentDefault = await listAgentsV1AgentsGet(
81
+ { visibility: 'built_in', slug: this.agentDefaultSlug, authorization: '' }, { signal },
82
+ )
83
+
84
+ const agentId = agentDefault.at(0)?.id
85
+ const agent = agentId ? await this.agent.query({ agentId }) : undefined
86
+ return agent
87
+ },
88
+ })
89
+
90
+ /**
91
+ * List agents filtered by visibility.
92
+ */
93
+ allAgents = this.query({
94
+ name: 'allAgents',
95
+ request: async (signal, variables: { visibilities: (AgentVisibilityLevel | 'all')[] }) => {
96
+ const allVisibilities = ['account', 'built_in', 'favorite', 'personal', 'shared', 'workspace'] as const
97
+ const visibilities = variables.visibilities.includes('all')
98
+ ? allVisibilities
99
+ : variables.visibilities as Array<AgentVisibilityLevelEnum | VisibilityLevelEnum>
100
+
101
+ const shouldFetchWorkspaceAgents = visibilities.includes('workspace')
102
+
103
+ const workspaceAgentsPromise = shouldFetchWorkspaceAgents
104
+ ? workspaceAiClient.workspacesContentsByType.query({ contentType: 'agent' })
105
+ : Promise.resolve([])
106
+
107
+ const [workspaceAgents, ...agentsByVisibility] = await Promise.all([
108
+ workspaceAgentsPromise,
109
+ ...visibilities.map((visibility) => listAgentsV1AgentsGet({ visibility, authorization: '' }, { signal })),
110
+ ])
111
+
112
+ const workspaceAgentsWithSpaceName = workspaceAgents.flatMap(({ agents, space_name }) =>
113
+ agents?.map((agent) => ({ ...agent, spaceName: space_name, builtIn: false }))) as AgentResponseWithBuiltIn[]
114
+
115
+ const allAgents: AgentResponseWithBuiltIn[] = workspaceAgentsWithSpaceName ?? []
116
+
117
+ agentsByVisibility.forEach(agents => allAgents.push(...agents.map(agent => ({
118
+ ...agent,
119
+ builtIn: agent?.visibility_level === 'built_in',
120
+ }))))
121
+
122
+ return allAgents
123
+ },
124
+ })
125
+
126
+ /* Get list of Toolkits
127
+ */
29
128
  toolkits = this.query(removeAuthorizationParam(listToolkitsV1ToolkitsGet))
30
129
  /**
31
130
  * Get a toolkit by Id
@@ -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
@@ -33,6 +33,7 @@ import {
33
33
  quickCommandsRunV2V2QuickCommandsSlugStepsStepSlugRunPost,
34
34
  resetKnowledgeObjectsV1KnowledgeSourcesSlugObjectsDelete,
35
35
  runFetchStepV1QuickCommandsSlugStepsStepSlugFetchRunPost,
36
+ searchKnowledgeSourcesV1KnowledgeSourcesSearchPost,
36
37
  updateQuickCommandV1QuickCommandsSlugPatch,
37
38
  updateTitleV1ConversationsConversationIdPatch,
38
39
  vectorizeCustomKnowledgeSourceV1KnowledgeSourcesSlugCustomPost,
@@ -134,6 +135,10 @@ class AIClient extends ReactQueryNetworkClient {
134
135
  * Gets a knowledge source document by the slug of the parent knowledge source and the document id.
135
136
  */
136
137
  knowledgeSourceDocument = this.query(removeAuthorizationParam(findKnowledgeObjectByCustomIdV1KnowledgeSourcesSlugObjectsCustomIdGet))
138
+ /**
139
+ * Lists knowledge sources matching the provided IDs.
140
+ */
141
+ searchKnowledgeSources = this.query(removeAuthorizationParam(searchKnowledgeSourcesV1KnowledgeSourcesSearchPost))
137
142
  /**
138
143
  * Gets the chat history. This is a paginated resource.
139
144
  */
@@ -1,7 +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'
4
- import { HttpMethod } from '../api/agent-tools'
3
+ import { AgentVisibilityLevelEnum, HttpMethod, ListAgentResponse, VisibilityLevelEnum } from '../api/agent-tools'
5
4
  import { ChatRequest, ChatResponse3, ContentDependencyResponse, ConversationHistoryResponse, ConversationResponse, DependencyResponse } from '../api/ai'
6
5
  import { ConnectAccountRequestV2, ManagedAccountProvisionRequest } from '../api/cloudAccount'
7
6
  import { AllocationCostRequest, AllocationCostResponse, ChargePeriod, getAllocationCostFilters, ManagedService, ServiceResource } from '../api/cloudServices'
@@ -220,6 +219,7 @@ export interface WorkspaceAiMembersPermissions {
220
219
  totalPages: number,
221
220
  }
222
221
 
222
+
223
223
  export interface WorkspaceAiGroupsPermissions extends GroupsFromResourceResponse {
224
224
  actions: Action[],
225
225
  }
@@ -358,12 +358,14 @@ 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 AgentResponse {
361
+ export interface AgentResponseWithBuiltIn extends Omit<ListAgentResponse, 'conversation_starter' | 'avatar'> {
362
362
  builtIn?: boolean,
363
363
  spaceName?: string,
364
- }
364
+ conversation_starter?: string[] | null,
365
+ avatar?: string | null | undefined,
366
+ }
365
367
 
366
- export type AgentVisibilityLevel = VisibilityLevel | 'BUILT-IN' | 'ALL'
368
+ export type AgentVisibilityLevel = AgentVisibilityLevelEnum | VisibilityLevelEnum
367
369
 
368
370
  export interface AgentToolsOpenAPIPreview {
369
371
  name: string,