@stack-spot/portal-network 0.149.0-beta.2 → 0.150.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 (63) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/api/agent.d.ts +30 -16
  3. package/dist/api/agent.d.ts.map +1 -1
  4. package/dist/api/agent.js +0 -18
  5. package/dist/api/agent.js.map +1 -1
  6. package/dist/api/discovery.d.ts +162 -106
  7. package/dist/api/discovery.d.ts.map +1 -1
  8. package/dist/api/discovery.js +23 -3
  9. package/dist/api/discovery.js.map +1 -1
  10. package/dist/client/agent-tools.d.ts +21 -92
  11. package/dist/client/agent-tools.d.ts.map +1 -1
  12. package/dist/client/agent-tools.js +21 -149
  13. package/dist/client/agent-tools.js.map +1 -1
  14. package/dist/client/agent.d.ts +50 -9
  15. package/dist/client/agent.d.ts.map +1 -1
  16. package/dist/client/agent.js +65 -10
  17. package/dist/client/agent.js.map +1 -1
  18. package/dist/client/ai.d.ts +6 -13
  19. package/dist/client/ai.d.ts.map +1 -1
  20. package/dist/client/ai.js +7 -16
  21. package/dist/client/ai.js.map +1 -1
  22. package/dist/client/discovery.d.ts +10 -1
  23. package/dist/client/discovery.d.ts.map +1 -1
  24. package/dist/client/discovery.js +10 -1
  25. package/dist/client/discovery.js.map +1 -1
  26. package/dist/client/secrets.d.ts +2 -2
  27. package/dist/client/secrets.d.ts.map +1 -1
  28. package/dist/client/secrets.js +2 -2
  29. package/dist/client/secrets.js.map +1 -1
  30. package/dist/client/types.d.ts +4 -5
  31. package/dist/client/types.d.ts.map +1 -1
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +2 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/types.d.ts +2 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/types.js +2 -0
  39. package/dist/types.js.map +1 -0
  40. package/dist/utils/StreamedArray.d.ts +66 -0
  41. package/dist/utils/StreamedArray.d.ts.map +1 -0
  42. package/dist/utils/StreamedArray.js +148 -0
  43. package/dist/utils/StreamedArray.js.map +1 -0
  44. package/dist/utils/StreamedJson.d.ts +1 -1
  45. package/dist/utils/StreamedJson.d.ts.map +1 -1
  46. package/dist/utils/use-streamed-array.d.ts +4 -0
  47. package/dist/utils/use-streamed-array.d.ts.map +1 -0
  48. package/dist/utils/use-streamed-array.js +15 -0
  49. package/dist/utils/use-streamed-array.js.map +1 -0
  50. package/package.json +1 -1
  51. package/src/api/agent.ts +30 -84
  52. package/src/api/discovery.ts +192 -107
  53. package/src/client/agent-tools.ts +17 -117
  54. package/src/client/agent.ts +72 -6
  55. package/src/client/ai.ts +6 -11
  56. package/src/client/discovery.ts +5 -1
  57. package/src/client/secrets.ts +2 -2
  58. package/src/client/types.ts +5 -7
  59. package/src/index.ts +3 -1
  60. package/src/types.ts +1 -0
  61. package/src/utils/StreamedArray.tsx +146 -0
  62. package/src/utils/StreamedJson.tsx +1 -1
  63. package/src/utils/use-streamed-array.ts +17 -0
@@ -15,7 +15,7 @@ export const servers = {
15
15
  generatedServerUrl: "https://discover-discover-core.dev.stackspot.com"
16
16
  };
17
17
  export type OpportunityResponse = {
18
- id?: string;
18
+ id: string;
19
19
  name?: string;
20
20
  "number"?: string;
21
21
  createdAt?: string;
@@ -25,14 +25,14 @@ export type OpportunityResponse = {
25
25
  };
26
26
  };
