@stack-spot/portal-network 0.101.0 → 0.102.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/agent.d.ts +70 -23
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +41 -20
- package/dist/api/agent.js.map +1 -1
- package/dist/client/agent.d.ts +2 -0
- package/dist/client/agent.d.ts.map +1 -1
- package/dist/client/ai.d.ts +60 -9
- package/dist/client/ai.d.ts.map +1 -1
- package/dist/client/ai.js +154 -7
- package/dist/client/ai.js.map +1 -1
- package/dist/client/types.d.ts +62 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/utils/StreamedJson.d.ts +29 -2
- package/dist/utils/StreamedJson.d.ts.map +1 -1
- package/dist/utils/StreamedJson.js +19 -4
- package/dist/utils/StreamedJson.js.map +1 -1
- package/package.json +1 -1
- package/src/api/agent.ts +142 -108
- package/src/client/ai.ts +169 -10
- package/src/client/types.ts +72 -0
- package/src/utils/StreamedJson.tsx +35 -4
package/src/api/agent.ts
CHANGED
|
@@ -37,16 +37,32 @@ export type NewAgentRequest = {
|
|
|
37
37
|
"type": AgentType;
|
|
38
38
|
llm_config?: (LlmConfigRequestPart) | null;
|
|
39
39
|
knowledge_sources_config?: (KnowledgeSourcesConfigRequestPart) | null;
|
|
40
|
+
builtin_tools_ids?: string[];
|
|
41
|
+
detail_mode?: boolean;
|
|
40
42
|
};
|
|
41
43
|
export type ViolationResponse = {
|
|
42
44
|
field?: string;
|
|
43
45
|
message?: string;
|
|
44
46
|
};
|
|
47
|
+
export type WorkspaceListRequest = {
|
|
48
|
+
agentIds?: string[];
|
|
49
|
+
name?: string;
|
|
50
|
+
};
|
|
51
|
+
export type Uuid = string;
|
|
45
52
|
export type WorkspaceForkRequest = {
|
|
46
53
|
agentIds?: string[];
|
|
54
|
+
memberId?: Uuid;
|
|
47
55
|
};
|
|
48
56
|
export type WorkspaceForkResponse = {
|
|
49
|
-
|
|
57
|
+
agentIds?: string[];
|
|
58
|
+
agentIdsAccount?: string[];
|
|
59
|
+
ksIds?: string[];
|
|
60
|
+
ksIdsAccount?: string[];
|
|
61
|
+
errorIds?: string[];
|
|
62
|
+
};
|
|
63
|
+
export type WorkspaceDeleteRequest = {
|
|
64
|
+
agentIds?: string[];
|
|
65
|
+
isRollback?: boolean;
|
|
50
66
|
};
|
|
51
67
|
export type LlmConfigResponse = {
|
|
52
68
|
model_slug: string;
|
|
@@ -74,6 +90,21 @@ export type KnowledgeSourceResponse = {
|
|
|
74
90
|
knowledge_sources_details?: KnowledgeSourceDetailResponse[];
|
|
75
91
|
};
|
|
76
92
|
export type ZonedDateTime = string;
|
|
93
|
+
export type BuiltinToolResponse = {
|
|
94
|
+
id?: string;
|
|
95
|
+
name?: string;
|
|
96
|
+
description?: string;
|
|
97
|
+
};
|
|
98
|
+
export type BuiltinToolkitResponse = {
|
|
99
|
+
id?: string;
|
|
100
|
+
name?: string;
|
|
101
|
+
description?: string;
|
|
102
|
+
image_url?: string;
|
|
103
|
+
tools?: BuiltinToolResponse[];
|
|
104
|
+
};
|
|
105
|
+
export type ToolkitsInAgentResponse = {
|
|
106
|
+
builtins?: BuiltinToolkitResponse[];
|
|
107
|
+
};
|
|
77
108
|
export type ModifiedAgentRequest = {
|
|
78
109
|
name?: string | null;
|
|
79
110
|
slug?: string | null;
|
|
@@ -85,6 +116,8 @@ export type ModifiedAgentRequest = {
|
|
|
85
116
|
llm_config?: (LlmConfigRequestPart) | null;
|
|
86
117
|
knowledge_sources_config?: (KnowledgeSourcesConfigRequestPart) | null;
|
|
87
118
|
use_only?: boolean | null;
|
|
119
|
+
builtin_tools_ids?: string[];
|
|
120
|
+
detail_mode?: boolean | null;
|
|
88
121
|
};
|
|
89
122
|
export type ForkAgentRequest = {
|
|
90
123
|
slug?: string;
|
|
@@ -113,6 +146,8 @@ export type AgentResponse = {
|
|
|
113
146
|
created_at: ZonedDateTime;
|
|
114
147
|
updated_by?: string;
|
|
115
148
|
updated_at?: ZonedDateTime;
|
|
149
|
+
toolkits?: ToolkitsInAgentResponse;
|
|
150
|
+
detail_mode?: boolean;
|
|
116
151
|
};
|
|
117
152
|
/**
|
|
118
153
|
* Creates a new AI Agent.
|
|
@@ -156,6 +191,75 @@ export function postV1Agent({ newAgentRequest }: {
|
|
|
156
191
|
body: newAgentRequest
|
|
157
192
|
})));
|
|
158
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* List Workspace Fork AI agents.
|
|
196
|
+
*/
|
|
197
|
+
export function postV1AgentDependencies({ workspaceListRequest }: {
|
|
198
|
+
workspaceListRequest?: WorkspaceListRequest;
|
|
199
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
200
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
201
|
+
status: 201;
|
|
202
|
+
data: Blob;
|
|
203
|
+
} | {
|
|
204
|
+
status: 500;
|
|
205
|
+
data: {
|
|
206
|
+
code?: string;
|
|
207
|
+
details?: string;
|
|
208
|
+
additionalInformation?: {
|
|
209
|
+
[key: string]: any;
|
|
210
|
+
} | null;
|
|
211
|
+
};
|
|
212
|
+
}>("/v1/agent/dependencies", oazapfts.json({
|
|
213
|
+
...opts,
|
|
214
|
+
method: "POST",
|
|
215
|
+
body: workspaceListRequest
|
|
216
|
+
})));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* List agents with specific KS
|
|
220
|
+
*/
|
|
221
|
+
export function getV1AgentKnowledgeSourceById({ id }: {
|
|
222
|
+
id: string;
|
|
223
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
224
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
225
|
+
status: 200;
|
|
226
|
+
data: Blob;
|
|
227
|
+
} | {
|
|
228
|
+
status: 500;
|
|
229
|
+
data: {
|
|
230
|
+
code?: string;
|
|
231
|
+
details?: string;
|
|
232
|
+
additionalInformation?: {
|
|
233
|
+
[key: string]: any;
|
|
234
|
+
} | null;
|
|
235
|
+
};
|
|
236
|
+
}>(`/v1/agent/knowledge-source/${encodeURIComponent(id)}`, {
|
|
237
|
+
...opts
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Disassociate KS from Agent
|
|
242
|
+
*/
|
|
243
|
+
export function deleteV1AgentKnowledgeSourceById({ id }: {
|
|
244
|
+
id: string;
|
|
245
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
246
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
247
|
+
status: 204;
|
|
248
|
+
data: Blob;
|
|
249
|
+
} | {
|
|
250
|
+
status: 500;
|
|
251
|
+
data: {
|
|
252
|
+
code?: string;
|
|
253
|
+
details?: string;
|
|
254
|
+
additionalInformation?: {
|
|
255
|
+
[key: string]: any;
|
|
256
|
+
} | null;
|
|
257
|
+
};
|
|
258
|
+
}>(`/v1/agent/knowledge-source/${encodeURIComponent(id)}`, {
|
|
259
|
+
...opts,
|
|
260
|
+
method: "DELETE"
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
159
263
|
/**
|
|
160
264
|
* Workspace Fork AI agents.
|
|
161
265
|
*/
|
|
@@ -174,7 +278,7 @@ export function postV1AgentWorkspaceFork({ workspaceForkRequest }: {
|
|
|
174
278
|
[key: string]: any;
|
|
175
279
|
} | null;
|
|
176
280
|
};
|
|
177
|
-
}>("/v1/agent/workspace
|
|
281
|
+
}>("/v1/agent/workspace/fork", oazapfts.json({
|
|
178
282
|
...opts,
|
|
179
283
|
method: "POST",
|
|
180
284
|
body: workspaceForkRequest
|
|
@@ -183,8 +287,8 @@ export function postV1AgentWorkspaceFork({ workspaceForkRequest }: {
|
|
|
183
287
|
/**
|
|
184
288
|
* Delete Workspace Fork AI agents.
|
|
185
289
|
*/
|
|
186
|
-
export function deleteV1AgentWorkspaceFork({
|
|
187
|
-
|
|
290
|
+
export function deleteV1AgentWorkspaceFork({ workspaceDeleteRequest }: {
|
|
291
|
+
workspaceDeleteRequest?: WorkspaceDeleteRequest;
|
|
188
292
|
}, opts?: Oazapfts.RequestOpts) {
|
|
189
293
|
return oazapfts.ok(oazapfts.fetchJson<{
|
|
190
294
|
status: 201;
|
|
@@ -198,10 +302,34 @@ export function deleteV1AgentWorkspaceFork({ workspaceForkRequest }: {
|
|
|
198
302
|
[key: string]: any;
|
|
199
303
|
} | null;
|
|
200
304
|
};
|
|
201
|
-
}>("/v1/agent/workspace
|
|
305
|
+
}>("/v1/agent/workspace/fork", oazapfts.json({
|
|
202
306
|
...opts,
|
|
203
307
|
method: "DELETE",
|
|
204
|
-
body:
|
|
308
|
+
body: workspaceDeleteRequest
|
|
309
|
+
})));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* List Workspace Fork AI agents.
|
|
313
|
+
*/
|
|
314
|
+
export function postV1AgentWorkspaceList({ workspaceListRequest }: {
|
|
315
|
+
workspaceListRequest?: WorkspaceListRequest;
|
|
316
|
+
}, opts?: Oazapfts.RequestOpts) {
|
|
317
|
+
return oazapfts.ok(oazapfts.fetchJson<{
|
|
318
|
+
status: 201;
|
|
319
|
+
data: Blob;
|
|
320
|
+
} | {
|
|
321
|
+
status: 500;
|
|
322
|
+
data: {
|
|
323
|
+
code?: string;
|
|
324
|
+
details?: string;
|
|
325
|
+
additionalInformation?: {
|
|
326
|
+
[key: string]: any;
|
|
327
|
+
} | null;
|
|
328
|
+
};
|
|
329
|
+
}>("/v1/agent/workspace/list", oazapfts.json({
|
|
330
|
+
...opts,
|
|
331
|
+
method: "POST",
|
|
332
|
+
body: workspaceListRequest
|
|
205
333
|
})));
|
|
206
334
|
}
|
|
207
335
|
/**
|
|
@@ -230,6 +358,8 @@ export function getV1AgentByAgentId({ agentId }: {
|
|
|
230
358
|
created_at: ZonedDateTime;
|
|
231
359
|
updated_by?: string;
|
|
232
360
|
updated_at?: ZonedDateTime;
|
|
361
|
+
toolkits?: ToolkitsInAgentResponse;
|
|
362
|
+
detail_mode?: boolean;
|
|
233
363
|
};
|
|
234
364
|
} | {
|
|
235
365
|
status: 404;
|
|
@@ -342,57 +472,6 @@ export function deleteV1AgentByAgentId({ agentId }: {
|
|
|
342
472
|
method: "DELETE"
|
|
343
473
|
}));
|
|
344
474
|
}
|
|
345
|
-
/**
|
|
346
|
-
* AI Agent validade publish.
|
|
347
|
-
*/
|
|
348
|
-
export function getV1AgentByAgentIdDependencies({ agentId }: {
|
|
349
|
-
agentId: string;
|
|
350
|
-
}, opts?: Oazapfts.RequestOpts) {
|
|
351
|
-
return oazapfts.ok(oazapfts.fetchJson<{
|
|
352
|
-
status: 200;
|
|
353
|
-
data: {
|
|
354
|
-
ks_names?: string[];
|
|
355
|
-
error_ks_names?: string[];
|
|
356
|
-
missing_ks_list?: string[];
|
|
357
|
-
};
|
|
358
|
-
} | {
|
|
359
|
-
status: 400;
|
|
360
|
-
data: {
|
|
361
|
-
code?: string;
|
|
362
|
-
details?: string;
|
|
363
|
-
violations?: ViolationResponse[];
|
|
364
|
-
};
|
|
365
|
-
} | {
|
|
366
|
-
status: 404;
|
|
367
|
-
data: {
|
|
368
|
-
code?: string;
|
|
369
|
-
details?: string;
|
|
370
|
-
additionalInformation?: {
|
|
371
|
-
[key: string]: any;
|
|
372
|
-
} | null;
|
|
373
|
-
};
|
|
374
|
-
} | {
|
|
375
|
-
status: 422;
|
|
376
|
-
data: {
|
|
377
|
-
code?: string;
|
|
378
|
-
details?: string;
|
|
379
|
-
additionalInformation?: {
|
|
380
|
-
[key: string]: any;
|
|
381
|
-
} | null;
|
|
382
|
-
};
|
|
383
|
-
} | {
|
|
384
|
-
status: 500;
|
|
385
|
-
data: {
|
|
386
|
-
code?: string;
|
|
387
|
-
details?: string;
|
|
388
|
-
additionalInformation?: {
|
|
389
|
-
[key: string]: any;
|
|
390
|
-
} | null;
|
|
391
|
-
};
|
|
392
|
-
}>(`/v1/agent/${encodeURIComponent(agentId)}/dependencies`, {
|
|
393
|
-
...opts
|
|
394
|
-
}));
|
|
395
|
-
}
|
|
396
475
|
/**
|
|
397
476
|
* Fork an AI agent.
|
|
398
477
|
*/
|
|
@@ -518,6 +597,8 @@ export function getV1AgentByAgentSlugExists({ agentSlug }: {
|
|
|
518
597
|
created_at: ZonedDateTime;
|
|
519
598
|
updated_by?: string;
|
|
520
599
|
updated_at?: ZonedDateTime;
|
|
600
|
+
toolkits?: ToolkitsInAgentResponse;
|
|
601
|
+
detail_mode?: boolean;
|
|
521
602
|
};
|
|
522
603
|
} | {
|
|
523
604
|
status: 404;
|
|
@@ -633,6 +714,8 @@ export function getV1PublicAgentByAgentId({ agentId }: {
|
|
|
633
714
|
created_at: ZonedDateTime;
|
|
634
715
|
updated_by?: string;
|
|
635
716
|
updated_at?: ZonedDateTime;
|
|
717
|
+
toolkits?: ToolkitsInAgentResponse;
|
|
718
|
+
detail_mode?: boolean;
|
|
636
719
|
};
|
|
637
720
|
} | {
|
|
638
721
|
status: 404;
|
|
@@ -745,57 +828,6 @@ export function deleteV1PublicAgentByAgentId({ agentId }: {
|
|
|
745
828
|
method: "DELETE"
|
|
746
829
|
}));
|
|
747
830
|
}
|
|
748
|
-
/**
|
|
749
|
-
* AI Agent validade publish.
|
|
750
|
-
*/
|
|
751
|
-
export function getV1PublicAgentByAgentIdDependencies({ agentId }: {
|
|
752
|
-
agentId: string;
|
|
753
|
-
}, opts?: Oazapfts.RequestOpts) {
|
|
754
|
-
return oazapfts.ok(oazapfts.fetchJson<{
|
|
755
|
-
status: 200;
|
|
756
|
-
data: {
|
|
757
|
-
ks_names?: string[];
|
|
758
|
-
error_ks_names?: string[];
|
|
759
|
-
missing_ks_list?: string[];
|
|
760
|
-
};
|
|
761
|
-
} | {
|
|
762
|
-
status: 400;
|
|
763
|
-
data: {
|
|
764
|
-
code?: string;
|
|
765
|
-
details?: string;
|
|
766
|
-
violations?: ViolationResponse[];
|
|
767
|
-
};
|
|
768
|
-
} | {
|
|
769
|
-
status: 404;
|
|
770
|
-
data: {
|
|
771
|
-
code?: string;
|
|
772
|
-
details?: string;
|
|
773
|
-
additionalInformation?: {
|
|
774
|
-
[key: string]: any;
|
|
775
|
-
} | null;
|
|
776
|
-
};
|
|
777
|
-
} | {
|
|
778
|
-
status: 422;
|
|
779
|
-
data: {
|
|
780
|
-
code?: string;
|
|
781
|
-
details?: string;
|
|
782
|
-
additionalInformation?: {
|
|
783
|
-
[key: string]: any;
|
|
784
|
-
} | null;
|
|
785
|
-
};
|
|
786
|
-
} | {
|
|
787
|
-
status: 500;
|
|
788
|
-
data: {
|
|
789
|
-
code?: string;
|
|
790
|
-
details?: string;
|
|
791
|
-
additionalInformation?: {
|
|
792
|
-
[key: string]: any;
|
|
793
|
-
} | null;
|
|
794
|
-
};
|
|
795
|
-
}>(`/v1/public/agent/${encodeURIComponent(agentId)}/dependencies`, {
|
|
796
|
-
...opts
|
|
797
|
-
}));
|
|
798
|
-
}
|
|
799
831
|
/**
|
|
800
832
|
* AI Agent update visibility.
|
|
801
833
|
*/
|
|
@@ -871,6 +903,8 @@ export function getV1PublicAgentByAgentSlugExists({ agentSlug }: {
|
|
|
871
903
|
created_at: ZonedDateTime;
|
|
872
904
|
updated_by?: string;
|
|
873
905
|
updated_at?: ZonedDateTime;
|
|
906
|
+
toolkits?: ToolkitsInAgentResponse;
|
|
907
|
+
detail_mode?: boolean;
|
|
874
908
|
};
|
|
875
909
|
} | {
|
|
876
910
|
status: 404;
|
package/src/client/ai.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpError } from '@oazapfts/runtime'
|
|
2
|
+
import { last } from 'lodash'
|
|
2
3
|
import {
|
|
3
4
|
addFavoriteV1FavoritesPost,
|
|
4
|
-
ChatResponse3,
|
|
5
5
|
conversationHistoryV1ConversationsConversationIdGet,
|
|
6
6
|
defaults,
|
|
7
7
|
deleteConversationV1ConversationsConversationIdDelete,
|
|
@@ -30,7 +30,16 @@ import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
|
30
30
|
import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
|
|
31
31
|
import { removeAuthorizationParam } from '../utils/remove-authorization-param'
|
|
32
32
|
import { StreamedJson } from '../utils/StreamedJson'
|
|
33
|
-
import {
|
|
33
|
+
import { agentClient } from './agent'
|
|
34
|
+
import {
|
|
35
|
+
ChatAgentTool,
|
|
36
|
+
ChatResponseWithSteps,
|
|
37
|
+
FixedChatRequest,
|
|
38
|
+
FixedChatResponse,
|
|
39
|
+
FixedConversationResponse,
|
|
40
|
+
FixedDependencyResponse,
|
|
41
|
+
ReplaceResult,
|
|
42
|
+
} from './types'
|
|
34
43
|
|
|
35
44
|
class AIClient extends ReactQueryNetworkClient {
|
|
36
45
|
constructor() {
|
|
@@ -46,42 +55,107 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
46
55
|
})
|
|
47
56
|
}
|
|
48
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Chat: runs a quick action.
|
|
60
|
+
*/
|
|
49
61
|
runQuickAction = this.mutation(removeAuthorizationParam(quickActionsV1QuickActionsPost))
|
|
62
|
+
/**
|
|
63
|
+
* Lists the AI Stacks according to their visibilities.
|
|
64
|
+
*/
|
|
50
65
|
aiStacks = this.query(removeAuthorizationParam(listAiStacksV1AiStacksGet))
|
|
66
|
+
/**
|
|
67
|
+
* Gets a workspace by its id.
|
|
68
|
+
*/
|
|
51
69
|
workspace = this.query(removeAuthorizationParam(listAssociationV1WorkspaceWorkspaceIdGet))
|
|
70
|
+
/**
|
|
71
|
+
* Lists the quick commands according to filters passed as parameter.
|
|
72
|
+
*/
|
|
52
73
|
quickCommands = this.query(removeAuthorizationParam(listAllV1QuickCommandsAllGet))
|
|
74
|
+
/**
|
|
75
|
+
* Gets a quick command by its slug.
|
|
76
|
+
*/
|
|
53
77
|
quickCommand = this.query(removeAuthorizationParam(getQuickCommandV1QuickCommandsSlugGet))
|
|
78
|
+
/**
|
|
79
|
+
* Lists the knowledge sources according to filters passed as parameter.
|
|
80
|
+
*/
|
|
54
81
|
knowledgeSources = this.query(removeAuthorizationParam(listKnowledgeSourcesV1KnowledgeSourcesGet))
|
|
82
|
+
/**
|
|
83
|
+
* Gets a knowledge source by its slug.
|
|
84
|
+
*/
|
|
55
85
|
knowledgeSource = this.query(removeAuthorizationParam(findKnowledgeSourceV1KnowledgeSourcesSlugGet))
|
|
86
|
+
/**
|
|
87
|
+
* Gets a knowledge source document by the slug of the parent knowledge source and the document id.
|
|
88
|
+
*/
|
|
56
89
|
knowledgeSourceDocument = this.query(removeAuthorizationParam(findKnowledgeObjectByCustomIdV1KnowledgeSourcesSlugObjectsCustomIdGet))
|
|
90
|
+
/**
|
|
91
|
+
* Gets the chat history. This is a paginated resource.
|
|
92
|
+
*/
|
|
57
93
|
chats = this.infiniteQuery(removeAuthorizationParam(listConversationsV1ConversationsGet))
|
|
94
|
+
/**
|
|
95
|
+
* Gets a specific chat from the history according to its id.
|
|
96
|
+
*/
|
|
58
97
|
chat = this.query(removeAuthorizationParam(
|
|
59
98
|
conversationHistoryV1ConversationsConversationIdGet as ReplaceResult<
|
|
60
99
|
typeof conversationHistoryV1ConversationsConversationIdGet,
|
|
61
100
|
FixedConversationResponse
|
|
62
101
|
>,
|
|
63
102
|
))
|
|
103
|
+
/**
|
|
104
|
+
* Deletes a chat from the chat history.
|
|
105
|
+
*/
|
|
64
106
|
deleteChat = this.mutation(removeAuthorizationParam(deleteConversationV1ConversationsConversationIdDelete))
|
|
107
|
+
/**
|
|
108
|
+
* Gets a plain text version of the chat with id passed as parameter.
|
|
109
|
+
*/
|
|
65
110
|
downloadChat = this.mutation(removeAuthorizationParam(downloadConversationV1ConversationsConversationIdDownloadGet))
|
|
111
|
+
/**
|
|
112
|
+
* Renames a chat.
|
|
113
|
+
*/
|
|
66
114
|
renameChat = this.mutation(removeAuthorizationParam(updateTitleV1ConversationsConversationIdPatch))
|
|
115
|
+
/**
|
|
116
|
+
* Creates an event so it can be used as metric by the product designers (analytics).
|
|
117
|
+
*/
|
|
67
118
|
createEvent = this.mutation(removeAuthorizationParam(postEventV1EventsPost))
|
|
119
|
+
/**
|
|
120
|
+
* Runs a step of type "fetch" of a quick command.
|
|
121
|
+
*/
|
|
68
122
|
fetchStepOfQuickCommand = this.mutation(removeAuthorizationParam(formatFetchStepV1QuickCommandsSlugStepsStepSlugFetchFormatPost))
|
|
123
|
+
/**
|
|
124
|
+
* Runs a step of type "llm" of a quick command.
|
|
125
|
+
*/
|
|
69
126
|
llmStepOfQuickCommand = this.mutation(removeAuthorizationParam(quickCommandsRunV2V2QuickCommandsSlugStepsStepSlugRunPost))
|
|
127
|
+
/**
|
|
128
|
+
* Formats the result of a quick command into a human-readable text (markdown).
|
|
129
|
+
*/
|
|
70
130
|
formatResultOfQuickCommand = this.mutation(removeAuthorizationParam(formatResultV1QuickCommandsSlugResultFormatPost))
|
|
71
131
|
/**
|
|
72
|
-
|
|
73
|
-
|
|
132
|
+
* Lists the resources of type "$type" marked as favorites.
|
|
133
|
+
*/
|
|
74
134
|
listFavoritesByType = this.query(removeAuthorizationParam(getFavoritesByTypeV1FavoritesGet))
|
|
75
135
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
136
|
+
* Removes the resource of type "favoriteRequest.type" from the list of favorites.
|
|
137
|
+
*/
|
|
78
138
|
removeFavorite = this.mutation(removeAuthorizationParam(deleteFavoriteV1FavoritesDelete))
|
|
79
139
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
140
|
+
* Adds the resource of type "favoriteRequest.type" to the list of favorites.
|
|
141
|
+
*/
|
|
82
142
|
addFavorite = this.mutation(removeAuthorizationParam(addFavoriteV1FavoritesPost))
|
|
83
143
|
|
|
84
|
-
|
|
144
|
+
private static async toolsOfAgent(agentId?: string) {
|
|
145
|
+
try {
|
|
146
|
+
const agent = agentId ? await agentClient.agent.query({ agentId }) : undefined
|
|
147
|
+
if (!agent) return []
|
|
148
|
+
const tools: (Omit<ChatAgentTool, 'duration' | 'prompt' | 'output'>)[] = []
|
|
149
|
+
agent.toolkits?.builtins?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
|
|
150
|
+
if (id) tools.push({ image: kit.image_url, id, name: name || id, description })
|
|
151
|
+
}))
|
|
152
|
+
return tools
|
|
153
|
+
} catch {
|
|
154
|
+
return []
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
sendChatMessage(request: FixedChatRequest, minChangeIntervalMS?: number): StreamedJson<ChatResponseWithSteps> {
|
|
85
159
|
const abortController = new AbortController()
|
|
86
160
|
const headers = {
|
|
87
161
|
'Content-Type': 'application/json',
|
|
@@ -91,7 +165,92 @@ class AIClient extends ReactQueryNetworkClient {
|
|
|
91
165
|
this.resolveURL('v3/chat'),
|
|
92
166
|
{ method: 'post', body: JSON.stringify(request), headers, signal: abortController.signal },
|
|
93
167
|
)
|
|
94
|
-
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* This function treats events in the streaming that deals with the execution of tools. Since these events are not concatenated like
|
|
171
|
+
* normal streamings of data, we need this separate function to deal with them. It transforms the internal data model of the
|
|
172
|
+
* StreamedJson object whenever an event is triggered.
|
|
173
|
+
*/
|
|
174
|
+
async function transform(event: Partial<FixedChatResponse>, data: Partial<ChatResponseWithSteps>) {
|
|
175
|
+
const info = event.agent_info
|
|
176
|
+
if (!info) return
|
|
177
|
+
data.steps = data.steps ? [...data.steps] : []
|
|
178
|
+
|
|
179
|
+
if (info.type === 'planning' && info.action === 'end') {
|
|
180
|
+
const tools = await AIClient.toolsOfAgent(request.context?.agent_id)
|
|
181
|
+
data.steps.push(
|
|
182
|
+
{ id: 'planning', type: 'planning', duration: info.duration, input: info.data?.plan_goal ?? '', status: 'success' },
|
|
183
|
+
)
|
|
184
|
+
info.data?.steps.forEach(s => data.steps?.push({
|
|
185
|
+
id: s.id,
|
|
186
|
+
type: 'step',
|
|
187
|
+
input: s.goal,
|
|
188
|
+
status: 'pending',
|
|
189
|
+
tools: s.tools?.map(t => ({
|
|
190
|
+
...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
|
|
191
|
+
executionId: t.tool_execution_id,
|
|
192
|
+
})),
|
|
193
|
+
}))
|
|
194
|
+
data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (info.type === 'step' && info.action === 'start') {
|
|
198
|
+
const step = data.steps.find(s => s.id === info.id)
|
|
199
|
+
if (step) step.status = 'running'
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (info.type === 'step' && info.action === 'end') {
|
|
203
|
+
const step = data.steps.find(s => s.id === info.id)
|
|
204
|
+
if (step) {
|
|
205
|
+
step.status = 'success'
|
|
206
|
+
step.duration = info.duration
|
|
207
|
+
step.output = last(step.tools)?.output
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (info.type === 'tool' && info.action === 'start') {
|
|
212
|
+
const currentStep = data.steps.find(s => s.status === 'running')
|
|
213
|
+
const tool = currentStep?.tools?.find(t => t.executionId === info.id)
|
|
214
|
+
if (tool) {
|
|
215
|
+
tool.input = info.data ? JSON.stringify(info.data.input, null, 2) : undefined
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (info.type === 'tool' && info.action === 'end') {
|
|
220
|
+
const currentStep = data.steps.find(s => s.status === 'running')
|
|
221
|
+
const tool = currentStep?.tools?.find(t => t.executionId === info.id)
|
|
222
|
+
if (tool) {
|
|
223
|
+
tool.output = info.data?.output
|
|
224
|
+
tool.duration ??= 0
|
|
225
|
+
tool.duration += info.duration ?? 0
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (info.type === 'final_answer' && info.action === 'start') {
|
|
230
|
+
// if we get a "final_answer" event while there's a previous step still running, it means that step has failed.
|
|
231
|
+
data.steps?.forEach((s) => {
|
|
232
|
+
if (s.type === 'step' && s.status === 'running') s.status = 'error'
|
|
233
|
+
})
|
|
234
|
+
const answerStep = last(data.steps)
|
|
235
|
+
if (answerStep) answerStep.status = 'running'
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (info.type === 'final_answer' && info.action === 'end') {
|
|
239
|
+
const answerStep = last(data.steps)
|
|
240
|
+
if (answerStep) {
|
|
241
|
+
answerStep.status = 'success'
|
|
242
|
+
answerStep.duration = info.duration
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return new StreamedJson({
|
|
248
|
+
eventsPromise: events,
|
|
249
|
+
abortController,
|
|
250
|
+
minChangeIntervalMS,
|
|
251
|
+
ignoreKeys: ['agent_info'],
|
|
252
|
+
transform,
|
|
253
|
+
})
|
|
95
254
|
}
|
|
96
255
|
|
|
97
256
|
contentDependencies = this.query(removeAuthorizationParam(
|
package/src/client/types.ts
CHANGED
|
@@ -227,6 +227,78 @@ export interface FixedAddResourceToWorkspaceAi {
|
|
|
227
227
|
error_id: string[],
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
export interface ChatAgentTool {
|
|
231
|
+
id: string,
|
|
232
|
+
executionId?: string,
|
|
233
|
+
duration?: number,
|
|
234
|
+
name: string,
|
|
235
|
+
description?: string,
|
|
236
|
+
image?: string,
|
|
237
|
+
input?: string,
|
|
238
|
+
output?: string,
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface ChatStep {
|
|
242
|
+
id: string,
|
|
243
|
+
type: 'planning' | 'step' | 'answer',
|
|
244
|
+
duration?: number,
|
|
245
|
+
input?: string,
|
|
246
|
+
output?: string,
|
|
247
|
+
status: 'pending' | 'running' | 'success' | 'error',
|
|
248
|
+
tools?: ChatAgentTool[],
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface BaseAgentInfo {
|
|
252
|
+
type: 'chat' | 'planning' | 'step' | 'tool' | 'final_answer',
|
|
253
|
+
action: 'start' | 'end',
|
|
254
|
+
duration?: number,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface PlanningAgentInfo extends BaseAgentInfo {
|
|
258
|
+
type: 'planning',
|
|
259
|
+
data?: {
|
|
260
|
+
plan_goal: string,
|
|
261
|
+
total_steps: number,
|
|
262
|
+
steps: {
|
|
263
|
+
id: string,
|
|
264
|
+
goal: string,
|
|
265
|
+
tools?: {
|
|
266
|
+
tool_id: string,
|
|
267
|
+
tool_execution_id: string,
|
|
268
|
+
}[],
|
|
269
|
+
}[],
|
|
270
|
+
},
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface StepAgentInfo extends BaseAgentInfo {
|
|
274
|
+
type: 'step',
|
|
275
|
+
id: string,
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface ToolAgentInfo extends BaseAgentInfo {
|
|
279
|
+
type: 'tool',
|
|
280
|
+
id: string,
|
|
281
|
+
data?: {
|
|
282
|
+
input?: any,
|
|
283
|
+
attempt: number,
|
|
284
|
+
output?: string,
|
|
285
|
+
},
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface GenericAgentInfo extends BaseAgentInfo {
|
|
289
|
+
type: 'chat' | 'final_answer',
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export type AgentInfo = GenericAgentInfo | PlanningAgentInfo | StepAgentInfo | ToolAgentInfo
|
|
293
|
+
|
|
294
|
+
export interface FixedChatResponse extends ChatResponse3 {
|
|
295
|
+
agent_info: AgentInfo,
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface ChatResponseWithSteps extends FixedChatResponse {
|
|
299
|
+
steps: ChatStep[],
|
|
300
|
+
}
|
|
301
|
+
|
|
230
302
|
export type OazapftsFunction<Variables = any, Result = any> = (variables: Variables, opts?: RequestOpts) => Promise<Result>
|
|
231
303
|
|
|
232
304
|
type Unpromisify<T> = T extends Promise<infer R> ? Unpromisify<R> : T
|