@stack-spot/portal-network 0.179.0 → 0.179.1-beta.1

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 +305 -0
  2. package/dist/api/agent-tools.d.ts +72 -1
  3. package/dist/api/agent-tools.d.ts.map +1 -1
  4. package/dist/api/agent-tools.js +36 -1
  5. package/dist/api/agent-tools.js.map +1 -1
  6. package/dist/api/codeShift.d.ts +170 -10
  7. package/dist/api/codeShift.d.ts.map +1 -1
  8. package/dist/api/codeShift.js +97 -0
  9. package/dist/api/codeShift.js.map +1 -1
  10. package/dist/apis-itau.json +1 -1
  11. package/dist/client/agent-tools.d.ts +14 -1
  12. package/dist/client/agent-tools.d.ts.map +1 -1
  13. package/dist/client/agent-tools.js +11 -2
  14. package/dist/client/agent-tools.js.map +1 -1
  15. package/dist/client/ai.d.ts.map +1 -1
  16. package/dist/client/ai.js +69 -15
  17. package/dist/client/ai.js.map +1 -1
  18. package/dist/client/code-shift.d.ts +69 -4
  19. package/dist/client/code-shift.d.ts.map +1 -1
  20. package/dist/client/code-shift.js +55 -1
  21. package/dist/client/code-shift.js.map +1 -1
  22. package/dist/client/types.d.ts +26 -6
  23. package/dist/client/types.d.ts.map +1 -1
  24. package/dist/error/DefaultAPIError.d.ts.map +1 -1
  25. package/dist/error/DefaultAPIError.js.map +1 -1
  26. package/dist/error/StackspotAPIError.d.ts +3 -4
  27. package/dist/error/StackspotAPIError.d.ts.map +1 -1
  28. package/dist/error/StackspotAPIError.js +3 -3
  29. package/dist/error/StackspotAPIError.js.map +1 -1
  30. package/package.json +2 -2
  31. package/readme.md +1 -1
  32. package/src/api/account.ts +1 -0
  33. package/src/api/agent-tools.ts +117 -1
  34. package/src/api/agent.ts +2 -0
  35. package/src/api/codeShift.ts +368 -12
  36. package/src/api/notification.ts +2 -0
  37. package/src/apis-itau.json +1 -1
  38. package/src/client/agent-tools.ts +7 -2
  39. package/src/client/ai.ts +72 -14
  40. package/src/client/code-shift.ts +36 -0
  41. package/src/client/types.ts +27 -6
  42. package/src/error/DefaultAPIError.ts +5 -5
  43. package/src/error/StackspotAPIError.ts +4 -4
package/src/client/ai.ts CHANGED
@@ -264,7 +264,10 @@ class AIClient extends ReactQueryNetworkClient {
264
264
  if (!agent) return []
265
265
  const tools: (Omit<ChatAgentTool, 'duration' | 'prompt' | 'output'>)[] = []
266
266
  agent.toolkits?.builtin_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
267
- if (id) tools.push({ image: kit.image_url, id, name: name || id, description })
267
+ if (id) tools.push({ image: kit.image_url, id, name: name || id, description, goal: '' })
268
+ }))
269
+ agent.toolkits?.custom_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, url, description }) => {
270
+ if (id) tools.push({ image: url, id, name: name || id, description, goal: '' })
268
271
  }))
269
272
  return tools
