@stack-spot/portal-network 0.227.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 +7 -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/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/package.json +1 -1
- package/src/api/ai.ts +165 -10
- package/src/client/ai.ts +58 -37
package/src/api/ai.ts
CHANGED
|
@@ -469,6 +469,8 @@ export type QuickCommandsCreateRequest = {
|
|
|
469
469
|
} | null;
|
|
470
470
|
share_context_between_steps?: boolean | null;
|
|
471
471
|
};
|
|
472
|
+
export type OrderDirection = "ASC" | "DESC";
|
|
473
|
+
export type OrderByFields = "name" | "visibility_level" | "username" | "created" | "type";
|
|
472
474
|
export type QuickCommandAccountListResponseV1 = {
|
|
473
475
|
name: string;
|
|
474
476
|
username: string;
|
|
@@ -486,7 +488,7 @@ export type PaginatedResponseQuickCommandAccountListResponseV1 = {
|
|
|
486
488
|
export type QuickCommandsUpdateRequest = {
|
|
487
489
|
name?: string | null;
|
|
488
490
|
description?: string | null;
|
|
489
|
-
steps?: (QuickCommandsStepFetchRequest | QuickCommandsStepPromptRequest | QuickCommandsStepRouterRequest | QuickCommandsStepScriptRequest)[] | null;
|
|
491
|
+
steps?: (QuickCommandsStepFetchRequest | QuickCommandsStepPromptRequest | QuickCommandsStepRouterRequest | QuickCommandsStepScriptRequest | QuickCommandsStepParallelStartRequest | QuickCommandsStepParallelEndRequest)[] | null;
|
|
490
492
|
return_type?: QuickCommandsReturnType | null;
|
|
491
493
|
knowledge_source_slugs?: string[] | null;
|
|
492
494
|
final_result?: string | null;
|
|
@@ -544,6 +546,7 @@ export type AgentDefinitionResponse = {
|
|
|
544
546
|
created_at: string;
|
|
545
547
|
updated_by?: string | null;
|
|
546
548
|
updated_at?: string | null;
|
|
549
|
+
version_number?: number | null;
|
|
547
550
|
};
|
|
548
551
|
export type QuickCommandStepLlmResponse = {
|
|
549
552
|
slug: string;
|
|
@@ -559,6 +562,7 @@ export type QuickCommandStepLlmResponse = {
|
|
|
559
562
|
next_failure_step_slug?: string | null;
|
|
560
563
|
use_uploaded_files?: boolean;
|
|
561
564
|
allow_use_current_workspace?: boolean;
|
|
565
|
+
agent_version_number?: number | null;
|
|
562
566
|
};
|
|
563
567
|
export type ConditionExpr2 = {
|
|
564
568
|
left?: any | null;
|
|
@@ -589,6 +593,16 @@ export type QuickCommandsStepScriptResponse = {
|
|
|
589
593
|
use_uploaded_files: boolean;
|
|
590
594
|
next_step_slug?: string | null;
|
|
591
595
|
};
|
|
596
|
+
export type QuickCommandsStepParallelStartResponse = {
|
|
597
|
+
slug: string;
|
|
598
|
+
"type": QuickCommandStepType;
|
|
599
|
+
next_steps_slugs: string[];
|
|
600
|
+
};
|
|
601
|
+
export type QuickCommandsStepParallelEndResponse = {
|
|
602
|
+
slug: string;
|
|
603
|
+
"type": QuickCommandStepType;
|
|
604
|
+
next_step_slug?: string | null;
|
|
605
|
+
};
|
|
592
606
|
export type CustomInputResponse = {
|
|
593
607
|
slug: string;
|
|
594
608
|
question: string;
|
|
@@ -602,7 +616,7 @@ export type QuickCommandResponse = {
|
|
|
602
616
|
studio_id?: string | null;
|
|
603
617
|
return_type?: QuickCommandsReturnType | null;
|
|
604
618
|
final_result?: string | null;
|
|
605
|
-
steps?: (QuickCommandStepFetchResponse | QuickCommandStepLlmResponse | QuickCommandsStepRouterResponse | QuickCommandsStepScriptResponse)[] | null;
|
|
619
|
+
steps?: (QuickCommandStepFetchResponse | QuickCommandStepLlmResponse | QuickCommandsStepRouterResponse | QuickCommandsStepScriptResponse | QuickCommandsStepParallelStartResponse | QuickCommandsStepParallelEndResponse)[] | null;
|
|
606
620
|
flow?: {
|
|
607
621
|
[key: string]: any;
|
|
608
622
|
} | null;
|
|
@@ -716,6 +730,7 @@ export type StepFetch = {
|
|
|
716
730
|
json_data?: {
|
|
717
731
|
[key: string]: any;
|
|
718
732
|
} | null;
|
|
733
|
+
failure_message?: string | null;
|
|
719
734
|
};
|
|
720
735
|
export type AnswerStatus = {
|
|
721
736
|
success: boolean;
|
|
@@ -730,12 +745,14 @@ export type StepLlm = {
|
|
|
730
745
|
answer_status?: AnswerStatus | null;
|
|
731
746
|
sources: (SourceStackAi | SourceKnowledgeSource | SourceProjectFile | KnowledgeSourceEvent)[];
|
|
732
747
|
tools?: string[];
|
|
748
|
+
failure_message?: string | null;
|
|
733
749
|
};
|
|
734
750
|
export type StepRouter = {
|
|
735
751
|
duration?: number | null;
|
|
736
752
|
next_step_slug: string;
|
|
737
753
|
condition?: ConditionExpr2 | null;
|
|
738
754
|
"default"?: boolean;
|
|
755
|
+
failure_message?: string | null;
|
|
739
756
|
};
|
|
740
757
|
export type StepScript = {
|
|
741
758
|
duration?: number | null;
|
|
@@ -745,12 +762,23 @@ export type StepScript = {
|
|
|
745
762
|
} | null;
|
|
746
763
|
logs?: string | null;
|
|
747
764
|
started?: string | null;
|
|
765
|
+
failure_message?: string | null;
|
|
766
|
+
};
|
|
767
|
+
export type StepParallelEnd = {
|
|
768
|
+
duration?: number | null;
|
|
769
|
+
message: string;
|
|
770
|
+
pending_branches: number;
|
|
771
|
+
total_branches: number;
|
|
772
|
+
error?: {
|
|
773
|
+
[key: string]: string;
|
|
774
|
+
} | null;
|
|
775
|
+
failure_message?: string | null;
|
|
748
776
|
};
|
|
749
777
|
export type Step = {
|
|
750
778
|
step_name: string;
|
|
751
779
|
execution_order: number;
|
|
752
780
|
"type": QuickCommandStepType;
|
|
753
|
-
step_result: StepFetch | StepLlm | StepRouter | StepScript | null;
|
|
781
|
+
step_result: StepFetch | StepLlm | StepRouter | StepScript | StepParallelEnd | null;
|
|
754
782
|
status?: string;
|
|
755
783
|
};
|
|
756
784
|
export type QuickCommandExecutionResponse = {
|
|
@@ -892,6 +920,13 @@ export type ResourceReviewRequest = {
|
|
|
892
920
|
export type ReviewAnswer = {
|
|
893
921
|
answer: string;
|
|
894
922
|
};
|
|
923
|
+
export type ExportContentsResponse = {
|
|
924
|
+
id: string;
|
|
925
|
+
};
|
|
926
|
+
export type GetExportRequestsResponse = {
|
|
927
|
+
id: string;
|
|
928
|
+
status: string;
|
|
929
|
+
};
|
|
895
930
|
export type SourceProjectFile2 = {
|
|
896
931
|
"type": "project_file";
|
|
897
932
|
path: string;
|
|
@@ -2684,15 +2719,16 @@ export function listAllV1QuickCommandsAllGet({ visibility, order, types, authori
|
|
|
2684
2719
|
}));
|
|
2685
2720
|
}
|
|
2686
2721
|
/**
|
|
2687
|
-
* List All
|
|
2722
|
+
* List All Account
|
|
2688
2723
|
*/
|
|
2689
|
-
export function
|
|
2724
|
+
export function listAllAccountV1QuickCommandsAccountGet({ name, size, page, username, types, order, orderBy, authorization, xAccountId, xMemberId, xUsername }: {
|
|
2690
2725
|
name?: string | null;
|
|
2691
2726
|
size?: number;
|
|
2692
2727
|
page?: number;
|
|
2693
|
-
username?: string | null;
|
|
2694
|
-
order?: OrderEnum | null;
|
|
2728
|
+
username?: string[] | null;
|
|
2695
2729
|
types?: QuickCommandTypeRequest[] | null;
|
|
2730
|
+
order?: OrderDirection | null;
|
|
2731
|
+
orderBy?: OrderByFields | null;
|
|
2696
2732
|
authorization: string;
|
|
2697
2733
|
xAccountId?: string | null;
|
|
2698
2734
|
xMemberId?: string | null;
|
|
@@ -2711,8 +2747,9 @@ export function listAllV1QuickCommandsAccountGet({ name, size, page, username, o
|
|
|
2711
2747
|
size,
|
|
2712
2748
|
page,
|
|
2713
2749
|
username,
|
|
2750
|
+
types,
|
|
2714
2751
|
order,
|
|
2715
|
-
|
|
2752
|
+
order_by: orderBy
|
|
2716
2753
|
}))}`, {
|
|
2717
2754
|
...opts,
|
|
2718
2755
|
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
@@ -2899,11 +2936,44 @@ export function shareV1QuickCommandsSlugSharePost({ slug, isResourceAccessManage
|
|
|
2899
2936
|
})
|
|
2900
2937
|
}));
|
|
2901
2938
|
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Update Visibility
|
|
2941
|
+
*/
|
|
2942
|
+
export function updateVisibilityV1QuickCommandsSlugVisibilityPatch({ slug, visibility, authorization, xAccountId, xMemberId, xUsername }: {
|
|
2943
|
+
slug: string;
|
|
2944
|
+
visibility: VisibilityLevelEnum;
|
|
2945
|
+
authorization: string;
|
|
2946
|
+
xAccountId?: string | null;
|
|
2947
|
+
xMemberId?: string | null;
|
|
2948
|
+
xUsername?: string | null;
|
|
2949
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
2950
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
2951
|
+
status: 200;
|
|
2952
|
+
data: any;
|
|
2953
|
+
} | {
|
|
2954
|
+
status: 404;
|
|
2955
|
+
} | {
|
|
2956
|
+
status: 422;
|
|
2957
|
+
data: HttpValidationError;
|
|
2958
|
+
}>(`/v1/quick-commands/${encodeURIComponent(slug)}/visibility${QS.query(QS.explode({
|
|
2959
|
+
visibility
|
|
2960
|
+
}))}`, {
|
|
2961
|
+
...opts,
|
|
2962
|
+
method: "PATCH",
|
|
2963
|
+
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
2964
|
+
authorization,
|
|
2965
|
+
"x-account-id": xAccountId,
|
|
2966
|
+
"x-member-id": xMemberId,
|
|
2967
|
+
"x-username": xUsername
|
|
2968
|
+
})
|
|
2969
|
+
}));
|
|
2970
|
+
}
|
|
2902
2971
|
/**
|
|
2903
2972
|
* Publish
|
|
2904
2973
|
*/
|
|
2905
|
-
export function publishV1QuickCommandsSlugPublishPost({ slug, authorization, xAccountId, xMemberId, xUsername, quickCommandPublishRequest }: {
|
|
2974
|
+
export function publishV1QuickCommandsSlugPublishPost({ slug, isResourceAccessManager, authorization, xAccountId, xMemberId, xUsername, quickCommandPublishRequest }: {
|
|
2906
2975
|
slug: string;
|
|
2976
|
+
isResourceAccessManager?: boolean | null;
|
|
2907
2977
|
authorization: string;
|
|
2908
2978
|
xAccountId?: string | null;
|
|
2909
2979
|
xMemberId?: string | null;
|
|
@@ -2917,7 +2987,9 @@ export function publishV1QuickCommandsSlugPublishPost({ slug, authorization, xAc
|
|
|
2917
2987
|
} | {
|
|
2918
2988
|
status: 422;
|
|
2919
2989
|
data: HttpValidationError;
|
|
2920
|
-
}>(`/v1/quick-commands/${encodeURIComponent(slug)}/publish
|
|
2990
|
+
}>(`/v1/quick-commands/${encodeURIComponent(slug)}/publish${QS.query(QS.explode({
|
|
2991
|
+
is_resource_access_manager: isResourceAccessManager
|
|
2992
|
+
}))}`, oazapfts.json({
|
|
2921
2993
|
...opts,
|
|
2922
2994
|
method: "POST",
|
|
2923
2995
|
body: quickCommandPublishRequest,
|
|
@@ -4025,6 +4097,89 @@ export function deleteReviewCommentV1ResourcesResourceTypeSlugResourceSlugReview
|
|
|
4025
4097
|
})
|
|
4026
4098
|
}));
|
|
4027
4099
|
}
|
|
4100
|
+
/**
|
|
4101
|
+
* Export All Contents
|
|
4102
|
+
*/
|
|
4103
|
+
export function exportAllContentsV1ExportContentsPost({ authorization, xAccountId, xMemberId, xUsername }: {
|
|
4104
|
+
authorization: string;
|
|
4105
|
+
xAccountId?: string | null;
|
|
4106
|
+
xMemberId?: string | null;
|
|
4107
|
+
xUsername?: string | null;
|
|
4108
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
4109
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
4110
|
+
status: 200;
|
|
4111
|
+
data: ExportContentsResponse | null;
|
|
4112
|
+
} | {
|
|
4113
|
+
status: 404;
|
|
4114
|
+
} | {
|
|
4115
|
+
status: 422;
|
|
4116
|
+
data: HttpValidationError;
|
|
4117
|
+
}>("/v1/export-contents", {
|
|
4118
|
+
...opts,
|
|
4119
|
+
method: "POST",
|
|
4120
|
+
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
4121
|
+
authorization,
|
|
4122
|
+
"x-account-id": xAccountId,
|
|
4123
|
+
"x-member-id": xMemberId,
|
|
4124
|
+
"x-username": xUsername
|
|
4125
|
+
})
|
|
4126
|
+
}));
|
|
4127
|
+
}
|
|
4128
|
+
/**
|
|
4129
|
+
* Get Export Contents By Account Id
|
|
4130
|
+
*/
|
|
4131
|
+
export function getExportContentsByAccountIdV1ExportContentsGet({ authorization, xAccountId, xMemberId, xUsername }: {
|
|
4132
|
+
authorization: string;
|
|
4133
|
+
xAccountId?: string | null;
|
|
4134
|
+
xMemberId?: string | null;
|
|
4135
|
+
xUsername?: string | null;
|
|
4136
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
4137
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
4138
|
+
status: 200;
|
|
4139
|
+
data: GetExportRequestsResponse | null;
|
|
4140
|
+
} | {
|
|
4141
|
+
status: 404;
|
|
4142
|
+
} | {
|
|
4143
|
+
status: 422;
|
|
4144
|
+
data: HttpValidationError;
|
|
4145
|
+
}>("/v1/export-contents", {
|
|
4146
|
+
...opts,
|
|
4147
|
+
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
4148
|
+
authorization,
|
|
4149
|
+
"x-account-id": xAccountId,
|
|
4150
|
+
"x-member-id": xMemberId,
|
|
4151
|
+
"x-username": xUsername
|
|
4152
|
+
})
|
|
4153
|
+
}));
|
|
4154
|
+
}
|
|
4155
|
+
/**
|
|
4156
|
+
* Get Export Contents By Id
|
|
4157
|
+
*/
|
|
4158
|
+
export function getExportContentsByIdV1ExportContentsIdGet({ id, authorization, xAccountId, xMemberId, xUsername }: {
|
|
4159
|
+
id: string;
|
|
4160
|
+
authorization: string;
|
|
4161
|
+
xAccountId?: string | null;
|
|
4162
|
+
xMemberId?: string | null;
|
|
4163
|
+
xUsername?: string | null;
|
|
4164
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
4165
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
4166
|
+
status: 200;
|
|
4167
|
+
data: GetExportRequestsResponse | null;
|
|
4168
|
+
} | {
|
|
4169
|
+
status: 404;
|
|
4170
|
+
} | {
|
|
4171
|
+
status: 422;
|
|
4172
|
+
data: HttpValidationError;
|
|
4173
|
+
}>(`/v1/export-contents/${encodeURIComponent(id)}`, {
|
|
4174
|
+
...opts,
|
|
4175
|
+
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
4176
|
+
authorization,
|
|
4177
|
+
"x-account-id": xAccountId,
|
|
4178
|
+
"x-member-id": xMemberId,
|
|
4179
|
+
"x-username": xUsername
|
|
4180
|
+
})
|
|
4181
|
+
}));
|
|
4182
|
+
}
|
|
4028
4183
|
/**
|
|
4029
4184
|
* Dev Assistant V2
|
|
4030
4185
|
*/
|
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()
|