@stack-spot/portal-network 1.0.0-dev.1768423147036 → 1.0.0-stg.1768484124183

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.
Files changed (54) hide show
  1. package/dist/api/agent-tools.d.ts +151 -614
  2. package/dist/api/agent-tools.d.ts.map +1 -1
  3. package/dist/api/agent-tools.js +45 -168
  4. package/dist/api/agent-tools.js.map +1 -1
  5. package/dist/api/ai.d.ts +2 -3
  6. package/dist/api/ai.d.ts.map +1 -1
  7. package/dist/api/ai.js +2 -1
  8. package/dist/api/ai.js.map +1 -1
  9. package/dist/api/genAiInference.d.ts +49 -2
  10. package/dist/api/genAiInference.d.ts.map +1 -1
  11. package/dist/api/genAiInference.js +55 -2
  12. package/dist/api/genAiInference.js.map +1 -1
  13. package/dist/api/workspace-ai.d.ts +0 -41
  14. package/dist/api/workspace-ai.d.ts.map +1 -1
  15. package/dist/api/workspace-ai.js +0 -34
  16. package/dist/api/workspace-ai.js.map +1 -1
  17. package/dist/client/agent-tools.d.ts +3 -130
  18. package/dist/client/agent-tools.d.ts.map +1 -1
  19. package/dist/client/agent-tools.js +2 -105
  20. package/dist/client/agent-tools.js.map +1 -1
  21. package/dist/client/ai.d.ts +2 -3
  22. package/dist/client/ai.d.ts.map +1 -1
  23. package/dist/client/ai.js +1 -251
  24. package/dist/client/ai.js.map +1 -1
  25. package/dist/client/discover.d.ts +2 -2
  26. package/dist/client/discover.d.ts.map +1 -1
  27. package/dist/client/discover.js +4 -3
  28. package/dist/client/discover.js.map +1 -1
  29. package/dist/client/gen-ai-inference.d.ts +4 -0
  30. package/dist/client/gen-ai-inference.d.ts.map +1 -1
  31. package/dist/client/gen-ai-inference.js +267 -0
  32. package/dist/client/gen-ai-inference.js.map +1 -1
  33. package/dist/client/types.d.ts +13 -14
  34. package/dist/client/types.d.ts.map +1 -1
  35. package/dist/client/workspace-ai.d.ts +3 -13
  36. package/dist/client/workspace-ai.d.ts.map +1 -1
  37. package/dist/client/workspace-ai.js +3 -17
  38. package/dist/client/workspace-ai.js.map +1 -1
  39. package/dist/utils/StreamedJson.d.ts +7 -1
  40. package/dist/utils/StreamedJson.d.ts.map +1 -1
  41. package/dist/utils/StreamedJson.js +10 -2
  42. package/dist/utils/StreamedJson.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/api/agent-tools.ts +196 -813
  45. package/src/api/ai.ts +3 -3
  46. package/src/api/genAiInference.ts +119 -3
  47. package/src/api/workspace-ai.ts +0 -83
  48. package/src/client/agent-tools.ts +2 -55
  49. package/src/client/ai.ts +1 -266
  50. package/src/client/discover.ts +7 -6
  51. package/src/client/gen-ai-inference.ts +281 -0
  52. package/src/client/types.ts +14 -14
  53. package/src/client/workspace-ai.ts +6 -21
  54. package/src/utils/StreamedJson.tsx +11 -2
package/src/api/ai.ts CHANGED
@@ -384,7 +384,6 @@ 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;
388
387
  use_uploaded_files?: boolean;
389
388
  agent_built_in?: boolean | null;
390
389
  next_step_slug?: string | null;
@@ -872,7 +871,6 @@ export type ChatRequest = {
872
871
  } | null;
873
872
  user_prompt: string;
874
873
  project_id?: string | null;
875
- agent_version_number?: number | null;
876
874
  };