27
27
  export type HypothesisResponse = {
28
- id?: string;
29
- opportunity?: OpportunityResponse;
30
- name?: string;
28
+ id: string;
29
+ opportunity: OpportunityResponse;
30
+ name: string;
31
31
  description?: string;
32
- "number"?: string;
33
- status?: "TO_DO" | "PRIORITIZED" | "IN_EXPERIMENTATION" | "VALIDATED" | "DISCARDED" | "CANCELED";
32
+ "number": string;
33
+ status: "TO_DO" | "PRIORITIZED" | "IN_EXPERIMENTATION" | "VALIDATED" | "DISCARDED" | "CANCELED";
34
34
  createdAt?: string;
35
- createdBy?: string;
35
+ createdBy: string;
36
36
  updatedAt?: string;
37
37
  updatedBy?: string;
38
38
  };
@@ -43,144 +43,188 @@ export type HypothesisUpdateRequest = {
43
43
  status?: string;
44
44
  };
45
45
  export type SortResponse = {
46
- direction?: string;
47
- nullHandling?: string;
48
- ascending?: boolean;
49
- property?: string;
50
- ignoreCase?: boolean;
46
+ direction: string;
47
+ nullHandling: string;
48
+ ascending: boolean;
49
+ property: string;
50
+ ignoreCase: boolean;
51
51
  };
52
52
  export type PageableResponse = {
53
- offset?: number;
54
- sort?: SortResponse[];
55
- paged?: boolean;
56
- pageSize?: number;
57
- pageNumber?: number;
58
- unpaged?: boolean;
53
+ offset: number;
54
+ sort: SortResponse[];
55
+ paged: boolean;
56
+ pageSize: number;
57
+ pageNumber: number;
58
+ unpaged: boolean;
59
59
  };
60
60
  export type PageResponseHypothesisResponse = {
61
- totalElements?: number;
62
- totalPages?: number;
63
- first?: boolean;
64
- last?: boolean;
65
- size?: number;
66
- content?: HypothesisResponse[];
67
- "number"?: number;
68
- sort?: SortResponse[];
69
- numberOfElements?: number;
70
- pageable?: PageableResponse;
71
- empty?: boolean;
61
+ totalElements: number;
62
+ totalPages: number;
63
+ first: boolean;
64
+ last: boolean;
65
+ size: number;
66
+ content: HypothesisResponse[];
67
+ "number": number;
68
+ sort: SortResponse[];
69
+ numberOfElements: number;
70
+ pageable: PageableResponse;
71
+ empty: boolean;
72
72
  };
73
73
  export type HypothesisCreateRequest = {
74
- name?: string;
75
- description?: string;
76
- opportunityId?: string;
74
+ name: string;
75
+ description: string;
76
+ opportunityId: string;
77
77
  };
78
78
  export type DocumentUploadRequest = {
79
- file?: Blob;
80
- description?: string;
81
- name?: string;
82
- typeId?: string;
83
- origin?: "AI" | "UPLOAD";
84
- };
85
- export type DocumentAttachRequest = {
86
- documentIds?: string[];
79
+ file: Blob;
80
+ description: string;
81
+ name: string;
82
+ typeId: string;
83
+ origin: "AI" | "UPLOAD";
87
84
  };
88
85
  export type AgentResponse = {
89
- id?: string;
90
- label?: string;
86
+ id: string;
87
+ label: string;
91
88
  image?: string;
92
- builtIn?: boolean;
93
- slug?: string;
89
+ builtIn: boolean;
90
+ slug: string;
94
91
  createdAt?: string;
95
92
  };
