@stack-spot/portal-network 0.187.0 → 0.187.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.
package/src/client/ai.ts CHANGED
@@ -266,6 +266,9 @@ class AIClient extends ReactQueryNetworkClient {
266
266
  agent.toolkits?.builtin_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
267
267
  if (id) tools.push({ image: kit.image_url, id, name: name || id, description })
268
268
  }))
269
+ agent.toolkits?.custom_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
270
+ if (id) tools.push({ image: kit.avatar ?? undefined, id, name: name || id, description })
271
+ }))
269
272
  return tools
270
273
  } catch {
271
274
  return []
@@ -303,6 +306,33 @@ class AIClient extends ReactQueryNetworkClient {
303
306
  steps: info.data?.steps?.map(s => s.goal) ?? [],
304
307
  goal: info.data?.plan_goal ?? '',
305
308
  })
309
+
310
+ info.data?.steps.forEach(s => data.steps?.push({
311
+ id: s.id,
312
+ type: 'step',
313
+ status: 'pending',
314
+ input: s.goal,
315
+ attempts: [{
316
+ tools: s.tools?.map(t => ({
317
+ ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
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
+ })
306
336
  info.data?.steps.forEach(s => data.steps?.push({
307
337
  id: s.id,
308
338
  type: 'step',
@@ -312,6 +342,7 @@ class AIClient extends ReactQueryNetworkClient {
312
342
  tools: s.tools?.map(t => ({
313
343
  ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
314
344
  executionId: t.tool_execution_id,
345
+ goal: t.goal,
315
346
  })),
316
347
  }],
317
348
  }))
@@ -334,27 +365,78 @@ 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,
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 input = formatJson(info.data.input)
397
+ const tool = tools.find(({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
398
+ data.steps.push({
399
+ id: info.id,
400
+ type: 'tool',
401
+ status: 'running',
402
+ duration: info.duration || 0,
403
+ input: info.data?.input,
404
+ user_question: info.data?.user_question,
405
+ attempts: [{
406
+ tools:[{ ...tool, executionId: info.id, input }],
407
+ }],
350
408
  })
409
+ } else {
410
+ const toolInFirstAttempt = currentStep.attempts[0].tools?.find(t => t.executionId === info.id)
411
+ //One step might have multiple tools. When in an approval mode, we might not have all the tools in the array yet.
412
+ //So we make sure to add any tools that are not in there.
413
+ if (!toolInFirstAttempt) {
414
+ const input = formatJson(info.data.input)
415
+ const tool = tools?.find(({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
416
+ currentStep.attempts[info.data.attempt-1].tools?.push({
417
+ ...tool,
418
+ input,
419
+ })
420
+ } else {
421
+ const input = formatJson(info.data.input)
422
+ if (info.data.attempt === 1) {
423
+ toolInFirstAttempt.input = input
424
+ } else {
425
+ const tool = tools.find(({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
426
+ currentStep.attempts[info.data.attempt-1] ??= { tools: [] }
427
+ currentStep.attempts[info.data.attempt-1].tools?.push({
428
+ ...tool,
429
+ input,
430
+ })
431
+ }
432
+ }
351
433
  }
352
434
  }
353
435
 
354
436
  if (info.type === 'tool' && info.action === 'end') {
355
437
  const currentStep = data.steps.find(s => s.status === 'running') as StepChatStep
356
438
  if (!currentStep || !info.data) return
357
- const tool = currentStep.attempts[info.data.attempt]?.tools?.find(t => t.executionId === info.id)
439
+ const tool = currentStep.attempts[info.data.attempt-1]?.tools?.find(t => t.executionId === info.id)
358
440
  if (tool) {
359
441
  tool.output = formatJson(info.data.output)
360
442
  tool.duration = info.duration
@@ -393,3 +475,4 @@ class AIClient extends ReactQueryNetworkClient {
393
475
  }
394
476
 
395
477
  export const aiClient = new AIClient()
478
+
@@ -58,11 +58,13 @@ import {
58
58
  getModuleV1ModulesModuleIdGet,
59
59
  analyticsProgramGroupsTargetDetailsV1AnalyticsProgramGroupsTargetDetailsGet,
60
60
  analyticsProgramGroupsTargetDetailsDownloadV1AnalyticsProgramGroupsTargetDetailsDownloadGet,
61
+ putCustomerRatingReportV1ReportsReportIdCustomerRatingPut,
61
62
  searchReposScmServiceV2ReposSearchScmPost,
62
63
  importReposWithTagsScmServiceV2ReposSearchScmSearchIdPost,
63
64
  searchReposScmV2V2ReposSearchScmSearchIdGet,
64
65
  analyticsRepositoryTargetDetailsV1AnalyticsRepositoriesTargetDetailsGet,
65
66
  analyticsRepositoryTargetDetailsDownloadV1AnalyticsRepositoriesTargetDetailsDownloadGet,
67
+ updateModuleServiceV1ModulesModuleIdPut,
66
68
  } from '../api/codeShift'
67
69
  import { DefaultAPIError } from '../error/DefaultAPIError'
68
70
  import { codeShiftDictionary } from '../error/dictionary/code-shift'
@@ -128,6 +130,10 @@ class CodeShift extends ReactQueryNetworkClient {
128
130
  * Creates a module.
129
131
  */
130
132
  createModule = this.mutation(removeAuthorizationParam(createModuleServiceV1ModulesPost))
133
+ /**
134
+ * Updates a module.
135
+ */
136
+ updateModule = this.mutation(removeAuthorizationParam(updateModuleServiceV1ModulesModuleIdPut))
131
137
  /**
132
138
  * Generates a report.
133
139
  */
@@ -144,6 +150,12 @@ class CodeShift extends ReactQueryNetworkClient {
144
150
  * Downloads a report as a csv file.
145
151
  */
146
152
  downloadReport = this.query(removeAuthorizationParam(downloadReportV1ReportsReportIdDownloadGet))
153
+ /**
154
+ * Put Customer Rating Report
155
+ */
156
+ updateReportRating = this.mutation(
157
+ removeAuthorizationParam(putCustomerRatingReportV1ReportsReportIdCustomerRatingPut),
158
+ )
147
159
  /**
148
160
  * Gets code shift settings
149
161
  */
@@ -245,6 +245,7 @@ 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 {
@@ -256,8 +257,8 @@ export interface ChatStepAttempt {
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