877
875
  export type SourceProjectFile3 = {
878
876
  "type": "project_file";
@@ -4063,13 +4061,14 @@ export function devAssistantV3V3ChatPost({ authorization, xAccountId, xMemberId,
4063
4061
  /**
4064
4062
  * List All
4065
4063
  */
4066
- export function listAllV3QuickCommandsGet({ name, slug, size, page, visibilityList, order, types, authorization, xAccountId, xMemberId, xUsername }: {
4064
+ export function listAllV3QuickCommandsGet({ name, slug, size, page, visibilityList, order, isRemote, types, authorization, xAccountId, xMemberId, xUsername }: {
4067
4065
  name?: string | null;
4068
4066
  slug?: string | null;
4069
4067
  size?: number;
4070
4068
  page?: number;
4071
4069
  visibilityList?: VisibilityLevelEnum[] | null;
4072
4070
  order?: OrderEnum | null;
4071
+ isRemote?: boolean;
4073
4072
  types?: QuickCommandTypeRequest[] | null;
4074
4073
  authorization: string;
4075
4074
  xAccountId?: string | null;
@@ -4091,6 +4090,7 @@ export function listAllV3QuickCommandsGet({ name, slug, size, page, visibilityLi
4091
4090
  page,
4092
4091
  visibility_list: visibilityList,
4093
4092
  order,
4093
+ is_remote: isRemote,
4094
4094
  types
4095
4095
  }))}`, {
4096
4096
  ...opts,
@@ -252,7 +252,23 @@ export type ChatRequest = {
252
252
  return_ks_in_response?: boolean;
253
253
  upload_ids?: string[];
254
254
  execution_id?: string | null;
255
+ conversation_id?: string | null;
256
+ use_conversation?: boolean;
255
257
  selected_model?: string | null;
258
+ workspace_id?: string | null;
259
+ stack_id?: string | null;
260
+ knowledge_sources?: string[];
261
+ deep_search_ks?: boolean;
262
+ show_chat_processing_state?: boolean;
263
+ };
264
+ export type PromptTokensCurrentUsageResponse = {
265
+ used: number;
266
+ limit: number;
267
+ renewal_date: string;
268
+ };
269
+ export type PromptTokensMonthlyUsageResponse = {
270
+ used: number;
271
+ month: number;
256
272
  };
257
273
  /**
258
274
  * Health Check
@@ -582,7 +598,7 @@ export function listLlmProvidersV1LlmProvidersGet({ acceptsSelfHosted, xAccountI
582
598
  /**
583
599
  * Handle completions requests
584
600
  */
585
- export function createCompletionsV1ChatCompletionsPost({ xAccountId, authorization, xRequestOrigin, xConversationId, xMessageId, xQcExecutionId, xQcSlug, xPlatformVersion, chatCompletion }: {
601
+ export function createCompletionsV1ChatCompletionsPost({ xAccountId, authorization, xRequestOrigin, xConversationId, xMessageId, xQcExecutionId, xQcSlug, xStackspotAiVersion, chatCompletion }: {
586
602
  xAccountId?: string | null;
587
603
  authorization: string;
588
604
  xRequestOrigin?: string | null;
@@ -590,7 +606,7 @@ export function createCompletionsV1ChatCompletionsPost({ xAccountId, authorizati
590
606
  xMessageId?: string | null;
591
607
  xQcExecutionId?: string | null;
592
608
  xQcSlug?: string | null;
593
- xPlatformVersion?: string | null;
609
+ xStackspotAiVersion?: string | null;
594
610
  chatCompletion: ChatCompletion;
595
611
  }, opts?: Oazapfts.RequestOpts) {
596
612
  return oazapfts.ok(oazapfts.fetchJson<{
@@ -613,7 +629,7 @@ export function createCompletionsV1ChatCompletionsPost({ xAccountId, authorizati
613
629
  "x-message-id": xMessageId,
614
630
  "x-qc-execution-id": xQcExecutionId,
615
631
  "x-qc-slug": xQcSlug,
616
- "x-platform-version": xPlatformVersion
632
+ "x-stackspot-ai-version": xStackspotAiVersion
617
633
  })
618
634
  })));
619
635
  }
@@ -644,3 +660,103 @@ export function agentChatV1AgentAgentIdChatPost({ agentId, xAccountId, authoriza
644
660
  })
645
661
  })));
646
662
  }
663
+ /**
664
+ * Total
665
+ */
666
+ export function totalV1PromptTokensUsageTotalGet({ xAccountId, authorization }: {
667
+ xAccountId?: string | null;
668
+ authorization: string;
669
+ }, opts?: Oazapfts.RequestOpts) {
670
+ return oazapfts.ok(oazapfts.fetchJson<{
671
+ status: 200;
672
+ data: PromptTokensCurrentUsageResponse;
673
+ } | {
674
+ status: 404;
675
+ } | {
676
+ status: 422;
677
+ data: HttpValidationError;
678
+ }>("/v1/prompt-tokens-usage/total", {
679
+ ...opts,
680
+ headers: oazapfts.mergeHeaders(opts?.headers, {
681
+ "x-account-id": xAccountId,
682
+ authorization
683
+ })
684
+ }));
685
+ }
686
+ /**
687
+ * Current
688
+ */
689
+ export function currentV1PromptTokensUsageCurrentGet({ xAccountId, authorization }: {
690
+ xAccountId?: string | null;
691
+ authorization: string;
692
+ }, opts?: Oazapfts.RequestOpts) {
693
+ return oazapfts.ok(oazapfts.fetchJson<{
694
+ status: 200;
695
+ data: PromptTokensCurrentUsageResponse;
696
+ } | {
697
+ status: 404;
698
+ } | {
699
+ status: 422;
700
+ data: HttpValidationError;
701
+ }>("/v1/prompt-tokens-usage/current", {
702
+ ...opts,
703
+ headers: oazapfts.mergeHeaders(opts?.headers, {
704
+ "x-account-id": xAccountId,
705
+ authorization
706
+ })
707
+ }));
708
+ }
709
+ /**
710
+ * Monthly
711
+ */
712
+ export function monthlyV1PromptTokensUsageMonthlyGet({ year, xAccountId, authorization }: {
713
+ year: number;
714
+ xAccountId?: string | null;
715
+ authorization: string;
716
+ }, opts?: Oazapfts.RequestOpts) {
717
+ return oazapfts.ok(oazapfts.fetchJson<{
718
+ status: 200;
719
+ data: PromptTokensMonthlyUsageResponse[];
720
+ } | {
721
+ status: 404;
722
+ } | {
723
+ status: 422;
724
+ data: HttpValidationError;
725
+ }>(`/v1/prompt-tokens-usage/monthly${QS.query(QS.explode({
726
+ year
727
+ }))}`, {
728
+ ...opts,
729
+ headers: oazapfts.mergeHeaders(opts?.headers, {
730
+ "x-account-id": xAccountId,
731
+ authorization
732
+ })
733
+ }));
734
+ }
735
+ /**
736
+ * Top Users
737
+ */
738
+ export function topUsersV1PromptTokensUsageTopUsersGet({ year, month, xAccountId, authorization }: {
739
+ year: number;
740
+ month: number;
741
+ xAccountId?: string | null;
742
+ authorization: string;
743
+ }, opts?: Oazapfts.RequestOpts) {
744
+ return oazapfts.ok(oazapfts.fetchJson<{
745
+ status: 200;
746
+ data: any;
747
+ } | {
748
+ status: 404;
749
+ } | {
750
+ status: 422;
751
+ data: HttpValidationError;
752
+ }>(`/v1/prompt-tokens-usage/top-users${QS.query(QS.explode({
753
+ year,
754
+ month
755
+ }))}`, {
756
+ ...opts,
757
+ headers: oazapfts.mergeHeaders(opts?.headers, {
758
+ "x-account-id": xAccountId,
759
+ authorization
760
+ })
761
+ }));
762
+ }
@@ -84,13 +84,6 @@ 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
- };
94
87
  export type ActionShared = "VIEW" | "EDIT" | "GRANT_ACESS";
95
88
  export type PermissionForSharedRequest = {
96
89
  userId: string;
@@ -107,12 +100,6 @@ export type ResourceMembersResponse = {
107
100
  name: string;
108
101
  actions: string[];
109
102
  };
110
- export type ResourceMembersPaginatedResponse = {
111
- items: ResourceMembersResponse[];
112
- page: number;
113
- size: number;
114
- total_pages: number;
115
- };
116
103
  /**
117
104
  * Create Workspace
118
105
  */
@@ -547,36 +534,6 @@ export function listAllContentsV1WorkspacesWorkspaceIdContentsGet({ workspaceId,
547
534
  })
548
535
  }));
549
536
  }
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
- }
580
537
  /**
581
538
  * Use Shareable Link
582
539
  */
@@ -696,46 +653,6 @@ export function listMembersV1ResourceTypeResourceTypeResourcesResourceIdentifier
696
653
  })
697
654
  }));
698
655
  }
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
- }
739
656
  /**
740
657
  * Healthz
741
658
  */
@@ -1,6 +1,6 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
2
  import { getApiAddresses } from '../api-addresses'
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'
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, searchAgentsV1AgentsSearchPost, shareV1AgentsAgentIdSharePost, updateAgentV1AgentsAgentIdPatch, 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,7 +13,6 @@ 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)
17
16
  const listToolkitsAuthorization = removeAuthorizationParam(listToolkitsV2ToolkitsGet)
18
17
 
19
18
  class AgentToolsClient extends ReactQueryNetworkClient {
@@ -31,7 +30,6 @@ class AgentToolsClient extends ReactQueryNetworkClient {
31
30
  tools = this.query(removeAuthorizationParam(getPublicToolKitsV1BuiltinToolkitGet))
32
31
 
33
32
  /**
34
- * @deprecated
35
33
  * Create agent
36
34
  */
37
35
  createAgent = this.mutation(removeAuthorizationParam(createAgentV1AgentsPost))
@@ -42,7 +40,6 @@ class AgentToolsClient extends ReactQueryNetworkClient {
42
40
  deleteAgent = this.mutation(removeAuthorizationParam(deleteAgentV1AgentsAgentIdDelete))
43
41
 
44
42
  /**
45
- * @deprecated
46
43
  * Updates an agent
47
44
  */
48
45
  updateAgent = this.mutation(removeAuthorizationParam(updateAgentV1AgentsAgentIdPatch))
@@ -81,16 +78,14 @@ class AgentToolsClient extends ReactQueryNetworkClient {
81
78
  availableAgentsForMultiAgentAddition = this.query(removeAuthorizationParam(listMultiAgentsV1AgentsMultiAgentsGet))
82
79
 
83
80
  /**
84
- * @deprecated
85
81
  * Gets agent by id
86
82
  */
87
83
  agent = this.query(removeAuthorizationParam(getAgentV1AgentsAgentIdGet))
88
84
 
89
85
  /**
90
- * @deprecated
91
86
  * Gets agents by ids
92
87
  */
93
- agentsByIds = this.query(removeAuthorizationParam(searchAgentsByIdsV1AgentsSearchPost))
88
+ agentsByIds = this.query(removeAuthorizationParam(searchAgentsV1AgentsSearchPost))
94
89
 
95
90
  /**
96
91
  * Gets the default agent slug
@@ -243,54 +238,6 @@ class AgentToolsClient extends ReactQueryNetworkClient {
243
238
  * remove an agent from favorites
244
239
  */
245
240
  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
- })
294
241
  }
295
242
 
296
243
  export const agentToolsClient = new AgentToolsClient()
package/src/client/ai.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
- import { findLast, isArray, last } from 'lodash'
2
+ import { isArray } from 'lodash'
3
3
  import { getApiAddresses } from '../api-addresses'
4
4
  import {
5
5
  addFavoriteV1AiStacksStackIdFavoritePost,
@@ -61,18 +61,10 @@ import { StackspotAPIError } from '../error/StackspotAPIError'
61
61
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
62
62
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
63
63
  import { StreamedJson } from '../utils/StreamedJson'
64
- import { formatJson } from '../utils/string'
65
- import { agentToolsClient } from './agent-tools'
66
64
  import {
67
- AgentInfo,
68
- ChatAgentTool,
69
- ChatResponseWithSteps,
70
- FixedChatRequest,
71
- FixedChatResponse,
72
65
  FixedConversationResponse,
73
66
  FixedDependencyResponse,
74
67
  ReplaceResult,
75
- StepChatStep,
76
68
  } from './types'
77
69
 
78
70
  const listQAV3WithoutAuthorization = removeAuthorizationParam(listAllV3QuickCommandsGet)
@@ -340,263 +332,6 @@ class AIClient extends ReactQueryNetworkClient {
340
332
  deleteReviewComment = this.mutation(
341
333
  removeAuthorizationParam(deleteReviewCommentV1ResourcesResourceTypeSlugResourceSlugReviewsReviewIdAnswersAnswerIdDelete))
342
334
 
343
- private static async toolsOfAgent(agentId?: string, agent_version_number?: number) {
344
- try {
345
- const agent = agentId ? await agentToolsClient.agentV2.query({
346
- agentCoreId: agentId, versionNumber: agent_version_number }) : undefined
347
- if (!agent) return []
348
- const tools: (Omit<ChatAgentTool, 'duration' | 'prompt' | 'output'>)[] = []
349
- agent.version?.toolkits?.builtin_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
350
- if (id) tools.push({ image: kit.image_url, id, name: name || id, description })
351
- }))
352
- agent.version?.toolkits?.custom_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
353
- if (id) tools.push({ image: kit.avatar ?? undefined, id, name: name || id, description })
354
- }))
355
- return tools
356
- } catch {
357
- return []
358
- }
359
- }
360
-
361
- sendChatMessage(request: FixedChatRequest, minChangeIntervalMS?: number): StreamedJson<ChatResponseWithSteps> {
362
- const abortController = new AbortController()
363
- const headers = {
364
- 'Content-Type': 'application/json',
365
- 'Accept': 'text/event-stream',
366
- }
367
- const events = this.stream(
368
- this.resolveURL('v3/chat'),
369
- { method: 'post', body: JSON.stringify(request), headers, signal: abortController.signal },
370
- )
371
-
372
- const DYNAMIC_TOOL_ID = 'dynamic'
373
- function isDynamicTool(info: AgentInfo) {
374
- return info.type === 'tool' && info.id === DYNAMIC_TOOL_ID
375
- }
376
- /**
377
- * This function treats events in the streaming that deals with the execution of tools. Since these events are not concatenated like
378
- * normal streamings of data, we need this separate function to deal with them. It transforms the internal data model of the
379
- * StreamedJson object whenever an event is triggered.
380
- */
381
- async function transform(event: Partial<FixedChatResponse>, data: Partial<ChatResponseWithSteps>) {
382
- const info = event.agent_info
383
- if (!info) return
384
- const tools = await AIClient.toolsOfAgent(request.context?.agent_id, request.agent_version_number ?? undefined)
385
- data.steps = data.steps ? [...data.steps] : []
386
-
387
- if (info.type === 'planning' && info.action === 'end') {
388
- data.steps.push({
389
- id: 'planning',
390
- type: 'planning',
391
- status: 'success',
392
- duration: info.duration || 0,
393
- steps: info.data?.steps?.map(s => s.goal) ?? [],
394
- goal: info.data?.plan_goal ?? '',
395
- })
396
-
397
- info.data?.steps.forEach(s => data.steps?.push({
398
- id: s.id,
399
- type: 'step',
400
- status: 'pending',
401
- input: s.goal,
402
- attempts: [{
403
- tools: s.tools?.map(t => ({
404
- ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
405
- executionId: t.tool_execution_id,
406
- goal: t.goal,
407
- })),
408
- }],
409
- }))
410
- data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
411
- }
412
-
413
- if (info.type === 'planning' && info.action === 'awaiting_approval') {
414
- data.steps.push({
415
- id: 'planning',
416
- type: 'planning',
417
- status: 'awaiting_approval',
418
- user_question: info.data?.user_question,
419
- duration: info.duration || 0,
420
- steps: info.data?.steps?.map(s => s.goal) ?? [],
421
- goal: info.data?.plan_goal ?? '',
422
- })
423
- info.data?.steps.forEach(s => data.steps?.push({
424
- id: s.id,
425
- type: 'step',
426
- status: 'pending',
427
- input: s.goal,
428
- attempts: [{
429
- tools: s.tools?.map(t => ({
430
- ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
431
- executionId: t.tool_execution_id,
432
- goal: t.goal,
433
- })),
434
- }],
435
- }))
436
- data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
437
- }
438
-
439
- if (info.type === 'step' && info.action === 'start') {
440
- const step = data.steps.find(s => s.id === info.id)
441
- if (step) step.status = 'running'
442
- }
443
-
444
- if (info.type === 'step' && info.action === 'end') {
445
- const step = data.steps.find(s => s.id === info.id) as StepChatStep
446
- if (step) {
447
- step.status = 'success'
448
- step.duration = info.duration
449
- const lastToolId = last(step.attempts[0].tools)?.id
450
- const lastAttemptOfLastTool = findLast(step.attempts.map(a => a.tools).flat(), t => t?.id === lastToolId)
451
- step.output = lastAttemptOfLastTool?.output
452
- }
453
- }
454
-
455
- if (info.type === 'tool_calls' && info.action === 'start') {
456
- const hasPlanning = data.steps.find(s => s.type === 'planning')
457
- // On the first tool_calls:start, create the synthetic planning ("dynamic") step.
458
- if (!hasPlanning) {
459
- const userPrompt = request.user_prompt === 'string' ? request.user_prompt : JSON.stringify(request.user_prompt)
460
- data.steps.push({
461
- id: 'dynamic',
462
- type: 'planning',
463
- status: 'success',
464
- steps: [],
465
- goal: userPrompt,
466
- user_question: userPrompt,
467
- })
468
- }
469
- const toolsStepId = data.steps.filter(s => s.id === 'tools' || s.id.startsWith('tools-')).length + 1
470
- data.steps.push({
471
- id: `tools-${toolsStepId.toString()}`,
472
- type: 'step',
473
- status: 'running',
474
- attempts: [{ tools: [] }],
475
- } as StepChatStep)
476
- }
477
-
478
- if (info.type === 'tool_calls' && info.action === 'end') {
479
- const lastStep = findLast(data.steps, s => s.id === 'tools' || s.id.startsWith('tools-')) as StepChatStep
480
- if (lastStep) {
481
- lastStep.status = 'success'
482
- lastStep.duration = info.duration
483
- const lastAttemptOfLastTool = last(lastStep.attempts.map(a => a.tools).flat())
484
- lastStep.output = lastAttemptOfLastTool?.output
485
- }
486
- }
487
-
488
- if (info.type === 'tool' && info.action === 'awaiting_approval') {
489
- const tool = tools.find(({ id }) => id === info.data?.tool_id)
490
- data.steps.push({
491
- id: info.id,
492
- type: 'tool',
493
- status: 'awaiting_approval',
494
- duration: info.duration || 0,
495
- input: info.data?.input,
496
- user_question: info.data?.user_question,
497
- attempts: [{
498
- tools: [{
499
- executionId: info.id,
500
- id: info.data?.tool_id ?? '',
501
- name: tool?.name ?? '',
502
- goal: tool?.goal,
503
- ...tool,
504
- }],
505
- }],
506
- })
507
- data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
508
- }
509
-
510
- if (info.type === 'tool' && info.action === 'start') {
511
- if (!info.data) return
512
- const input = formatJson(info.data.input)
513
- const tool = findLast(tools, ({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
514
-
515
- const currentStep = findLast(data.steps, s => s.status === 'running') as StepChatStep
516
-
517
- //There might be a tool with status awaiting_approval, so we want to inform tool has already started
518
- if (!currentStep || !currentStep?.attempts?.[0]?.tools) {
519
- data.steps.push({
520
- id: info.id,
521
- type: 'tool',
522
- status: 'running',
523
- duration: info.duration || 0,
524
- input: info.data?.input,
525
- user_question: info.data?.user_question,
526
- attempts: [{
527
- tools: [{ ...tool, executionId: info.id, input }],
528
- }],
529
- })
530
- } else {
531
- const toolInFirstAttempt = findLast(currentStep?.attempts?.[0]?.tools, t => t.executionId === info.id)
532
- //One step might have multiple tools. When in an approval mode, we might not have all the tools in the array yet.
533
- //For dynamic tools (id === 'dynamic'), we always push a new tool, since dynamic executions can trigger
534
- //multiple tool runs in the same step and do not follow the planned tool structure.
535
- //So we make sure to add any tools that are not in there, or always add for dynamic tools.
536
- if (!toolInFirstAttempt || isDynamicTool(info)) {
537
- currentStep.attempts?.[0].tools?.push({
538
- ...tool,
539
- executionId: info.id,
540
- input,
541
- status: 'running',
542
- })
543
- } else {
544
- const input = formatJson(info.data.input)
545
- if (info.data.attempt === 1) {
546
- toolInFirstAttempt.input = input
547
- } else {
548
- currentStep.attempts[info.data.attempt - 1] ??= { tools: [] }
549
- currentStep.attempts[info.data.attempt - 1].tools?.push({
550
- ...tool,
551
- executionId: info.id,
552
- input,
553
- })
554
- }
555
- }
556
- }
557
- }
558
-
559
- if (info.type === 'tool' && info.action === 'end') {
560
- const currentStep = data.steps.find(s => s.status === 'running') as StepChatStep
561
- if (!currentStep || !info.data) return
562
-
563
- // attempt index for tool execution starts at 0 for dynamically executed tools,while for planned tools it starts at 1
564
- const attempt = isDynamicTool(info) ? info.data.attempt : info.data.attempt - 1
565
- const tool = last(currentStep?.attempts?.[attempt]?.tools)
566
- if (tool) {
567
- tool.output = formatJson(info.data.output)
568
- tool.duration = info.duration
569
- tool.status = 'success'
570
- }
571
- }
572
-
573
- if (info.type === 'final_answer' && info.action === 'start') {
574
- const answerStep = last(data.steps)
575
- if (answerStep) answerStep.status = 'running'
576
- }
577
-
578
-
579
- if (info.type === 'chat' && info.action === 'end') {
580
- const lastStep = last(data.steps)
581
- if (lastStep?.type === 'answer') {
582
- lastStep.status = 'success'
583
- lastStep.duration = info.duration
584
- } else {
585
- data.steps.push({ id: 'answer', type: 'answer', status: 'success' })
586
- }
587
- }
588
- }
589
-
590
- return new StreamedJson({
591
- eventsPromise: events,
592
- abortController,
593
- minChangeIntervalMS,
594
- ignoreKeys: ['agent_info'],
595
- transform,
596
- textFromErrorEvent: data => data.answer ?? 'Unknown error',
597
- })
598
- }
599
-
600
335
  contentDependencies = this.query(removeAuthorizationParam(
601
336
  getContentDependenciesV1ContentContentTypeContentIdDependenciesGet as ReplaceResult<
602
337
  typeof getContentDependenciesV1ContentContentTypeContentIdDependenciesGet,