@stack-spot/portal-network 0.218.0 → 0.218.1

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.
@@ -10,7 +10,7 @@ export class StreamedJson {
10
10
  * @param response the fetch response.
11
11
  * @param minChangeIntervalMS a stream can be too fast. This sets a minimum interval between running the listeners. The default is 50ms.
12
12
  */
13
- constructor({ eventsPromise, abortController, minChangeIntervalMS = 50, transform, ignoreKeys, textFromErrorEvent }) {
13
+ constructor({ eventsPromise, abortController, minChangeIntervalMS = 50, minChangeIntervalMSFromEvent, transform, ignoreKeys, textFromErrorEvent }) {
14
14
  Object.defineProperty(this, "onChangeListeners", {
15
15
  enumerable: true,
16
16
  configurable: true,
@@ -53,6 +53,12 @@ export class StreamedJson {
53
53
  writable: true,
54
54
  value: void 0
55
55
  });
56
+ Object.defineProperty(this, "minChangeIntervalMSFromEvent", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
56
62
  Object.defineProperty(this, "textFromErrorEvent", {
57
63
  enumerable: true,
58
64
  configurable: true,
@@ -62,6 +68,7 @@ export class StreamedJson {
62
68
  this.abortController = abortController;
63
69
  this.transform = transform;
64
70
  this.ignoreKeys = ignoreKeys;
71
+ this.minChangeIntervalMSFromEvent = minChangeIntervalMSFromEvent;
65
72
  this.run(eventsPromise, minChangeIntervalMS);
66
73
  this.textFromErrorEvent = textFromErrorEvent ?? ((data) => JSON.stringify(data));
67
74
  }
@@ -85,7 +92,8 @@ export class StreamedJson {
85
92
  }
86
93
  await this.transform?.(json, this.data);
87
94
  this.merge(json, this.data);
88
- if (event.event !== 'error' && new Date().getTime() - lastChangeCall >= minChangeIntervalMS) {
95
+ const intervalMS = this.minChangeIntervalMSFromEvent?.(json, this.data) ?? minChangeIntervalMS;
96
+ if (event.event !== 'error' && new Date().getTime() - lastChangeCall >= intervalMS) {
89
97
  this.onChangeListeners.forEach(l => l(this.data));
90
98
  lastChangeCall = new Date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pE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,IAAI,CAAC;gBAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACjF,CAAC,CAAA;IACH,CAAC;IAED,SAAS;QACP,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,OAAO,CAAA;QAC9B,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAA;QAC/C,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAA;IACxD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stack-spot/portal-network",
3
- "version": "0.218.0",
3
+ "version": "0.218.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
+ }
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,
@@ -67,18 +67,10 @@ import { StackspotAPIError } from '../error/StackspotAPIError'
67
67
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
68
68
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
69
69
  import { StreamedJson } from '../utils/StreamedJson'
70
- import { formatJson } from '../utils/string'
71
- import { agentToolsClient } from './agent-tools'
72
70
  import {
73
- AgentInfo,
74
- ChatAgentTool,
75
- ChatResponseWithSteps,
76
- FixedChatRequest,
77
- FixedChatResponse,
78
71
  FixedConversationResponse,
79
72
  FixedDependencyResponse,
80
73
  ReplaceResult,
81
- StepChatStep,
82
74
  } from './types'
83
75
 
84
76
  const listQAV3WithoutAuthorization = removeAuthorizationParam(listAllV3QuickCommandsGet)
@@ -374,262 +366,6 @@ class AIClient extends ReactQueryNetworkClient {
374
366
  deleteReviewComment = this.mutation(
375
367
  removeAuthorizationParam(deleteReviewCommentV1ResourcesResourceTypeSlugResourceSlugReviewsReviewIdAnswersAnswerIdDelete))
376
368
 
377
- private static async toolsOfAgent(agentId?: string) {
378
- try {
379
- const agent = agentId ? await agentToolsClient.agent.query({ agentId }) : undefined
380
- if (!agent) return []
381
- const tools: (Omit<ChatAgentTool, 'duration' | 'prompt' | 'output'>)[] = []
382
- agent.toolkits?.builtin_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
383
- if (id) tools.push({ image: kit.image_url, id, name: name || id, description })
384
- }))
385
- agent.toolkits?.custom_toolkits?.forEach(kit => kit.tools?.forEach(({ id, name, description }) => {
386
- if (id) tools.push({ image: kit.avatar ?? undefined, id, name: name || id, description })
387
- }))
388
- return tools
389
- } catch {
390
- return []
391
- }
392
- }
393
-
394
- sendChatMessage(request: FixedChatRequest, minChangeIntervalMS?: number): StreamedJson<ChatResponseWithSteps> {
395
- const abortController = new AbortController()
396
- const headers = {
397
- 'Content-Type': 'application/json',
398
- 'Accept': 'text/event-stream',
399
- }
400
- const events = this.stream(
401
- this.resolveURL('v3/chat'),
402
- { method: 'post', body: JSON.stringify(request), headers, signal: abortController.signal },
403
- )
404
-
405
- const DYNAMIC_TOOL_ID = 'dynamic'
406
- function isDynamicTool(info: AgentInfo) {
407
- return info.type === 'tool' && info.id === DYNAMIC_TOOL_ID
408
- }
409
- /**
410
- * This function treats events in the streaming that deals with the execution of tools. Since these events are not concatenated like
411
- * normal streamings of data, we need this separate function to deal with them. It transforms the internal data model of the
412
- * StreamedJson object whenever an event is triggered.
413
- */
414
- async function transform(event: Partial<FixedChatResponse>, data: Partial<ChatResponseWithSteps>) {
415
- const info = event.agent_info
416
- if (!info) return
417
- const tools = await AIClient.toolsOfAgent(request.context?.agent_id)
418
- data.steps = data.steps ? [...data.steps] : []
419
-
420
- if (info.type === 'planning' && info.action === 'end') {
421
- data.steps.push({
422
- id: 'planning',
423
- type: 'planning',
424
- status: 'success',
425
- duration: info.duration || 0,
426
- steps: info.data?.steps?.map(s => s.goal) ?? [],
427
- goal: info.data?.plan_goal ?? '',
428
- })
429
-
430
- info.data?.steps.forEach(s => data.steps?.push({
431
- id: s.id,
432
- type: 'step',
433
- status: 'pending',
434
- input: s.goal,
435
- attempts: [{
436
- tools: s.tools?.map(t => ({
437
- ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
438
- executionId: t.tool_execution_id,
439
- goal: t.goal,
440
- })),
441
- }],
442
- }))
443
- data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
444
- }
445
-
446
- if (info.type === 'planning' && info.action === 'awaiting_approval') {
447
- data.steps.push({
448
- id: 'planning',
449
- type: 'planning',
450
- status: 'awaiting_approval',
451
- user_question: info.data?.user_question,
452
- duration: info.duration || 0,
453
- steps: info.data?.steps?.map(s => s.goal) ?? [],
454
- goal: info.data?.plan_goal ?? '',
455
- })
456
- info.data?.steps.forEach(s => data.steps?.push({
457
- id: s.id,
458
- type: 'step',
459
- status: 'pending',
460
- input: s.goal,
461
- attempts: [{
462
- tools: s.tools?.map(t => ({
463
- ...(tools.find(({ id }) => id === t.tool_id) ?? { id: t.tool_id, name: t.tool_id }),
464
- executionId: t.tool_execution_id,
465
- goal: t.goal,
466
- })),
467
- }],
468
- }))
469
- data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
470
- }
471
-
472
- if (info.type === 'step' && info.action === 'start') {
473
- const step = data.steps.find(s => s.id === info.id)
474
- if (step) step.status = 'running'
475
- }
476
-
477
- if (info.type === 'step' && info.action === 'end') {
478
- const step = data.steps.find(s => s.id === info.id) as StepChatStep
479
- if (step) {
480
- step.status = 'success'
481
- step.duration = info.duration
482
- const lastToolId = last(step.attempts[0].tools)?.id
483
- const lastAttemptOfLastTool = findLast(step.attempts.map(a => a.tools).flat(), t => t?.id === lastToolId)
484
- step.output = lastAttemptOfLastTool?.output
485
- }
486
- }
487
-
488
- if (info.type === 'tool_calls' && info.action === 'start') {
489
- const hasPlanning = data.steps.find(s => s.type === 'planning')
490
- // On the first tool_calls:start, create the synthetic planning ("dynamic") step.
491
- if (!hasPlanning) {
492
- const userPrompt = request.user_prompt === 'string' ? request.user_prompt : JSON.stringify(request.user_prompt)
493
- data.steps.push({
494
- id: 'dynamic',
495
- type: 'planning',
496
- status: 'success',
497
- steps: [],
498
- goal: userPrompt,
499
- user_question: userPrompt,
500
- })
501
- }
502
- const toolsStepId = data.steps.filter(s => s.id === 'tools' || s.id.startsWith('tools-')).length + 1
503
- data.steps.push({
504
- id: `tools-${toolsStepId.toString()}`,
505
- type: 'step',
506
- status: 'running',
507
- attempts: [{ tools: [] }],
508
- } as StepChatStep)
509
- }
510
-
511
- if (info.type === 'tool_calls' && info.action === 'end') {
512
- const lastStep = findLast(data.steps, s => s.id === 'tools' || s.id.startsWith('tools-')) as StepChatStep
513
- if (lastStep) {
514
- lastStep.status = 'success'
515
- lastStep.duration = info.duration
516
- const lastAttemptOfLastTool = last(lastStep.attempts.map(a => a.tools).flat())
517
- lastStep.output = lastAttemptOfLastTool?.output
518
- }
519
- }
520
-
521
- if (info.type === 'tool' && info.action === 'awaiting_approval') {
522
- const tool = tools.find(({ id }) => id === info.data?.tool_id)
523
- data.steps.push({
524
- id: info.id,
525
- type: 'tool',
526
- status: 'awaiting_approval',
527
- duration: info.duration || 0,
528
- input: info.data?.input,
529
- user_question: info.data?.user_question,
530
- attempts: [{
531
- tools: [{
532
- executionId: info.id,
533
- id: info.data?.tool_id ?? '',
534
- name: tool?.name ?? '',
535
- goal: tool?.goal,
536
- ...tool,
537
- }],
538
- }],
539
- })
540
- data.steps.push({ id: 'answer', type: 'answer', status: 'pending' })
541
- }
542
-
543
- if (info.type === 'tool' && info.action === 'start') {
544
- if (!info.data) return
545
- const input = formatJson(info.data.input)
546
- const tool = findLast(tools, ({ id }) => id === info.data?.tool_id) ?? { id: info.data?.tool_id, name: info.data?.tool_id }
547
-
548
- const currentStep = findLast(data.steps, s => s.status === 'running') as StepChatStep
549
-
550
- //There might be a tool with status awaiting_approval, so we want to inform tool has already started
551
- if (!currentStep || !currentStep?.attempts?.[0]?.tools) {
552
- data.steps.push({
553
- id: info.id,
554
- type: 'tool',
555
- status: 'running',
556
- duration: info.duration || 0,
557
- input: info.data?.input,
558
- user_question: info.data?.user_question,
559
- attempts: [{
560
- tools: [{ ...tool, executionId: info.id, input }],
561
- }],
562
- })
563
- } else {
564
- const toolInFirstAttempt = findLast(currentStep?.attempts?.[0]?.tools, t => t.executionId === info.id)
565
- //One step might have multiple tools. When in an approval mode, we might not have all the tools in the array yet.
566
- //For dynamic tools (id === 'dynamic'), we always push a new tool, since dynamic executions can trigger
567
- //multiple tool runs in the same step and do not follow the planned tool structure.
568
- //So we make sure to add any tools that are not in there, or always add for dynamic tools.
569
- if (!toolInFirstAttempt || isDynamicTool(info)) {
570
- currentStep.attempts?.[0].tools?.push({
571
- ...tool,
572
- executionId: info.id,
573
- input,
574
- status: 'running',
575
- })
576
- } else {
577
- const input = formatJson(info.data.input)
578
- if (info.data.attempt === 1) {
579
- toolInFirstAttempt.input = input
580
- } else {
581
- currentStep.attempts[info.data.attempt - 1] ??= { tools: [] }
582
- currentStep.attempts[info.data.attempt - 1].tools?.push({
583
- ...tool,
584
- executionId: info.id,
585
- input,
586
- })
587
- }
588
- }
589
- }
590
- }
591
-
592
- if (info.type === 'tool' && info.action === 'end') {
593
- const currentStep = data.steps.find(s => s.status === 'running') as StepChatStep
594
- if (!currentStep || !info.data) return
595
-
596
- // attempt index for tool execution starts at 0 for dynamically executed tools,while for planned tools it starts at 1
597
- const attempt = isDynamicTool(info) ? info.data.attempt : info.data.attempt - 1
598
- const tool = last(currentStep?.attempts?.[attempt]?.tools)
599
- if (tool) {
600
- tool.output = formatJson(info.data.output)
601
- tool.duration = info.duration
602
- tool.status = 'success'
603
- }
604
- }
605
-
606
- if (info.type === 'final_answer' && info.action === 'start') {
607
- const answerStep = last(data.steps)
608
- if (answerStep) answerStep.status = 'running'
609
- }
610
-
611
-
612
- if (info.type === 'chat' && info.action === 'end') {
613
- const lastStep = last(data.steps)
614
- if (lastStep?.type === 'answer') {
615
- lastStep.status = 'success'
616
- lastStep.duration = info.duration
617
- } else {
618
- data.steps.push({ id: 'answer', type: 'answer', status: 'success' })
619
- }
620
- }
621
- }
622
-
623
- return new StreamedJson({
624
- eventsPromise: events,
625
- abortController,
626
- minChangeIntervalMS,
627
- ignoreKeys: ['agent_info'],
628
- transform,
629
- textFromErrorEvent: data => data.answer ?? 'Unknown error',
630
- })
631
- }
632
-
633
369
  contentDependencies = this.query(removeAuthorizationParam(
634
370
  getContentDependenciesV1ContentContentTypeContentIdDependenciesGet as ReplaceResult<
635
371
  typeof getContentDependenciesV1ContentContentTypeContentIdDependenciesGet,
@@ -1,17 +1,26 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
2
  import { findLast, last } from 'lodash'
3
3
  import { getApiAddresses } from '../api-addresses'
4
- import { ConversationResponse } from '../api/ai'
5
- import { create, create1, create2, defaults, deleteById, deleteById1, deleteById2, fetchInsights, getAll, getAll1, getAll2, getAllByHypothesis, getById, getById1, getById2, getInsightById, GetOpportunityResponse, AiChatRequest, refreshInsights } from '../api/discover'
4
+ import { ChatResponse3, ConversationResponse } from '../api/ai'
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
+ import { baseDictionary } from '../error/dictionary/base'
7
8
  import { StackspotAPIError } from '../error/StackspotAPIError'
9
+ import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
8
10
  import { StreamedJson } from '../utils/StreamedJson'
9
- import { baseDictionary } from '../error/dictionary/base'
10
11
  import { formatJson } from '../utils/string'
11
- import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
12
- import { aiClient } from './ai'
13
- import { ChatAgentTool, ChatResponseWithSteps, FixedChatResponse, StepChatStep } from './types'
14
12
  import { agentToolsClient } from './agent-tools'
13
+ import { aiClient } from './ai'
14
+ import { AgentInfo, ChatAgentTool, ChatStep, StepChatStep } from './types'
15
+
16
+ export interface FixedDiscoveryChatResponse extends ChatResponse3 {
17
+ agent_info: AgentInfo,
18
+ tools?: string[],
19
+ }
20
+
21
+ export interface DiscoveryChatResponseWithSteps extends FixedDiscoveryChatResponse {
22
+ steps: ChatStep[],
23
+ }
15
24
 
16
25
  export interface ChatConversionDetails extends ConversationResponse {
17
26
  opportunityName?: string,
@@ -121,7 +130,8 @@ class DiscoverClient extends ReactQueryNetworkClient {
121
130
  }
122
131
 
123
132
 
124
- sendChatMessage(request: AiChatRequest & { agentId: string }, minChangeIntervalMS?: number): StreamedJson<ChatResponseWithSteps> {
133
+ sendChatMessage(request: AiChatRequest & { agentId: string }, minChangeIntervalMS?: number)
134
+ : StreamedJson<DiscoveryChatResponseWithSteps> {
125
135
  const abortController = new AbortController()
126
136
  const headers = {
127
137
  'Content-Type': 'application/json',
@@ -136,7 +146,7 @@ class DiscoverClient extends ReactQueryNetworkClient {
136
146
  * normal streamings of data, we need this separate function to deal with them. It transforms the internal data model of the
137
147
  * StreamedJson object whenever an event is triggered.
138
148
  */
139
- async function transform(event: Partial<FixedChatResponse>, data: Partial<ChatResponseWithSteps>) {
149
+ async function transform(event: Partial<FixedDiscoveryChatResponse>, data: Partial<DiscoveryChatResponseWithSteps>) {
140
150
  const info = event.agent_info
141
151
 
142
152
  if (!info) return