96
93
  export type DocumentTypeResponse = {
97
- id?: string;
98
- typeName?: "PRESS_RELEASE" | "PRODUCT_VISION" | "PRODUCT_REQUIREMENTS" | "MARKET_COMPARISON";
94
+ id: string;
95
+ typeName: "PRESS_RELEASE" | "PRODUCT_VISION" | "PRODUCT_REQUIREMENTS" | "MARKET_COMPARISON";
99
96
  agent?: AgentResponse;
100
- description?: string;
97
+ description: string;
98
+ createdAt?: string;
99
+ };
100
+ export type DocumentVersionSummaryResponse = {
101
+ id: string;
102
+ name: string;
101
103
  createdAt?: string;
104
+ createdBy?: string;
105
+ };
106
+ export type DocumentUploadResponse = {
107
+ id: string;
108
+ name: string;
109
+ description: string;
110
+ "type": DocumentTypeResponse;
111
+ origin: "AI" | "UPLOAD";
112
+ createdAt?: string;
113
+ createdBy: string;
114
+ version: DocumentVersionSummaryResponse;
115
+ };
116
+ export type DocumentAttachRequest = {
117
+ documentIds: string[];
102
118
  };
103
119
  export type DocumentDetailContent = {
104
- hasPreview?: boolean;
120
+ hasPreview: boolean;
105
121
  content?: string;
106
122
  };
