@stack-spot/portal-network 0.218.2 → 0.219.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/agent-tools.d.ts +752 -164
- package/dist/api/agent-tools.d.ts.map +1 -1
- package/dist/api/agent-tools.js +203 -43
- package/dist/api/agent-tools.js.map +1 -1
- package/dist/api/ai.d.ts +3 -2
- package/dist/api/ai.d.ts.map +1 -1
- package/dist/api/ai.js +1 -2
- package/dist/api/ai.js.map +1 -1
- package/dist/api/genAiInference.d.ts +5 -1
- package/dist/api/genAiInference.d.ts.map +1 -1
- package/dist/api/genAiInference.js.map +1 -1
- package/dist/api/workspace-ai.d.ts +41 -0
- package/dist/api/workspace-ai.d.ts.map +1 -1
- package/dist/api/workspace-ai.js +34 -0
- package/dist/api/workspace-ai.js.map +1 -1
- package/dist/client/agent-tools.d.ts +130 -3
- package/dist/client/agent-tools.d.ts.map +1 -1
- package/dist/client/agent-tools.js +105 -2
- package/dist/client/agent-tools.js.map +1 -1
- package/dist/client/ai.d.ts +0 -1
- package/dist/client/ai.d.ts.map +1 -1
- package/dist/client/discover.d.ts +4 -4
- package/dist/client/discover.d.ts.map +1 -1
- package/dist/client/discover.js +143 -134
- package/dist/client/discover.js.map +1 -1
- package/dist/client/types.d.ts +1 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/workspace-ai.d.ts +13 -3
- package/dist/client/workspace-ai.d.ts.map +1 -1
- package/dist/client/workspace-ai.js +15 -1
- package/dist/client/workspace-ai.js.map +1 -1
- package/package.json +1 -1
- package/src/api/agent-tools.ts +1259 -472
- package/src/api/ai.ts +3 -3
- package/src/api/genAiInference.ts +5 -1
- package/src/api/workspace-ai.ts +83 -0
- package/src/client/agent-tools.ts +55 -2
- package/src/client/discover.ts +143 -135
- package/src/client/types.ts +1 -0
- package/src/client/workspace-ai.ts +18 -3
package/src/api/ai.ts
CHANGED
|
@@ -384,6 +384,7 @@ export type QuickCommandsStepPromptRequest = {
|
|
|
384
384
|
allow_use_current_workspace?: boolean;
|
|
385
385
|
knowledge_source_slugs?: string[] | null;
|
|
386
386
|
agent_id?: string | null;
|
|
387
|
+
agent_version_number?: number | null;
|
|
387
388
|
use_uploaded_files?: boolean;
|
|
388
389
|
agent_built_in?: boolean | null;
|
|
389
390
|
next_step_slug?: string | null;
|
|
@@ -871,6 +872,7 @@ export type ChatRequest = {
|
|
|
871
872
|
} | null;
|
|
872
873
|
user_prompt: string;
|
|
873
874
|
project_id?: string | null;
|
|
875
|
+
agent_version_number?: number | null;
|
|
874
876
|
};
|
|
875
877
|
export type SourceProjectFile3 = {
|
|
876
878
|
"type": "project_file";
|
|
@@ -4061,14 +4063,13 @@ export function devAssistantV3V3ChatPost({ authorization, xAccountId, xMemberId,
|
|
|
4061
4063
|
/**
|
|
4062
4064
|
* List All
|
|
4063
4065
|
*/
|
|
4064
|
-
export function listAllV3QuickCommandsGet({ name, slug, size, page, visibilityList, order,
|
|
4066
|
+
export function listAllV3QuickCommandsGet({ name, slug, size, page, visibilityList, order, types, authorization, xAccountId, xMemberId, xUsername }: {
|
|
4065
4067
|
name?: string | null;
|
|
4066
4068
|
slug?: string | null;
|
|
4067
4069
|
size?: number;
|
|
4068
4070
|
page?: number;
|
|
4069
4071
|
visibilityList?: VisibilityLevelEnum[] | null;
|
|
4070
4072
|
order?: OrderEnum | null;
|
|
4071
|
-
isRemote?: boolean;
|
|
4072
4073
|
types?: QuickCommandTypeRequest[] | null;
|
|
4073
4074
|
authorization: string;
|
|
4074
4075
|
xAccountId?: string | null;
|
|
@@ -4090,7 +4091,6 @@ export function listAllV3QuickCommandsGet({ name, slug, size, page, visibilityLi
|
|
|
4090
4091
|
page,
|
|
4091
4092
|
visibility_list: visibilityList,
|
|
4092
4093
|
order,
|
|
4093
|
-
is_remote: isRemote,
|
|
4094
4094
|
types
|
|
4095
4095
|
}))}`, {
|
|
4096
4096
|
...opts,
|
|
@@ -69,7 +69,7 @@ export type ValidationError = {
|
|
|
69
69
|
export type HttpValidationError = {
|
|
70
70
|
detail?: ValidationError[];
|
|
71
71
|
};
|
|
72
|
-
export type ResourceName = "agents" | "deep_ks" | "autocomplete";
|
|
72
|
+
export type ResourceName = "agents" | "deep_ks" | "autocomplete" | "summary";
|
|
73
73
|
export type LlmModelResourceRequest = {
|
|
74
74
|
name: ResourceName;
|
|
75
75
|
is_default?: boolean;
|
|
@@ -244,6 +244,8 @@ export type ChatCompletion = {
|
|
|
244
244
|
} | null;
|
|
245
245
|
/** ID of an alternative model for chat completion. It should be present on available_model_ids agent attr. */
|
|
246
246
|
selected_model_id?: string | null;
|
|
247
|
+
/** The specific Agent version number to be use in chat. */
|
|
248
|
+
agent_version_number?: number | null;
|
|
247
249
|
};
|
|
248
250
|
export type ChatRequest = {
|
|
249
251
|
streaming: boolean;
|
|
@@ -260,6 +262,8 @@ export type ChatRequest = {
|
|
|
260
262
|
knowledge_sources?: string[];
|
|
261
263
|
deep_search_ks?: boolean;
|
|
262
264
|
show_chat_processing_state?: boolean;
|
|
265
|
+
/** The specific Agent version number to be use in chat. */
|
|
266
|
+
agent_version_number?: number | null;
|
|
263
267
|
};
|
|
264
268
|
export type PromptTokensCurrentUsageResponse = {
|
|
265
269
|
used: number;
|
package/src/api/workspace-ai.ts
CHANGED
|
@@ -84,6 +84,13 @@ export type ListWksContentsResponse = {
|
|
|
84
84
|
[key: string]: any;
|
|
85
85
|
}[] | null;
|
|
86
86
|
};
|
|
87
|
+
export type ContentVersion = {
|
|
88
|
+
core_id: string;
|
|
89
|
+
version_number?: number | null;
|
|
90
|
+
};
|
|
91
|
+
export type AddWorkspaceContentRequestV2 = {
|
|
92
|
+
content_identifier: ContentVersion[];
|
|
93
|
+
};
|
|
87
94
|
export type ActionShared = "VIEW" | "EDIT" | "GRANT_ACESS";
|
|
88
95
|
export type PermissionForSharedRequest = {
|
|
89
96
|
userId: string;
|
|
@@ -100,6 +107,12 @@ export type ResourceMembersResponse = {
|
|
|
100
107
|
name: string;
|
|
101
108
|
actions: string[];
|
|
102
109
|
};
|
|
110
|
+
export type ResourceMembersPaginatedResponse = {
|
|
111
|
+
items: ResourceMembersResponse[];
|
|
112
|
+
page: number;
|
|
113
|
+
size: number;
|
|
114
|
+
total_pages: number;
|
|
115
|
+
};
|
|
103
116
|
/**
|
|
104
117
|
* Create Workspace
|
|
105
118
|
*/
|
|
@@ -534,6 +547,36 @@ export function listAllContentsV1WorkspacesWorkspaceIdContentsGet({ workspaceId,
|
|
|
534
547
|
})
|
|
535
548
|
}));
|
|
536
549
|
}
|
|
550
|
+
/**
|
|
551
|
+
* Add Content
|
|
552
|
+
*/
|
|
553
|
+
export function addContentV2WorkspacesWorkspaceIdContentTypePost({ workspaceId, contentType, authorization, xAccountId, addWorkspaceContentRequestV2 }: {
|
|
554
|
+
workspaceId: string;
|
|
555
|
+
contentType: ContentType;
|
|
556
|
+
authorization: string;
|
|
557
|
+
xAccountId?: string | null;
|
|
558
|
+
addWorkspaceContentRequestV2: AddWorkspaceContentRequestV2;
|
|
559
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
560
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
561
|
+
status: 200;
|
|
562
|
+
data: {
|
|
563
|
+
[key: string]: any;
|
|
564
|
+
};
|
|
565
|
+
} | {
|
|
566
|
+
status: 404;
|
|
567
|
+
} | {
|
|
568
|
+
status: 422;
|
|
569
|
+
data: HttpValidationError;
|
|
570
|
+
}>(`/v2/workspaces/${encodeURIComponent(workspaceId)}/${encodeURIComponent(contentType)}`, oazapfts.json({
|
|
571
|
+
...opts,
|
|
572
|
+
method: "POST",
|
|
573
|
+
body: addWorkspaceContentRequestV2,
|
|
574
|
+
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
575
|
+
authorization,
|
|
576
|
+
"x-account-id": xAccountId
|
|
577
|
+
})
|
|
578
|
+
})));
|
|
579
|
+
}
|
|
537
580
|
/**
|
|
538
581
|
* Use Shareable Link
|
|
539
582
|
*/
|
|
@@ -653,6 +696,46 @@ export function listMembersV1ResourceTypeResourceTypeResourcesResourceIdentifier
|
|
|
653
696
|
})
|
|
654
697
|
}));
|
|
655
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* List Members
|
|
701
|
+
*/
|
|
702
|
+
export function listMembersV2ResourceTypeResourceTypeResourcesResourceIdentifierMembersGet({ resourceType, resourceIdentifier, search, filterBy, filterValue, sortBy, page, size, order, authorization, xAccountId }: {
|
|
703
|
+
resourceType: ContentType;
|
|
704
|
+
resourceIdentifier: string;
|
|
705
|
+
search?: string | null;
|
|
706
|
+
filterBy?: string | null;
|
|
707
|
+
filterValue?: string | null;
|
|
708
|
+
sortBy?: SortBy | null;
|
|
709
|
+
page?: number;
|
|
710
|
+
size?: number;
|
|
711
|
+
order?: OrderEnum;
|
|
712
|
+
authorization: string;
|
|
713
|
+
xAccountId?: string | null;
|
|
714
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
715
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
716
|
+
status: 200;
|
|
717
|
+
data: ResourceMembersPaginatedResponse;
|
|
718
|
+
} | {
|
|
719
|
+
status: 404;
|
|
720
|
+
} | {
|
|
721
|
+
status: 422;
|
|
722
|
+
data: HttpValidationError;
|
|
723
|
+
}>(`/v2/resource-type/${encodeURIComponent(resourceType)}/resources/${encodeURIComponent(resourceIdentifier)}/members${QS.query(QS.explode({
|
|
724
|
+
search,
|
|
725
|
+
filter_by: filterBy,
|
|
726
|
+
filter_value: filterValue,
|
|
727
|
+
sort_by: sortBy,
|
|
728
|
+
page,
|
|
729
|
+
size,
|
|
730
|
+
order
|
|
731
|
+
}))}`, {
|
|
732
|
+
...opts,
|
|
733
|
+
headers: oazapfts.mergeHeaders(opts?.headers, {
|
|
734
|
+
authorization,
|
|
735
|
+
"x-account-id": xAccountId
|
|
736
|
+
})
|
|
737
|
+
}));
|
|
738
|
+
}
|
|
656
739
|
/**
|
|
657
740
|
* Healthz
|
|
658
741
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpError } from '@oazapfts/runtime'
|
|
2
2
|
import { getApiAddresses } from '../api-addresses'
|
|
3
|
-
import { addFavoriteV1AgentsAgentIdFavoritePost, AgentVisibilityLevelEnum, createAgentV1AgentsPost, createToolkitToolsV1ToolkitsToolkitIdToolsPost, createToolkitV1ToolkitsPost, defaults, deleteAgentV1AgentsAgentIdDelete, deleteFavoriteV1AgentsAgentIdFavoriteDelete, deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete, deleteToolkitV1ToolkitsToolkitIdDelete, editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut, forkAgentV1AgentsAgentIdForkPost, forkToolkitV1ToolkitsToolkitIdForkPost, getAgentV1AgentsAgentIdGet, getPublicToolKitsV1BuiltinToolkitGet, getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet, getToolkitV1ToolkitsToolkitIdGet, listAgentsUsingToolsV1ToolkitsToolkitIdToolsAgentsPost, listAgentsV1AgentsGet, listAgentsV3AgentsGet, listMcpToolsV1McpToolsToolkitIdGet, listMultiAgentsV1AgentsMultiAgentsGet, listToolkitsV1ToolkitsGet, listToolkitsV2ToolkitsGet, publishAgentV1AgentsAgentIdPublishPost,
|
|
3
|
+
import { addFavoriteV1AgentsAgentIdFavoritePost, AgentVisibilityLevelEnum, createAgentV1AgentsPost, createAgentV2AgentsPost, createToolkitToolsV1ToolkitsToolkitIdToolsPost, createToolkitV1ToolkitsPost, createVersionV1AgentsAgentCoreIdVersionsPost, defaults, deleteAgentV1AgentsAgentIdDelete, deleteFavoriteV1AgentsAgentIdFavoriteDelete, deleteToolkitToolsV1ToolkitsToolkitIdToolsDelete, deleteToolkitV1ToolkitsToolkitIdDelete, deleteVersionV1AgentsAgentCoreIdVersionsVersionNumberDelete, editToolkitToolV1ToolkitsToolkitIdToolsToolIdPut, findByAgentCoreIdV2AgentsAgentCoreIdGet, forkAgentV1AgentsAgentIdForkPost, forkAgentVersionV1AgentsAgentCoreIdVersionsVersionNumberForkPost, forkToolkitV1ToolkitsToolkitIdForkPost, getAgentV1AgentsAgentIdGet, getPublicToolKitsV1BuiltinToolkitGet, getToolkitToolV1ToolkitsToolkitIdToolsToolIdGet, getToolkitV1ToolkitsToolkitIdGet, listAgentsUsingToolsV1ToolkitsToolkitIdToolsAgentsPost, listAgentsV1AgentsGet, listAgentsV3AgentsGet, listAgentsV4AgentsGet, listMcpToolsV1McpToolsToolkitIdGet, listMultiAgentsV1AgentsMultiAgentsGet, listToolkitsV1ToolkitsGet, listToolkitsV2ToolkitsGet, listVersionsOfAgentCoreV1AgentsAgentCoreIdVersionsGet, patchVersionRecommendedV1AgentsAgentCoreIdVersionsVersionNumberPatch, publishAgentV1AgentsAgentIdPublishPost, searchAgentsByIdsV1AgentsSearchPost, searchAgentsV2AgentsSearchPost, shareV1AgentsAgentIdSharePost, updateAgentV1AgentsAgentIdPatch, updateAgentV2AgentsAgentIdPatch, updateToolkitV1ToolkitsToolkitIdPatch, VisibilityLevelEnum } from '../api/agent-tools'
|
|
4
4
|
import { DefaultAPIError } from '../error/DefaultAPIError'
|
|
5
5
|
import { agentToolsDictionary } from '../error/dictionary/agent-tools'
|
|
6
6
|
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
@@ -13,6 +13,7 @@ import { workspaceAiClient } from './workspace-ai'
|
|
|
13
13
|
|
|
14
14
|
const AGENT_DEFAULT_SLUG = 'stk_flex'
|
|
15
15
|
const listAgentsV3AgentsWithoutAuthorization = removeAuthorizationParam(listAgentsV3AgentsGet)
|
|
16
|
+
const listAgentsV4 = removeAuthorizationParam(listAgentsV4AgentsGet)
|
|
16
17
|
const listToolkitsAuthorization = removeAuthorizationParam(listToolkitsV2ToolkitsGet)
|
|
17
18
|
|
|
18
19
|
class AgentToolsClient extends ReactQueryNetworkClient {
|
|
@@ -30,6 +31,7 @@ class AgentToolsClient extends ReactQueryNetworkClient {
|
|
|
30
31
|
tools = this.query(removeAuthorizationParam(getPublicToolKitsV1BuiltinToolkitGet))
|
|
31
32
|
|
|
32
33
|
/**
|
|
34
|
+
* @deprecated
|
|
33
35
|
* Create agent
|
|
34
36
|
*/
|
|
35
37
|
createAgent = this.mutation(removeAuthorizationParam(createAgentV1AgentsPost))
|
|
@@ -40,6 +42,7 @@ class AgentToolsClient extends ReactQueryNetworkClient {
|
|
|
40
42
|
deleteAgent = this.mutation(removeAuthorizationParam(deleteAgentV1AgentsAgentIdDelete))
|
|
41
43
|
|
|
42
44
|
/**
|
|
45
|
+
* @deprecated
|
|
43
46
|
* Updates an agent
|
|
44
47
|
*/
|
|
45
48
|
updateAgent = this.mutation(removeAuthorizationParam(updateAgentV1AgentsAgentIdPatch))
|
|
@@ -78,14 +81,16 @@ class AgentToolsClient extends ReactQueryNetworkClient {
|
|
|
78
81
|
availableAgentsForMultiAgentAddition = this.query(removeAuthorizationParam(listMultiAgentsV1AgentsMultiAgentsGet))
|
|
79
82
|
|
|
80
83
|
/**
|
|
84
|
+
* @deprecated
|
|
81
85
|
* Gets agent by id
|
|
82
86
|
*/
|
|
83
87
|
agent = this.query(removeAuthorizationParam(getAgentV1AgentsAgentIdGet))
|
|
84
88
|
|
|
85
89
|
/**
|
|
90
|
+
* @deprecated
|
|
86
91
|
* Gets agents by ids
|
|
87
92
|
*/
|
|
88
|
-
agentsByIds = this.query(removeAuthorizationParam(
|
|
93
|
+
agentsByIds = this.query(removeAuthorizationParam(searchAgentsByIdsV1AgentsSearchPost))
|
|
89
94
|
|
|
90
95
|
/**
|
|
91
96
|
* Gets the default agent slug
|
|
@@ -238,6 +243,54 @@ class AgentToolsClient extends ReactQueryNetworkClient {
|
|
|
238
243
|
* remove an agent from favorites
|
|
239
244
|
*/
|
|
240
245
|
removeFavorite = this.mutation(removeAuthorizationParam(deleteFavoriteV1AgentsAgentIdFavoriteDelete))
|
|
246
|
+
/**
|
|
247
|
+
* Creates an agent version
|
|
248
|
+
*/
|
|
249
|
+
createAgentVersion = this.mutation(removeAuthorizationParam(createVersionV1AgentsAgentCoreIdVersionsPost))
|
|
250
|
+
/**
|
|
251
|
+
* V2 of agent creation
|
|
252
|
+
*/
|
|
253
|
+
createAgentV2 = this.mutation(removeAuthorizationParam(createAgentV2AgentsPost))
|
|
254
|
+
/**
|
|
255
|
+
* V2 of agent update
|
|
256
|
+
*/
|
|
257
|
+
updateAgentV2 = this.mutation(removeAuthorizationParam(updateAgentV2AgentsAgentIdPatch))
|
|
258
|
+
/**
|
|
259
|
+
* Update agent recommended version
|
|
260
|
+
*/
|
|
261
|
+
updateRecommendedVersion = this.mutation(removeAuthorizationParam(patchVersionRecommendedV1AgentsAgentCoreIdVersionsVersionNumberPatch))
|
|
262
|
+
/**
|
|
263
|
+
* V2 of get agent by id
|
|
264
|
+
*/
|
|
265
|
+
agentV2 = this.query(removeAuthorizationParam(findByAgentCoreIdV2AgentsAgentCoreIdGet))
|
|
266
|
+
/**
|
|
267
|
+
* Deletes an agent version
|
|
268
|
+
*/
|
|
269
|
+
deleteVersion = this.mutation(removeAuthorizationParam(deleteVersionV1AgentsAgentCoreIdVersionsVersionNumberDelete))
|
|
270
|
+
/**
|
|
271
|
+
* Gets agent versions
|
|
272
|
+
*/
|
|
273
|
+
listAgentVersions = this.query(removeAuthorizationParam(listVersionsOfAgentCoreV1AgentsAgentCoreIdVersionsGet))
|
|
274
|
+
/**
|
|
275
|
+
* Get agents by list of ids using api v2
|
|
276
|
+
*/
|
|
277
|
+
agentsByIdsV2 = this.query(removeAuthorizationParam(searchAgentsV2AgentsSearchPost))
|
|
278
|
+
/**
|
|
279
|
+
* Deletes an agent version
|
|
280
|
+
*/
|
|
281
|
+
forkAgentVersion = this.mutation(removeAuthorizationParam(forkAgentVersionV1AgentsAgentCoreIdVersionsVersionNumberForkPost))
|
|
282
|
+
/**
|
|
283
|
+
* Get agents v4
|
|
284
|
+
*/
|
|
285
|
+
agentsV4 = this.infiniteQuery(listAgentsV4, {
|
|
286
|
+
pageParamName: 'filters.page',
|
|
287
|
+
accumulator: 'items',
|
|
288
|
+
getNextPageParam: ({ variables, lastPage, lastPageParam }) => {
|
|
289
|
+
const size = variables.filters.size ?? 1
|
|
290
|
+
const parsedLastPageParam = (lastPageParam as number) ?? variables.filters.page ?? 1
|
|
291
|
+
return lastPage.items && lastPage.items.length < size ? undefined : parsedLastPageParam + 1
|
|
292
|
+
},
|
|
293
|
+
})
|
|
241
294
|
}
|
|
242
295
|
|
|
243
296
|
export const agentToolsClient = new AgentToolsClient()
|
package/src/client/discover.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpError } from '@oazapfts/runtime'
|
|
2
2
|
import { findLast, last } from 'lodash'
|
|
3
3
|
import { getApiAddresses } from '../api-addresses'
|
|
4
|
-
import {
|
|
4
|
+
import { ConversationResponse } from '../api/ai'
|
|
5
5
|
import { AiChatRequest, create, create1, create2, defaults, deleteById, deleteById1, deleteById2, fetchInsights, getAll, getAll1, getAll2, getAllByHypothesis, getById, getById1, getById2, getInsightById, GetOpportunityResponse, refreshInsights } from '../api/discover'
|
|
6
6
|
import { DefaultAPIError } from '../error/DefaultAPIError'
|
|
7
7
|
import { baseDictionary } from '../error/dictionary/base'
|
|
@@ -11,10 +11,10 @@ import { StreamedJson } from '../utils/StreamedJson'
|
|
|
11
11
|
import { formatJson } from '../utils/string'
|
|
12
12
|
import { agentToolsClient } from './agent-tools'
|
|
13
13
|
import { aiClient } from './ai'
|
|
14
|
-
import { AgentInfo, ChatAgentTool, ChatStep, StepChatStep } from './types'
|
|
14
|
+
import { AgentInfo, ChatAgentTool, ChatResponse, ChatStep, StepChatStep } from './types'
|
|
15
15
|
|
|
16
|
-
export interface FixedDiscoveryChatResponse extends
|
|
17
|
-
agent_info: AgentInfo,
|
|
16
|
+
export interface FixedDiscoveryChatResponse extends ChatResponse {
|
|
17
|
+
agent_info: AgentInfo[],
|
|
18
18
|
tools?: string[],
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -131,7 +131,7 @@ class DiscoverClient extends ReactQueryNetworkClient {
|
|
|
131
131
|
|
|
132
132
|
|
|
133
133
|
sendChatMessage(request: AiChatRequest & { agentId: string }, minChangeIntervalMS?: number)
|
|
134
|
-
|
|
134
|
+
: StreamedJson<DiscoveryChatResponseWithSteps> {
|
|
135
135
|
const abortController = new AbortController()
|
|
136
136
|
const headers = {
|
|
137
137
|
'Content-Type': 'application/json',
|
|
@@ -147,171 +147,175 @@ class DiscoverClient extends ReactQueryNetworkClient {
|
|
|
147
147
|
* StreamedJson object whenever an event is triggered.
|
|
148
148
|
*/
|
|
149
149
|
async function transform(event: Partial<FixedDiscoveryChatResponse>, data: Partial<DiscoveryChatResponseWithSteps>) {
|
|
150
|
-
const
|
|
150
|
+
const agentInfoList = event.agent_info
|
|
151
151
|
|
|
152
|
-
if (!
|
|
152
|
+
if (!agentInfoList?.length) return
|
|
153
153
|
|
|
154
154
|
const tools = await DiscoverClient.toolsOfAgent(request.agentId)
|
|
155
155
|
data.steps = data.steps ? [...data.steps] : []
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
id: 'planning',
|
|
160
|
-
type: 'planning',
|
|
161
|
-
status: 'success',
|
|
162
|
-
duration: info.duration || 0,
|
|
163
|
-
steps: info.data?.steps?.map(s => s.goal) ?? [],
|
|
164
|
-
goal: info.data?.plan_goal ?? '',
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
info.data?.steps.forEach(s => data.steps?.push({
|
|
168
|
-
id: s.id,
|
|
169
|
-
type: 'step',
|
|
170
|
-
status: 'pending',
|
|
171
|
-
input: s.goal,
|
|
172
|
-
attempts: [{
|
|
173
|
-
tools: s.tools?.map(t => ({
|
|
174
|
-
...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
|
|
175
|
-
executionId: t.tool_execution_id,
|
|
176
|
-
goal: t.goal,
|
|
177
|
-
})),
|
|
178
|
-
}],
|
|
179
|
-
}))
|
|
180
|
-
data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (info.type === 'planning' && info.action === 'awaiting_approval') {
|
|
184
|
-
data.steps.push({
|
|
185
|
-
id: 'planning',
|
|
186
|
-
type: 'planning',
|
|
187
|
-
status: 'awaiting_approval',
|
|
188
|
-
user_question: info.data?.user_question,
|
|
189
|
-
duration: info.duration || 0,
|
|
190
|
-
steps: info.data?.steps?.map(s => s.goal) ?? [],
|
|
191
|
-
goal: info.data?.plan_goal ?? '',
|
|
192
|
-
})
|
|
193
|
-
info.data?.steps.forEach(s => data.steps?.push({
|
|
194
|
-
id: s.id,
|
|
195
|
-
type: 'step',
|
|
196
|
-
status: 'pending',
|
|
197
|
-
input: s.goal,
|
|
198
|
-
attempts: [{
|
|
199
|
-
tools: s.tools?.map(t => ({
|
|
200
|
-
...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
|
|
201
|
-
executionId: t.tool_execution_id,
|
|
202
|
-
goal: t.goal,
|
|
203
|
-
})),
|
|
204
|
-
}],
|
|
205
|
-
}))
|
|
206
|
-
data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
|
|
207
|
-
}
|
|
157
|
+
for (const info of agentInfoList) {
|
|
158
|
+
if (!info) continue
|
|
208
159
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
160
|
+
if (info.type === 'planning' && info.action === 'end') {
|
|
161
|
+
data.steps.push({
|
|
162
|
+
id: 'planning',
|
|
163
|
+
type: 'planning',
|
|
164
|
+
status: 'success',
|
|
165
|
+
duration: info.duration || 0,
|
|
166
|
+
steps: info.data?.steps?.map(s => s.goal) ?? [],
|
|
167
|
+
goal: info.data?.plan_goal ?? '',
|
|
168
|
+
})
|
|
213
169
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
170
|
+
info.data?.steps.forEach(s => data.steps?.push({
|
|
171
|
+
id: s.id,
|
|
172
|
+
type: 'step',
|
|
173
|
+
status: 'pending',
|
|
174
|
+
input: s.goal,
|
|
175
|
+
attempts: [{
|
|
176
|
+
tools: s.tools?.map(t => ({
|
|
177
|
+
...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
|
|
178
|
+
executionId: t.tool_execution_id,
|
|
179
|
+
goal: t.goal,
|
|
180
|
+
})),
|
|
181
|
+
}],
|
|
182
|
+
}))
|
|
183
|
+
data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
|
|
222
184
|
}
|
|
223
|
-
}
|
|
224
185
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
186
|
+
if (info.type === 'planning' && info.action === 'awaiting_approval') {
|
|
187
|
+
data.steps.push({
|
|
188
|
+
id: 'planning',
|
|
189
|
+
type: 'planning',
|
|
190
|
+
status: 'awaiting_approval',
|
|
191
|
+
user_question: info.data?.user_question,
|
|
192
|
+
duration: info.duration || 0,
|
|
193
|
+
steps: info.data?.steps?.map(s => s.goal) ?? [],
|
|
194
|
+
goal: info.data?.plan_goal ?? '',
|
|
195
|
+
})
|
|
196
|
+
info.data?.steps.forEach(s => data.steps?.push({
|
|
197
|
+
id: s.id,
|
|
198
|
+
type: 'step',
|
|
199
|
+
status: 'pending',
|
|
200
|
+
input: s.goal,
|
|
201
|
+
attempts: [{
|
|
202
|
+
tools: s.tools?.map(t => ({
|
|
203
|
+
...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
|
|
204
|
+
executionId: t.tool_execution_id,
|
|
205
|
+
goal: t.goal,
|
|
206
|
+
})),
|
|
241
207
|
}],
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
208
|
+
}))
|
|
209
|
+
data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
|
|
210
|
+
}
|
|
246
211
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
212
|
+
if (info.type === 'step' && info.action === 'start') {
|
|
213
|
+
const step = data.steps.find(s => s.id === info.id)
|
|
214
|
+
if (step) step.status = 'running'
|
|
215
|
+
}
|
|
250
216
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
217
|
+
if (info.type === 'step' && info.action === 'end') {
|
|
218
|
+
const step = data.steps.find(s => s.id === info.id) as StepChatStep
|
|
219
|
+
if (step) {
|
|
220
|
+
step.status = 'success'
|
|
221
|
+
step.duration = info.duration
|
|
222
|
+
const lastToolId = last(step.attempts[0].tools)?.id
|
|
223
|
+
const lastAttemptOfLastTool = findLast(step.attempts.map(a => a.tools).flat(), t => t?.id === lastToolId)
|
|
224
|
+
step.output = lastAttemptOfLastTool?.output
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (info.type === 'tool' && info.action === 'awaiting_approval') {
|
|
229
|
+
const tool = tools.find(({ id }) => id === info.data?.tool_id)
|
|
255
230
|
data.steps.push({
|
|
256
231
|
id: info.id,
|
|
257
232
|
type: 'tool',
|
|
258
|
-
status: '
|
|
233
|
+
status: 'awaiting_approval',
|
|
259
234
|
duration: info.duration || 0,
|
|
260
235
|
input: info.data?.input,
|
|
261
236
|
user_question: info.data?.user_question,
|
|
262
237
|
attempts: [{
|
|
263
|
-
tools: [{
|
|
238
|
+
tools: [{
|
|
239
|
+
executionId: info.id,
|
|
240
|
+
id: info.data?.tool_id ?? '',
|
|
241
|
+
name: tool?.name ?? '',
|
|
242
|
+
goal: tool?.goal,
|
|
243
|
+
...tool,
|
|
244
|
+
}],
|
|
264
245
|
}],
|
|
265
246
|
})
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
247
|
+
data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (info.type === 'tool' && info.action === 'start') {
|
|
251
|
+
const currentStep = data.steps.find(s => s.status === 'running') as StepChatStep
|
|
252
|
+
if (!info.data) return
|
|
253
|
+
|
|
254
|
+
//There might be a tool with status awaiting_approval, so we want to inform tool has already started
|
|
255
|
+
if (!currentStep || !currentStep.attempts[0].tools) {
|
|
271
256
|
const input = formatJson(info.data.input)
|
|
272
|
-
const tool = tools
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
257
|
+
const tool = tools.find(({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
|
|
258
|
+
data.steps.push({
|
|
259
|
+
id: info.id,
|
|
260
|
+
type: 'tool',
|
|
261
|
+
status: 'running',
|
|
262
|
+
duration: info.duration || 0,
|
|
263
|
+
input: info.data?.input,
|
|
264
|
+
user_question: info.data?.user_question,
|
|
265
|
+
attempts: [{
|
|
266
|
+
tools: [{ ...tool, executionId: info.id, input }],
|
|
267
|
+
}],
|
|
277
268
|
})
|
|
278
269
|
} else {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
270
|
+
const toolInFirstAttempt = currentStep.attempts[0].tools?.find(t => t.executionId === info.id)
|
|
271
|
+
//One step might have multiple tools. When in an approval mode, we might not have all the tools in the array yet.
|
|
272
|
+
//So we make sure to add any tools that are not in there.
|
|
273
|
+
if (!toolInFirstAttempt) {
|
|
274
|
+
const input = formatJson(info.data.input)
|
|
275
|
+
const tool = tools?.find(({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
|
|
285
276
|
currentStep.attempts[info.data.attempt - 1].tools?.push({
|
|
286
277
|
...tool,
|
|
287
278
|
executionId: info.id,
|
|
288
279
|
input,
|
|
289
280
|
})
|
|
281
|
+
} else {
|
|
282
|
+
const input = formatJson(info.data.input)
|
|
283
|
+
if (info.data.attempt === 1) {
|
|
284
|
+
toolInFirstAttempt.input = input
|
|
285
|
+
} else {
|
|
286
|
+
const tool = tools.find(({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
|
|
287
|
+
currentStep.attempts[info.data.attempt - 1] ??= { tools: [] }
|
|
288
|
+
currentStep.attempts[info.data.attempt - 1].tools?.push({
|
|
289
|
+
...tool,
|
|
290
|
+
executionId: info.id,
|
|
291
|
+
input,
|
|
292
|
+
})
|
|
293
|
+
}
|
|
290
294
|
}
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
|
-
}
|
|
294
297
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
if (info.type === 'tool' && info.action === 'end') {
|
|
299
|
+
const currentStep = data.steps.find(s => s.status === 'running') as StepChatStep
|
|
300
|
+
if (!currentStep || !info.data) return
|
|
301
|
+
const tool = currentStep.attempts[info.data.attempt - 1]?.tools?.find(t => t.executionId === info.id)
|
|
302
|
+
if (tool) {
|
|
303
|
+
tool.output = formatJson(info.data.output)
|
|
304
|
+
tool.duration = info.duration
|
|
305
|
+
}
|
|
302
306
|
}
|
|
303
|
-
}
|
|
304
307
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
if (info.type === 'final_answer' && info.action === 'start') {
|
|
309
|
+
const answerStep = last(data.steps)
|
|
310
|
+
if (answerStep) answerStep.status = 'running'
|
|
311
|
+
}
|
|
309
312
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
if (info.type === 'chat' && info.action === 'end') {
|
|
314
|
+
const answerStep = last(data.steps)
|
|
315
|
+
if (answerStep) {
|
|
316
|
+
answerStep.status = 'success'
|
|
317
|
+
answerStep.duration = info.duration
|
|
318
|
+
}
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
321
|
}
|
|
@@ -319,9 +323,13 @@ class DiscoverClient extends ReactQueryNetworkClient {
|
|
|
319
323
|
return new StreamedJson({
|
|
320
324
|
eventsPromise: events,
|
|
321
325
|
abortController,
|
|
322
|
-
minChangeIntervalMS,
|
|
323
326
|
ignoreKeys: ['agent_info'],
|
|
324
327
|
transform,
|
|
328
|
+
minChangeIntervalMS,
|
|
329
|
+
minChangeIntervalMSFromEvent: (event) => {
|
|
330
|
+
if (event?.agent_info?.length) return 0
|
|
331
|
+
return minChangeIntervalMS
|
|
332
|
+
},
|
|
325
333
|
})
|
|
326
334
|
}
|
|
327
335
|
}
|