270
273
  } catch {
@@ -293,7 +296,7 @@ class AIClient extends ReactQueryNetworkClient {
293
296
  if (!info) return
294
297
  const tools = await AIClient.toolsOfAgent(request.context?.agent_id)
295
298
  data.steps = data.steps ? [...data.steps] : []
296
-
299
+
297
300
  if (info.type === 'planning' && info.action === 'end') {
298
301
  data.steps.push({
299
302
  id: 'planning',
@@ -303,6 +306,7 @@ class AIClient extends ReactQueryNetworkClient {
303
306
  steps: info.data?.steps?.map(s => s.goal) ?? [],
304
307
  goal: info.data?.plan_goal ?? '',
305
308
  })
309
+
306
310
  info.data?.steps.forEach(s => data.steps?.push({
307
311
  id: s.id,
308
312
  type: 'step',
@@ -312,6 +316,33 @@ class AIClient extends ReactQueryNetworkClient {
312
316
  tools: s.tools?.map(t => ({
313
317
  ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
314
318
  executionId: t.tool_execution_id,
319
+ goal: t.goal,
320
+ })),
321
+ }],
322
+ }))
323
+ data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
324
+ }
325
+
326
+ if (info.type === 'planning' && info.action === 'awaiting_approval') {
327
+ data.steps.push({
328
+ id: 'planning',
329
+ type: 'planning',
330
+ status: 'awaiting_approval',
331
+ user_question: info.data?.user_question,
332
+ duration: info.duration || 0,
333
+ steps: info.data?.steps?.map(s => s.goal) ?? [],
334
+ goal: info.data?.plan_goal ?? '',
335
+ })
336
+ info.data?.steps.forEach(s => data.steps?.push({
337
+ id: s.id,
338
+ type: 'step',
339
+ status: 'pending',
340
+ input: s.goal,
341
+ attempts: [{
342
+ tools: s.tools?.map(t => ({
343
+ ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
344
+ executionId: t.tool_execution_id,
345
+ goal: t.goal,
315
346
  })),
316
347
  }],
317
348
  }))
@@ -334,20 +365,46 @@ class AIClient extends ReactQueryNetworkClient {
334
365
  }
335
366
  }
336
367
 
368
+ if (info.type === 'tool' && info.action === 'awaiting_approval') {
369
+ const tool = tools.find(({ id }) => id === info.data?.tool_id)
370
+ data.steps.push({
371
+ id: info.id,
372
+ type: 'tool',
373
+ status: 'awaiting_approval',
374
+ duration: info.duration || 0,
375
+ input: info.data?.input,
376
+ user_question: info.data?.user_question,
377
+ attempts: [{
378
+ tools: [{
379
+ executionId: info.id,
380
+ id: info.data?.tool_id ?? '',
381
+ name: tool?.name ?? '',
382
+ goal: tool?.goal ?? '',
383
+ ...tool,
384
+ }],
385
+ }],
386
+ })
387
+ data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
388
+ }
389
+
337
390
  if (info.type === 'tool' && info.action === 'start') {
338
391
  const currentStep = data.steps.find(s => s.status === 'running') as StepChatStep
339
- if (!currentStep || !info.data || !currentStep.attempts[0].tools) return
340
- const toolInFirstAttempt = currentStep.attempts[0].tools.find(t => t.executionId === info.id)
341
- if (!toolInFirstAttempt) return
342
- const input = formatJson(info.data.input)
343
- if (info.data.attempt === 0) {
344
- toolInFirstAttempt.input = input
345
- } else {
346
- currentStep.attempts[info.data.attempt] ??= { tools: [] }
347
- currentStep.attempts[info.data.attempt].tools?.push({
348
- ...toolInFirstAttempt,
349
- input,
350
- })
392
+ if (!info.data) return
393
+
394
+ //There might be a tool with status awaiting_approval, so we want to inform tool has already started
395
+ if (currentStep && currentStep.attempts?.[0].tools) {
396
+ const toolInFirstAttempt = currentStep.attempts[0].tools.find(t => t.executionId === info.id)
397
+ if (!toolInFirstAttempt) return
398
+ const input = formatJson(info.data.input)
399
+ if (info.data.attempt === 1) {
400
+ toolInFirstAttempt.input = input
401
+ } else {
402
+ currentStep.attempts[info.data.attempt] ??= { tools: [] }
403
+ currentStep.attempts[info.data.attempt].tools?.push({
404
+ ...toolInFirstAttempt,
405
+ input,
406
+ })
407
+ }
351
408
  }
352
409
  }
353
410
 
@@ -393,3 +450,4 @@ class AIClient extends ReactQueryNetworkClient {
393
450
  }
394
451
 
395
452
  export const aiClient = new AIClient()
453
+
@@ -58,6 +58,12 @@ import {
58
58
  getModuleV1ModulesModuleIdGet,
59
59
  analyticsProgramGroupsTargetDetailsV1AnalyticsProgramGroupsTargetDetailsGet,
60
60
  analyticsProgramGroupsTargetDetailsDownloadV1AnalyticsProgramGroupsTargetDetailsDownloadGet,
61
+ analyticsRepositoryTargetDetailsV1AnalyticsRepositoriesTargetDetailsGet,
62
+ analyticsRepositoryTargetDetailsDownloadV1AnalyticsRepositoriesTargetDetailsDownloadGet,
63
+ searchReposScmServiceV2ReposSearchScmPost,
64
+ importReposWithTagsScmServiceV2ReposSearchScmSearchIdPost,
65
+ searchReposScmV2V2ReposSearchScmSearchIdGet,
66
+ putCustomerRatingReportV1ReportsReportIdCustomerRatingPut,
61
67
  } from '../api/codeShift'
62
68
  import { DefaultAPIError } from '../error/DefaultAPIError'
63
69
  import { codeShiftDictionary } from '../error/dictionary/code-shift'
@@ -159,6 +165,18 @@ class CodeShift extends ReactQueryNetworkClient {
159
165
  * Downloads file with found repositories
160
166
  */
161
167
  downloadSearchRepository = this.mutation(removeAuthorizationParam(downloadSearchReposScmServiceV1ReposSearchScmSearchRepoIdDownloadGet))
168
+ /**
169
+ * Searches for repositories (v2)
170
+ */
171
+ searchRepositoryV2 = this.mutation(removeAuthorizationParam(searchReposScmServiceV2ReposSearchScmPost))
172
+ /**
173
+ * Imports repositories (v2)
174
+ */
175
+ importRepositories = this.mutation(removeAuthorizationParam(importReposWithTagsScmServiceV2ReposSearchScmSearchIdPost))
176
+ /**
177
+ * Gets repositories search by id (v2)
178
+ */
179
+ getRepositoriesBySearchId = this.query(removeAuthorizationParam(searchReposScmV2V2ReposSearchScmSearchIdGet))
162
180
  /**
163
181
  * Validate if the user has permission.
164
182
  * We do not use opa in this api, so this is the fn needed to check permissions.
@@ -330,6 +348,24 @@ class CodeShift extends ReactQueryNetworkClient {
330
348
  analyticsProgramGroupsTargetDetailsDownload = this.query(
331
349
  removeAuthorizationParam(analyticsProgramGroupsTargetDetailsDownloadV1AnalyticsProgramGroupsTargetDetailsDownloadGet),
332
350
  )
351
+ /**
352
+ * Analytics Repository Target Details
353
+ */
354
+ analyticsRepositoryTargetDetails = this.query(
355
+ removeAuthorizationParam(analyticsRepositoryTargetDetailsV1AnalyticsRepositoriesTargetDetailsGet),
356
+ )
357
+ /**
358
+ * Analytics Repository Target Details Download
359
+ */
360
+ analyticsRepositoryTargetDetailsDownload = this.query(
361
+ removeAuthorizationParam(analyticsRepositoryTargetDetailsDownloadV1AnalyticsRepositoriesTargetDetailsDownloadGet),
362
+ )
363
+ /**
364
+ * Put Customer Rating Report
365
+ */
366
+ updateReportRating = this.mutation(
367
+ removeAuthorizationParam(putCustomerRatingReportV1ReportsReportIdCustomerRatingPut),
368
+ )
333
369
  }
334
370
 
335
371
  export const codeShiftClient = new CodeShift()
@@ -245,19 +245,20 @@ export interface ChatAgentTool {
245
245
  image?: string,
246
246
  input?: string,
247
247
  output?: string,
248
+ goal: string,
248
249
  }
249
250
 
250
251
  export interface ChatStepAttempt {
251
252
  /**
252
253
  * The tools used by this step.
253
254
  */
254
- tools?: ChatAgentTool[],
255
+ tools?: Partial<ChatAgentTool>[],
255
256
  }
256
257
 
257
258
  export interface BaseChatStep {
258
259
  id: string,
259
- type: 'planning' | 'step' | 'answer',
260
- status: 'pending' | 'running' | 'success' | 'error',
260
+ type: 'planning' | 'step' | 'answer' | 'tool',
261
+ status: 'pending' | 'running' | 'success' | 'error' | 'awaiting_approval',
261
262
  /**
262
263
  * Duration in seconds.
263
264
  */
@@ -266,9 +267,24 @@ export interface BaseChatStep {
266
267
 
267
268
  export interface PlanningChatStep extends BaseChatStep {
268
269
  type: 'planning',
269
- status: 'success',
270
+ status: 'success' | 'awaiting_approval',
270
271
  steps: string[],
271
272
  goal: string,
273
+ user_question?: string,
274
+ }
275
+
276
+ export interface ToolChatStep extends BaseChatStep {
277
+ type: 'tool',
278
+ status: 'running' | 'success' | 'error' | 'awaiting_approval',
279
+ /**
280
+ * Each step might attempt to run for multiple times, with different inputs and outputs. If first attempt succeeds, this array will have
281
+ * only one element.
282
+ *
283
+ * This array never has less than one element, despite the step's status.
284
+ */
285
+ attempts: ChatStepAttempt[],
286
+ input?: Record<string, any>,
287
+ user_question?: string,
272
288
  }
273
289
 
274
290
  export interface StepChatStep extends BaseChatStep {
@@ -288,17 +304,19 @@ export interface AnswerChatStep extends BaseChatStep {
288
304
  type: 'answer',
289
305
  }
290
306
 
291
- export type ChatStep = PlanningChatStep | StepChatStep | AnswerChatStep
307
+ export type ChatStep = PlanningChatStep | StepChatStep | AnswerChatStep | ToolChatStep
292
308
 
293
309
  export interface BaseAgentInfo {
294
310
  type: 'chat' | 'planning' | 'step' | 'tool' | 'final_answer',
295
- action: 'start' | 'end',
311
+ action: 'start' | 'end' | 'awaiting_approval',
296
312
  duration?: number,
313
+ id: string,
297
314
  }
298
315
 
299
316
  export interface AgentTool {
300
317
  tool_id: string,
301
318
  tool_execution_id: string,
319
+ goal: string,
302
320
  }
303
321
 
304
322
  export interface PlanningAgentInfo extends BaseAgentInfo {
@@ -311,6 +329,7 @@ export interface PlanningAgentInfo extends BaseAgentInfo {
311
329
  goal: string,
312
330
  tools?: AgentTool[],
313
331
  }[],
332
+ user_question?: string,
314
333
  },
315
334
  }
316
335
 
@@ -326,6 +345,8 @@ export interface ToolAgentInfo extends BaseAgentInfo {
326
345
  input?: any,
327
346
  attempt: number,
328
347
  output?: string,
348
+ user_question?: string,
349
+ tool_id: string,
329
350
  },
330
351
  }
331
352
 
@@ -1,4 +1,4 @@
1
- import { Dictionary, Language } from '@stack-spot/portal-translate'
1
+ import { Dictionary } from '@stack-spot/portal-translate'
2
2
  import { every, isString } from 'lodash'
3
3
  import { actionDetails } from './dictionary/action-details'
4
4
  import { baseDictionary } from './dictionary/base'
@@ -24,7 +24,7 @@ const detailsDictionary = {
24
24
  actionapi: actionDetails,
25
25
  }
26
26
 
27
- function getTitle(status: number, raw: ErrorResponse, dictionary: Dictionary, language: Language) {
27
+ function getTitle(status: number, raw: ErrorResponse, dictionary: Dictionary, language: 'pt' | 'en') {
28
28
  if (ignoredTitleErrorCodes.includes(raw.code)) return ' '
29
29
  if (dictionary[language][raw.code]) return dictionary[language][raw.code]
30
30
  if (raw.details && !ignoredDescriptions.includes(raw.details)) return raw.details
@@ -35,8 +35,8 @@ function getValues(detail: ValidationDetails) {
35
35
  return detail.values && every(detail.values, isString) ? `\n${detail.values.join('\n')}` : ''
36
36
  }
37
37
 
38
- function getSuggestedMessages(suggestedMessage: ErrorResponse['suggestedMessages'] | null | undefined, language?: Language) {
39
- const parseLanguage: Record<Language, LanguageSuggestedMessageKeys> = { pt: 'ptBr', en: 'enUs' }
38
+ function getSuggestedMessages(suggestedMessage: ErrorResponse['suggestedMessages'] | null | undefined, language?: 'pt' | 'en') {
39
+ const parseLanguage: Record<'pt' | 'en', LanguageSuggestedMessageKeys> = { pt: 'ptBr', en: 'enUs' }
40
40
  return suggestedMessage?.[parseLanguage?.[language || 'en']]
41
41
  }
42
42
 
@@ -60,7 +60,7 @@ export function interpolateErrors(message: string, values: string[], fieldValues
60
60
  }
61
61
 
62
62
 
63
- function createMessage(status: number, raw: ErrorResponse, dictionary: Dictionary, language?: Language): ErrorDetailsProperties {
63
+ function createMessage(status: number, raw: ErrorResponse, dictionary: Dictionary, language?: 'pt' | 'en'): ErrorDetailsProperties {
64
64
  const title = getTitle(status, raw, dictionary, language || 'en')
65
65
  const api = raw.code?.split(/[-_]/)[0]
66
66
  const dictDetails = (detailsDictionary[api?.toLowerCase() as keyof typeof detailsDictionary] ?? {})[language || 'en']
@@ -1,6 +1,6 @@
1
- import { Language, getLanguage } from '@stack-spot/portal-translate'
1
+ import { getLanguage, ptEn } from '@stack-spot/portal-translate'
2
2
 
3
- export type InternationalizedMessage = (language: Language) => string | ErrorDetailsProperties
3
+ export type InternationalizedMessage = (language: 'pt' | 'en') => string | ErrorDetailsProperties
4
4
 
5
5
  export interface ErrorDetailsProperties {
6
6
  /**
@@ -81,7 +81,7 @@ export class StackspotAPIError extends Error {
81
81
  * @param language
82
82
  * @returns an error message
83
83
  */
84
- translate(language: Language = getLanguage()): string {
84
+ translate(language = getLanguage(ptEn)): string {
85
85
  const unknown = language === 'en' ? 'unknown error' : 'erro desconhecido'
86
86
 
87
87
  const error = this.intl?.(language)
@@ -89,7 +89,7 @@ export class StackspotAPIError extends Error {
89
89
  return message ?? this.message ?? this.code ?? (this.status === 0 ? unknown : `${this.status}`)
90
90
  }
91
91
 
92
- translateDetails(language: Language = getLanguage()): ErrorDetailsProperties {
92
+ translateDetails(language = getLanguage(ptEn)): ErrorDetailsProperties {
93
93
  const unknown = language === 'en' ? 'unknown error' : 'erro desconhecido'
94
94
  const errorMessage = this.intl?.(language)
95
95
  if (typeof errorMessage === 'string')