@stack-spot/portal-network 0.226.0 → 0.228.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.
- package/CHANGELOG.md +14 -0
- package/dist/api/ai.d.ts +84 -8
- package/dist/api/ai.d.ts.map +1 -1
- package/dist/api/ai.js +68 -5
- package/dist/api/ai.js.map +1 -1
- package/dist/client/agent-tools.d.ts +3 -14
- package/dist/client/agent-tools.d.ts.map +1 -1
- package/dist/client/agent-tools.js +7 -25
- package/dist/client/agent-tools.js.map +1 -1
- package/dist/client/ai.d.ts +29 -0
- package/dist/client/ai.d.ts.map +1 -1
- package/dist/client/ai.js +38 -7
- package/dist/client/ai.js.map +1 -1
- package/dist/client/types.d.ts +2 -2
- package/dist/client/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/ai.ts +165 -10
- package/src/client/agent-tools.ts +8 -23
- package/src/client/ai.ts +58 -37
- package/src/client/types.ts +2 -2
package/src/client/ai.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
deleteResourceReviewV1ResourcesResourceTypeSlugResourceSlugReviewsReviewIdDelete,
|
|
24
24
|
deleteReviewCommentV1ResourcesResourceTypeSlugResourceSlugReviewsReviewIdAnswersAnswerIdDelete,
|
|
25
25
|
downloadConversationV1ConversationsConversationIdDownloadGet,
|
|
26
|
+
exportAllContentsV1ExportContentsPost,
|
|
26
27
|
findKnowledgeObjectByCustomIdV1KnowledgeSourcesSlugObjectsCustomIdGet,
|
|
27
28
|
findKnowledgeSourceDependenciesV1KnowledgeSourcesSlugDependenciesGet,
|
|
28
29
|
findKnowledgeSourceV1KnowledgeSourcesSlugGet,
|
|
@@ -30,6 +31,8 @@ import {
|
|
|
30
31
|
formatFetchStepV1QuickCommandsSlugStepsStepSlugFetchFormatPost,
|
|
31
32
|
formatResultV1QuickCommandsSlugResultFormatPost,
|
|
32
33
|
getContentDependenciesV1ContentContentTypeContentIdDependenciesGet,
|
|
34
|
+
getExportContentsByAccountIdV1ExportContentsGet,
|
|
35
|
+
getExportContentsByIdV1ExportContentsIdGet,
|
|
33
36
|
getFlagsV1FlagsGet,
|
|
34
37
|
getQuickCommandV1QuickCommandsSlugGet,
|
|
35
38
|
getReviewsByResourceV1ResourcesResourceTypeSlugResourceSlugReviewsGet,
|
|
@@ -380,7 +383,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
380
383
|
async runRouterStep(
|
|
381
384
|
ctx: QCContextExecution,
|
|
382
385
|
stepIndex: number, iteration: Record<string, number>,
|
|
383
|
-
progress?:QCProgressProps,
|
|
386
|
+
progress?: QCProgressProps,
|
|
384
387
|
) {
|
|
385
388
|
const { qc: { slug, steps }, code, resultMap, customInputs } = ctx
|
|
386
389
|
const step = steps![stepIndex]
|
|
@@ -402,7 +405,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
402
405
|
slugs_executions: resultMap,
|
|
403
406
|
},
|
|
404
407
|
})
|
|
405
|
-
|
|
408
|
+
|
|
406
409
|
progress?.onStepChange?.({ step: step.slug, ...resultMap, ...{ statusResult: 'END' } })
|
|
407
410
|
|
|
408
411
|
if (next_step_slug === step.slug) {
|
|
@@ -415,14 +418,14 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
415
418
|
return aiClient.runStepsRecursively(nextStepIndex, ctx, iteration, progress)
|
|
416
419
|
}
|
|
417
420
|
catch (error: any) {
|
|
418
|
-
progress?.onStepChange?.({
|
|
419
|
-
step: step.slug, error: error, answer: JSON.stringify(error.message), statusResult: 'ERROR', ...resultMap,
|
|
421
|
+
progress?.onStepChange?.({
|
|
422
|
+
step: step.slug, error: error, answer: JSON.stringify(error.message), statusResult: 'ERROR', ...resultMap,
|
|
420
423
|
})
|
|
421
424
|
// eslint-disable-next-line no-console
|
|
422
425
|
console.error('Error executing QC step', error)
|
|
423
426
|
}
|
|
424
427
|
}
|
|
425
|
-
|
|
428
|
+
|
|
426
429
|
async getScriptStepStatus(
|
|
427
430
|
scriptExecutionId: string,
|
|
428
431
|
interval = 5000,
|
|
@@ -434,7 +437,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
434
437
|
}
|
|
435
438
|
await aiClient.getStatusScriptStep.invalidate({ scriptExecutionId })
|
|
436
439
|
const response = await aiClient.getStatusScriptStep.query({ scriptExecutionId })
|
|
437
|
-
|
|
440
|
+
|
|
438
441
|
if (response.status === 'success') {
|
|
439
442
|
return response
|
|
440
443
|
}
|
|
@@ -443,7 +446,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
443
446
|
throw response
|
|
444
447
|
}
|
|
445
448
|
|
|
446
|
-
await new Promise(resolve => {setTimeout(resolve, interval)})
|
|
449
|
+
await new Promise(resolve => { setTimeout(resolve, interval) })
|
|
447
450
|
|
|
448
451
|
return aiClient.getScriptStepStatus(scriptExecutionId, interval, maxAttempts, currentAttempt + 1)
|
|
449
452
|
}
|
|
@@ -454,7 +457,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
454
457
|
const { qc: { slug, steps }, code, context, resultMap, customInputs, executionId, signal } = ctx
|
|
455
458
|
const step = steps![stepIndex] as QuickCommandStepFetchResponse
|
|
456
459
|
progress?.onStepChange?.({ step: step.slug, ...resultMap, answer: undefined, statusResult: 'START' })
|
|
457
|
-
|
|
460
|
+
|
|
458
461
|
//If is_remote we call backend to execute for us and we only have the response
|
|
459
462
|
if (step.is_remote) {
|
|
460
463
|
ctx.isRemote = true
|
|
@@ -470,8 +473,9 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
470
473
|
//data is the return of the request in the QC so we do not have full control over the response
|
|
471
474
|
//We handle the usual format with body, status_code and headers, but we might also handle other formats
|
|
472
475
|
const responseData = data as any
|
|
473
|
-
progress?.onStepChange?.({
|
|
474
|
-
step: step.slug, ...resultMap, answer: JSON.stringify(responseData.body) ?? JSON.stringify(responseData), statusResult: 'END'
|
|
476
|
+
progress?.onStepChange?.({
|
|
477
|
+
step: step.slug, ...resultMap, answer: JSON.stringify(responseData.body) ?? JSON.stringify(responseData), statusResult: 'END',
|
|
478
|
+
})
|
|
475
479
|
resultMap[step.slug] = {
|
|
476
480
|
status: responseData.status_code || 200,
|
|
477
481
|
data: JSON.stringify(responseData.body) ?? JSON.stringify(responseData),
|
|
@@ -484,7 +488,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
484
488
|
throw new Error(errorMessage)
|
|
485
489
|
}
|
|
486
490
|
}
|
|
487
|
-
|
|
491
|
+
|
|
488
492
|
const { headers, data, method, url } = await aiClient.fetchStepOfQuickCommand.mutate({
|
|
489
493
|
slug,
|
|
490
494
|
stepSlug: step.slug,
|
|
@@ -494,9 +498,9 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
494
498
|
},
|
|
495
499
|
}, signal)
|
|
496
500
|
const body = ['get', 'head'].includes(method.toLowerCase()) ? undefined : data
|
|
497
|
-
|
|
501
|
+
|
|
498
502
|
try {
|
|
499
|
-
|
|
503
|
+
//Local execution
|
|
500
504
|
const response = await fetch(url, { headers: headers || undefined, body, method, signal })
|
|
501
505
|
const responseData = await response.text()
|
|
502
506
|
if (!response.ok) throw new Error(`Failed to execute step "${step.slug}" of quick command "${slug}". Status ${response.status}.`)
|
|
@@ -531,8 +535,8 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
531
535
|
}
|
|
532
536
|
// eslint-disable-next-line no-async-promise-executor
|
|
533
537
|
return new Promise(async (resolve) => {
|
|
534
|
-
progress?.onStepChange?.({
|
|
535
|
-
|
|
538
|
+
progress?.onStepChange?.({ step: step.slug, ...resultMap, answer: undefined, statusResult: 'START' })
|
|
539
|
+
|
|
536
540
|
const stream = aiClient.streamLlmStepOfQuickCommand(
|
|
537
541
|
slug,
|
|
538
542
|
step.slug,
|
|
@@ -548,20 +552,22 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
548
552
|
|
|
549
553
|
stream.onChange(item => {
|
|
550
554
|
if (item?.sources?.length) {
|
|
551
|
-
progress?.onStepChange?.({
|
|
555
|
+
progress?.onStepChange?.({ step: step.slug, ...resultMap, sources: JSON.stringify(item.sources) })
|
|
552
556
|
} else {
|
|
553
|
-
item.answer !== undefined && progress?.onStepChange?.({
|
|
557
|
+
item.answer !== undefined && progress?.onStepChange?.({ step: step.slug, ...resultMap, answer: item.answer })
|
|
554
558
|
}
|
|
555
559
|
})
|
|
556
|
-
|
|
560
|
+
|
|
557
561
|
try {
|
|
558
562
|
const finalValue = await stream.getValue()
|
|
559
563
|
resultMap[step.slug] = finalValue
|
|
560
|
-
progress?.onStepChange?.({
|
|
561
|
-
|
|
564
|
+
progress?.onStepChange?.({
|
|
565
|
+
step: step.slug, ...resultMap, answer: finalValue.answer,
|
|
566
|
+
sources: finalValue.sources ? JSON.stringify(finalValue.sources) : '', statusResult: 'END',
|
|
567
|
+
})
|
|
562
568
|
resolve(finalValue)
|
|
563
569
|
} catch (error: any) {
|
|
564
|
-
|
|
570
|
+
// eslint-disable-next-line no-console
|
|
565
571
|
console.error('Error executing QC step', error)
|
|
566
572
|
const errorStep = `Failed to execute step "${step.slug}" of quick command "${slug}". Reason: ${error.message}`
|
|
567
573
|
progress?.onStepChange?.({ step: step.slug, ...resultMap, answer: errorStep, error: errorStep, statusResult: 'ERROR' })
|
|
@@ -607,15 +613,15 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
607
613
|
}
|
|
608
614
|
}
|
|
609
615
|
|
|
610
|
-
async runStepsRecursively(currentIndex: number, ctx: QCContextExecution, iteration: Record<string, number>,
|
|
616
|
+
async runStepsRecursively(currentIndex: number, ctx: QCContextExecution, iteration: Record<string, number>,
|
|
611
617
|
progress?: QCProgressProps) {
|
|
612
618
|
const { qc, resultMap } = ctx
|
|
613
619
|
|
|
614
620
|
if (!qc.steps || currentIndex >= qc.steps?.length) return
|
|
615
621
|
progress?.update?.(currentIndex)
|
|
616
|
-
|
|
622
|
+
|
|
617
623
|
const currentStep = qc.steps[currentIndex]
|
|
618
|
-
|
|
624
|
+
|
|
619
625
|
if (currentStep.type === 'ROUTER') {
|
|
620
626
|
await aiClient.runRouterStep(ctx, currentIndex, iteration, progress)
|
|
621
627
|
return
|
|
@@ -624,17 +630,19 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
624
630
|
const parsedStep = currentStep as QuickCommandStepFetchResponse | QuickCommandStepLlmResponse
|
|
625
631
|
let nextIndex = currentIndex + 1
|
|
626
632
|
let nextStepSlug = parsedStep.next_step_slug
|
|
627
|
-
|
|
633
|
+
|
|
628
634
|
if (currentStep.type === 'SCRIPT') {
|
|
629
635
|
await aiClient.runScriptStep(ctx, currentIndex, progress)
|
|
630
636
|
} else if (currentStep.type === 'FETCH') {
|
|
631
|
-
await aiClient.runFetchStep(ctx, currentIndex, progress)
|
|
637
|
+
await aiClient.runFetchStep(ctx, currentIndex, progress)
|
|
632
638
|
} else {
|
|
633
639
|
try {
|
|
634
640
|
await aiClient.runLLMStep(ctx, currentIndex, progress)
|
|
635
641
|
} catch (error: any) {
|
|
636
|
-
progress?.onStepChange?.({
|
|
637
|
-
|
|
642
|
+
progress?.onStepChange?.({
|
|
643
|
+
step: currentStep.slug,
|
|
644
|
+
error: error, answer: JSON.stringify(error), statusResult: 'ERROR', ...resultMap,
|
|
645
|
+
})
|
|
638
646
|
}
|
|
639
647
|
const stepResult = resultMap[currentStep.slug] as QuickCommandPromptResponse
|
|
640
648
|
|
|
@@ -642,13 +650,14 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
642
650
|
if (typeof stepResult !== 'string' && stepResult.answer_status?.next_step_slug) {
|
|
643
651
|
nextStepSlug = stepResult?.answer_status?.next_step_slug
|
|
644
652
|
} else if (!stepResult?.answer_status?.success) { //When we have an error but no error path defined we should fail the execution
|
|
645
|
-
progress?.onStepChange?.({
|
|
646
|
-
step: currentStep.slug, error: stepResult?.answer_status,
|
|
647
|
-
answer: JSON.stringify(stepResult?.answer_status?.failure_message), statusResult: 'ERROR', ...resultMap
|
|
653
|
+
progress?.onStepChange?.({
|
|
654
|
+
step: currentStep.slug, error: stepResult?.answer_status,
|
|
655
|
+
answer: JSON.stringify(stepResult?.answer_status?.failure_message), statusResult: 'ERROR', ...resultMap,
|
|
656
|
+
})
|
|
648
657
|
throw new Error()
|
|
649
658
|
}
|
|
650
659
|
}
|
|
651
|
-
|
|
660
|
+
|
|
652
661
|
const stepResult = ctx.resultMap[currentStep.slug]
|
|
653
662
|
if (stepResult && typeof stepResult !== 'string' && 'answer_status' in stepResult && !!stepResult.answer_status?.next_step_slug) {
|
|
654
663
|
nextStepSlug = stepResult.answer_status.next_step_slug
|
|
@@ -660,7 +669,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
660
669
|
}
|
|
661
670
|
await aiClient.runStepsRecursively(nextIndex, ctx, iteration, progress)
|
|
662
671
|
}
|
|
663
|
-
|
|
672
|
+
|
|
664
673
|
async formatResult({ qc, code, executionId, context, resultMap, customInputs, signal }: QCContextExecution) {
|
|
665
674
|
const formatted = await aiClient.formatResultOfQuickCommand.mutate({
|
|
666
675
|
slug: qc.slug,
|
|
@@ -670,7 +679,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
670
679
|
qc_execution_id: executionId,
|
|
671
680
|
slugs_executions: { ...resultMap, ...customInputs },
|
|
672
681
|
},
|
|
673
|
-
|
|
682
|
+
|
|
674
683
|
}, signal)
|
|
675
684
|
return formatted.result
|
|
676
685
|
}
|
|
@@ -678,7 +687,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
678
687
|
/**
|
|
679
688
|
* This registers a quick command event in the backend (analytics).
|
|
680
689
|
*/
|
|
681
|
-
private async registerQCAnalyticsEvent({
|
|
690
|
+
private async registerQCAnalyticsEvent({
|
|
682
691
|
qc, isRemote, executionId, code = '', context }: QCContextExecution, status: string, start: number) {
|
|
683
692
|
const now = new Date().getTime()
|
|
684
693
|
try {
|
|
@@ -706,7 +715,7 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
706
715
|
console.warn('Failed to register event: quick command.')
|
|
707
716
|
}
|
|
708
717
|
}
|
|
709
|
-
|
|
718
|
+
|
|
710
719
|
async runQuickCommand(ctx: QCContext, progress?: QCProgressProps) {
|
|
711
720
|
const start = new Date().getTime()
|
|
712
721
|
|
|
@@ -733,7 +742,19 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
733
742
|
FixedDependencyResponse
|
|
734
743
|
>,
|
|
735
744
|
))
|
|
736
|
-
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Exports all contents.
|
|
748
|
+
*/
|
|
749
|
+
exportAllContents = this.mutation(removeAuthorizationParam(exportAllContentsV1ExportContentsPost))
|
|
750
|
+
/**
|
|
751
|
+
* Get Export Contents By Account Id
|
|
752
|
+
*/
|
|
753
|
+
getExportContentsByAccountId = this.query(removeAuthorizationParam(getExportContentsByAccountIdV1ExportContentsGet))
|
|
754
|
+
/**
|
|
755
|
+
* Get Export Contents By Id
|
|
756
|
+
*/
|
|
757
|
+
getExportContentsById = this.query(removeAuthorizationParam(getExportContentsByIdV1ExportContentsIdGet))
|
|
737
758
|
}
|
|
738
759
|
|
|
739
760
|
export const aiClient = new AIClient()
|
package/src/client/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RequestOpts } from '@oazapfts/runtime'
|
|
2
2
|
import { AccountScmInfoSaveRequest, AccountScmInfoUpdateRequest, AccountScmStatusResponse, GroupsFromResourceResponse, MembersFromResourceResponse } from '../api/account'
|
|
3
|
-
import { AgentVisibilityLevelEnum, HttpMethod,
|
|
3
|
+
import { AgentVisibilityLevelEnum, HttpMethod, ListAgentCoreResponse, VisibilityLevelEnum } from '../api/agent-tools'
|
|
4
4
|
import { ChatResponse3, ContentDependencyResponse, ConversationHistoryResponse, ConversationResponse, DependencyResponse, QuickCommandResponse, QuickCommandStepResult, SourceKnowledgeSource, SourceProjectFile3, SourceStackAi } from '../api/ai'
|
|
5
5
|
import { ConnectAccountRequestV2, ManagedAccountProvisionRequest } from '../api/cloudAccount'
|
|
6
6
|
import { AllocationCostRequest, AllocationCostResponse, ChargePeriod, getAllocationCostFilters, ManagedService, ServiceResource } from '../api/cloudServices'
|
|
@@ -405,7 +405,7 @@ export type FixVariables<
|
|
|
405
405
|
|
|
406
406
|
export type ReplaceResult<T extends (...args: any[]) => Promise<any>, Fix> = (...args: Parameters<T>) => Promise<Fix>
|
|
407
407
|
|
|
408
|
-
export interface AgentResponseWithBuiltIn extends Omit<
|
|
408
|
+
export interface AgentResponseWithBuiltIn extends Omit<ListAgentCoreResponse, 'conversation_starter' | 'avatar'> {
|
|
409
409
|
builtIn?: boolean,
|
|
410
410
|
spaceName?: string,
|
|
411
411
|
conversation_starter?: string[] | null,
|