107
- export type DocumentDetailResponse = {
108
- id?: string;
109
- name?: string;
110
- description?: string;
111
- "type"?: DocumentTypeResponse;
112
- origin?: "AI" | "UPLOAD";
123
+ export type DocumentVersion = {
124
+ id: string;
125
+ name: string;
113
126
  createdAt?: string;
114
127
  createdBy?: string;
115
- details?: DocumentDetailContent;
128
+ };
129
+ export type DocumentDetailResponse = {
130
+ id: string;
131
+ name: string;
132
+ description: string;
133
+ "type": DocumentTypeResponse;
134
+ origin: "AI" | "UPLOAD";
135
+ createdAt?: string;
136
+ createdBy: string;
137
+ details: DocumentDetailContent;
138
+ version: DocumentVersion;
116
139
  };
117
140
  export type DocumentPatchRequest = {
118
- file?: Blob;
141
+ file: Blob;
119
142
  description?: string;
120
143
  name?: string;
121
144
  };
122
145
  export type PageResponseOpportunityResponse = {
123
- totalElements?: number;
124
- totalPages?: number;
125
- first?: boolean;
126
- last?: boolean;
127
- size?: number;
128
- content?: OpportunityResponse[];
129
- "number"?: number;
130
- sort?: SortResponse[];
131
- numberOfElements?: number;
132
- pageable?: PageableResponse;
133
- empty?: boolean;
146
+ totalElements: number;
147
+ totalPages: number;
148
+ first: boolean;
149
+ last: boolean;
150
+ size: number;
151
+ content: OpportunityResponse[];
152
+ "number": number;
153
+ sort: SortResponse[];
154
+ numberOfElements: number;
155
+ pageable: PageableResponse;
156
+ empty: boolean;
134
157
  };
135
158
  export type HypothesisSummaryResponse = {
136
- id?: string;
137
- name?: string;
138
- "number"?: string;
139
- status?: "TO_DO" | "PRIORITIZED" | "IN_EXPERIMENTATION" | "VALIDATED" | "DISCARDED" | "CANCELED";
159
+ id: string;
160
+ name: string;
161
+ "number": string;
162
+ status: "TO_DO" | "PRIORITIZED" | "IN_EXPERIMENTATION" | "VALIDATED" | "DISCARDED" | "CANCELED";
140
163
  };
141
164
  export type DocumentWithHypothesesResponse = {
142
- id?: string;
143
- name?: string;
165
+ id: string;
166
+ name: string;
144
167
  description?: string;
145
- origin?: "AI" | "UPLOAD";
146
- hypotheses?: HypothesisSummaryResponse[];
168
+ origin: "AI" | "UPLOAD";
169
+ hypotheses: HypothesisSummaryResponse[];
147
170
  createdAt?: string;
148
- createdBy?: string;
171
+ createdBy: string;
149
172
  };
150
173
  export type PageResponseDocumentWithHypothesesResponse = {
151
- totalElements?: number;
152
- totalPages?: number;
153
- first?: boolean;
154
- last?: boolean;
155
- size?: number;
156
- content?: DocumentWithHypothesesResponse[];
157
- "number"?: number;
158
- sort?: SortResponse[];
159
- numberOfElements?: number;
160
- pageable?: PageableResponse;
161
- empty?: boolean;
174
+ totalElements: number;
175
+ totalPages: number;
176
+ first: boolean;
177
+ last: boolean;
178
+ size: number;
179
+ content: DocumentWithHypothesesResponse[];
180
+ "number": number;
181
+ sort: SortResponse[];
182
+ numberOfElements: number;
183
+ pageable: PageableResponse;
184
+ empty: boolean;
162
185
  };
163
- export type DocumentSummaryResponse = {
164
- id?: string;
165
- name?: string;
166
- description?: string;
167
- origin?: "AI" | "UPLOAD";
168
- hasMultipleHypotheses?: boolean;
186
+ export type DocumentVersionResponse = {
187
+ id: string;
188
+ documentId: string;
189
+ versionName: string;
190
+ s3VersionId: string;
169
191
  createdAt?: string;
170
192
  createdBy?: string;
171
193
  };
194
+ export type PageResponseDocumentVersionResponse = {
195
+ totalElements: number;
196
+ totalPages: number;
197
+ first: boolean;
198
+ last: boolean;
199
+ size: number;
200
+ content: DocumentVersionResponse[];
201
+ "number": number;
202
+ sort: SortResponse[];
203
+ numberOfElements: number;
204
+ pageable: PageableResponse;
205
+ empty: boolean;
206
+ };
207
+ export type DocumentSummaryResponse = {
208
+ id: string;
209
+ name: string;
210
+ description: string;
211
+ origin: "AI" | "UPLOAD";
212
+ hasMultipleHypotheses: boolean;
213
+ createdAt?: string;
214
+ createdBy: string;
215
+ };
172
216
  export type PageResponseDocumentSummaryResponse = {
173
- totalElements?: number;
174
- totalPages?: number;
175
- first?: boolean;
176
- last?: boolean;
177
- size?: number;
178
- content?: DocumentSummaryResponse[];
179
- "number"?: number;
180
- sort?: SortResponse[];
181
- numberOfElements?: number;
182
- pageable?: PageableResponse;
183
- empty?: boolean;
217
+ totalElements: number;
218
+ totalPages: number;
219
+ first: boolean;
220
+ last: boolean;
221
+ size: number;
222
+ content: DocumentSummaryResponse[];
223
+ "number": number;
224
+ sort: SortResponse[];
225
+ numberOfElements: number;
226
+ pageable: PageableResponse;
227
+ empty: boolean;
184
228
  };
185
229
  export function findHypothesisById({ hypothesisId }: {
186
230
  hypothesisId: string;
@@ -248,7 +292,10 @@ export function upload({ hypothesisId, documentUploadRequest }: {
248
292
  hypothesisId: string;
249
293
  documentUploadRequest?: DocumentUploadRequest;
250
294
  }, opts?: Oazapfts.RequestOpts) {
251
- return oazapfts.ok(oazapfts.fetchText(`/v1/documents/hypotheses/${encodeURIComponent(hypothesisId)}/upload`, oazapfts.multipart({
295
+ return oazapfts.ok(oazapfts.fetchJson<{
296
+ status: 200;
297
+ data: DocumentUploadResponse;
298
+ }>(`/v1/documents/hypotheses/${encodeURIComponent(hypothesisId)}/upload`, oazapfts.multipart({
252
299
  ...opts,
253
300
  method: "POST",
254
301
  body: documentUploadRequest
@@ -264,13 +311,16 @@ export function attach({ hypothesisId, documentAttachRequest }: {
264
311
  body: documentAttachRequest
265
312
  })));
266
313
  }
267
- export function getById({ documentId }: {
314
+ export function getById({ documentId, versionId }: {
268
315
  documentId: string;
316
+ versionId?: string;
269
317
  }, opts?: Oazapfts.RequestOpts) {
270
318
  return oazapfts.ok(oazapfts.fetchJson<{
271
319
  status: 200;
272
320
  data: DocumentDetailResponse;
273
- }>(`/v1/documents/${encodeURIComponent(documentId)}`, {
321
+ }>(`/v1/documents/${encodeURIComponent(documentId)}${QS.query(QS.explode({
322
+ versionId
323
+ }))}`, {
274
324
  ...opts
275
325
  }));
276
326
  }
@@ -334,6 +384,21 @@ export function listAllDocumentsWithHypotheses({ filter, page, size, sort, direc
334
384
  ...opts
335
385
  }));
336
386
  }
387
+ export function listVersions({ documentId, page, size }: {
388
+ documentId: string;
389
+ page?: number;
390
+ size?: number;
391
+ }, opts?: Oazapfts.RequestOpts) {
392
+ return oazapfts.ok(oazapfts.fetchJson<{
393
+ status: 200;
394
+ data: PageResponseDocumentVersionResponse;
395
+ }>(`/v1/documents/${encodeURIComponent(documentId)}/versions${QS.query(QS.explode({
396
+ page,
397
+ size
398
+ }))}`, {
399
+ ...opts
400
+ }));
401
+ }
337
402
  export function download({ documentId }: {
338
403
  documentId: string;
339
404
  }, opts?: Oazapfts.RequestOpts) {
@@ -373,6 +438,26 @@ export function getAll(opts?: Oazapfts.RequestOpts) {
373
438
  ...opts
374
439
  }));
375
440
  }
441
+ export function systemHealth(opts?: Oazapfts.RequestOpts) {
442
+ return oazapfts.ok(oazapfts.fetchJson<{
443
+ status: 200;
444
+ data: {
445
+ [key: string]: object;
446
+ };
447
+ }>("/system/health", {
448
+ ...opts
449
+ }));
450
+ }
451
+ export function health(opts?: Oazapfts.RequestOpts) {
452
+ return oazapfts.ok(oazapfts.fetchJson<{
453
+ status: 200;
454
+ data: {
455
+ [key: string]: string;
456
+ };
457
+ }>("/orchestrator/health", {
458
+ ...opts
459
+ }));
460
+ }
376
461
  export function deleteV1DocumentsByDocumentIdHypothesesAndHypothesisId({ hypothesisId, documentId }: {
377
462
  hypothesisId: string;
378
463
  documentId: string;
@@ -1,13 +1,12 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
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'
2
+ import { createToolkitToolsV1ToolkitsToolkitIdToolsPost, createToolkitV1ToolkitsPost, defaults, deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete, deleteToolkitV1ToolkitsToolkitIdDelete, editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut, getPublicToolKitsV1BuiltinToolkitGet, getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet, getToolkitV1ToolkitsToolkitIdGet, HttpValidationError, listAgentsUsingToolsV1ToolkitsToolkitIdToolsAgentsPost, 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
+ import { FetchEventStream } from '../network/types'
6
7
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
7
- import { AgentResponseWithBuiltIn, AgentToolsOpenAPIPreview, AgentVisibilityLevel } from './types'
8
- import { workspaceAiClient } from './workspace-ai'
9
-
10
- const AGENT_DEFAULT_SLUG = 'stk_code_buddy'
8
+ import { StreamedArray } from '../utils/StreamedArray'
9
+ import { AgentToolsOpenAPIPreview } from './types'
11
10
 
12
11
  class AgentToolsClient extends ReactQueryNetworkClient {
13
12
  constructor() {
@@ -27,104 +26,8 @@ class AgentToolsClient extends ReactQueryNetworkClient {
27
26
  tools = this.query(removeAuthorizationParam(getPublicToolKitsV1BuiltinToolkitGet))
28
27
 
29
28
  /**
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)
48
-
49
- /**
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
29
+ * Get list of Toolkits
76
30
  */
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
- */
128
31
  toolkits = this.query(removeAuthorizationParam(listToolkitsV1ToolkitsGet))
129
32
  /**
130
33
  * Get a toolkit by Id
@@ -159,22 +62,19 @@ class AgentToolsClient extends ReactQueryNetworkClient {
159
62
  */
160
63
  deleteToolFromToolkit = this.mutation(removeAuthorizationParam(deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete))
161
64
  /**
162
- * Previews an uploaded open api file.
65
+ * Previews an uploaded open api file as a stream where each array item is an OpenAPI operation.
66
+ */
67
+ streamUploadedAPIs = ({ fileUploadIds, signal }: { fileUploadIds: string[], signal?: AbortSignal }) => {
68
+ const promises: Promise<FetchEventStream>[] = fileUploadIds.map((id) => {
69
+ const url = `/v1/toolkits/tools/preview/${encodeURIComponent(id)}`
70
+ return this.stream(url, { signal })
71
+ })
72
+ return new StreamedArray<AgentToolsOpenAPIPreview>({ eventsPromises: promises, signal })
73
+ }
74
+ /**
75
+ * Lists the agents using the tools passed as parameter.
163
76
  */
164
- previewUploadedAPI = this.query({
165
- name: 'previewUploadedAPI',
166
- request: async (signal, params: { fileUploadId: string }) => {
167
- const url = `/v1/toolkits/tools/preview/${encodeURIComponent(params.fileUploadId)}`
168
- const events = await this.stream(url, { signal })
169
- const result: AgentToolsOpenAPIPreview[] = []
170
- for await (const event of events) {
171
- if (event.data) {
172
- result.push(JSON.parse(event.data))
173
- }
174
- }
175
- return result
176
- },
177
- })
77
+ agentsUsingTools = this.query(removeAuthorizationParam(listAgentsUsingToolsV1ToolkitsToolkitIdToolsAgentsPost))
178
78
  }
179
79
 
180
80
  export const agentToolsClient = new AgentToolsClient()
@@ -1,8 +1,16 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { defaults, deleteV1AgentByAgentIdFavorite, getV1AgentByAgentId, getV1Agents, getV1PublicAgentByAgentId, getV1PublicAgents, postV1AgentByAgentIdFavorite, postV1AgentsTrial, putV1AgentByAgentId } from '../api/agent'
2
+ import {
3
+ defaults, deleteV1AgentByAgentIdFavorite, getV1AgentByAgentId, getV1Agents, getV1PublicAgentByAgentId, getV1PublicAgents,
4
+ postV1AgentByAgentIdFavorite, putV1AgentByAgentId,
5
+ VisibilityLevel,
6
+ } from '../api/agent'
3
7
  import apis from '../apis.json'
4
8
  import { StackspotAPIError } from '../error/StackspotAPIError'
5
9
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
10
+ import { AgentResponseWithBuiltIn, AgentVisibilityLevel } from './types'
11
+ import { workspaceAiClient } from './workspace-ai'
12
+
13
+ export const isAgentDefault = (agentSlug?: string) => agentSlug === 'stk_code_buddy'
6
14
 
7
15
  interface AgentError {
8
16
  code?: string,
@@ -28,6 +36,57 @@ class AgentClient extends ReactQueryNetworkClient {
28
36
  })
29
37
  }
30
38
 
39
+ /**
40
+ * List agents filtered by visibility.
41
+ */
42
+ allAgents = this.query({
43
+ name: 'allAgents',
44
+ request: async (signal, variables: { visibilities: AgentVisibilityLevel[] }) => {
45
+ const visibilities: VisibilityLevel[] = variables.visibilities.includes('ALL')
46
+ ? ['PERSONAL', 'SHARED', 'WORKSPACE', 'ACCOUNT', 'FAVORITE']
47
+ : variables.visibilities.filter((visibility) => visibility !== 'BUILT-IN' && visibility !== 'ALL') as VisibilityLevel[]
48
+
49
+ const shouldIncludeBuiltInAgent = variables.visibilities.includes('ALL') || variables.visibilities.includes('BUILT-IN')
50
+ const shouldFetchBuiltInAgent = shouldIncludeBuiltInAgent || variables.visibilities.includes('FAVORITE')
51
+ const shouldFetchWorkspaceAgents = variables.visibilities.includes('ALL') || variables.visibilities.includes('WORKSPACE')
52
+
53
+ const publicAgentsPromise = shouldFetchBuiltInAgent ? getV1PublicAgents({}, { signal }) : Promise.resolve([])
54
+ const workspaceAgentsPromise = shouldFetchWorkspaceAgents
55
+ ? workspaceAiClient.workspacesContentsByType.query({ contentType: 'agent' })
56
+ : Promise.resolve([])
57
+
58
+ const [publicAgents, workspaceAgents, ...agentsByVisibility] = await Promise.all([
59
+ publicAgentsPromise,
60
+ workspaceAgentsPromise,
61
+ ...visibilities.map((visibility) => getV1Agents({ visibility }, { signal })),
62
+ ])
63
+
64
+ const workspaceAgentsWithSpaceName = workspaceAgents?.flatMap(({ agents, space_name }) =>
65
+ agents?.map((agent) => ({
66
+ ...agent,
67
+ spaceName: space_name,
68
+ builtIn: publicAgents?.some(publicAgent => publicAgent.id === agent.id),
69
+ }))) as AgentResponseWithBuiltIn[]
70
+
71
+ const allAgents: AgentResponseWithBuiltIn[] = workspaceAgentsWithSpaceName || []
72
+
73
+ if (shouldIncludeBuiltInAgent) {
74
+ const builtInsAgents = publicAgents?.map((agent) => ({ ...agent, builtIn: true, visibility_level: 'BUILT-IN' }))
75
+ // @ts-ignore fixme: above, BUILT-IN is not a valid value for the enum VisibilityLevel.
76
+ allAgents.push(...builtInsAgents)
77
+ }
78
+
79
+ agentsByVisibility.forEach(agents => {
80
+ allAgents.push(...agents.map(agent => ({
81
+ ...agent,
82
+ builtIn: publicAgents?.some(publicAgent => publicAgent.id === agent.id),
83
+ })))
84
+ })
85
+
86
+ return allAgents
87
+ },
88
+ })
89
+
31
90
  /**
32
91
  * Gets an agent by id
33
92
  */
@@ -38,6 +97,18 @@ class AgentClient extends ReactQueryNetworkClient {
38
97
  : getV1AgentByAgentId({ ...variables }, { signal }),
39
98
  })
40
99
 
100
+ /**
101
+ * Gets the default agent
102
+ */
103
+ agentDefault = this.query({
104
+ name: 'agentDefault',
105
+ request: async (signal) => {
106
+ const publicAgents = await getV1PublicAgents({}, { signal })
107
+ const agentDefault = publicAgents.find((agent) => isAgentDefault(agent.slug))
108
+ return agentDefault ? { ...agentDefault, builtIn: true } : undefined
109
+ },
110
+ })
111
+
41
112
  /**
42
113
  * List commons agents
43
114
  */
@@ -67,11 +138,6 @@ class AgentClient extends ReactQueryNetworkClient {
67
138
  * Removes the resource of type Agent from the list of favorites.
68
139
  */
69
140
  removeFavoriteAgent = this.mutation(deleteV1AgentByAgentIdFavorite)
70
-
71
- /**
72
- * Create a test agent if it does not exist
73
- */
74
- createTrialAgents = this.mutation(postV1AgentsTrial)
75
141
  /**
76
142
  * Updates an agent
77
143
  */