1- import { AxiosInstance } from "axios" ;
21import { RoomsSocket , RoomsSocketConfig } from "../utils/socket-utils" ;
32import { createAxiosClient } from "../utils/axios-client" ;
3+ import { AgentConversation , AgentMessage } from "./agents.types" ;
44
55export type AgentsModuleConfig = {
66 serverUrl : string ;
@@ -10,11 +10,11 @@ export type AgentsModuleConfig = {
1010
1111export function createAgentsModule ( {
1212 appId,
13- serverUrl,
14- token,
13+ serverUrl,
14+ token,
1515} : AgentsModuleConfig ) {
1616 let currentConversation : any = null ;
17- const socketConfig : RoomsSocketConfig = {
17+ const socketConfig : RoomsSocketConfig = {
1818 serverUrl,
1919 mountPath : "/ws-user-apps/socket.io/" ,
2020 transports : [ "websocket" ] ,
@@ -24,18 +24,18 @@ export function createAgentsModule({
2424 } ,
2525 } ;
2626
27- const axiosConfig : AgentsModuleConfig = {
28- serverUrl,
29- appId,
30- token,
31- } ;
27+ const axiosConfig : AgentsModuleConfig = {
28+ serverUrl,
29+ appId,
30+ token,
31+ } ;
32+
33+ let axios = createAgentsAxiosClient ( {
34+ serverUrl,
35+ appId,
36+ token,
37+ } ) ;
3238
33- let axios = createAgentsAxiosClient ( {
34- serverUrl,
35- appId,
36- token,
37- } ) ;
38-
3939 const roomSocket = RoomsSocket ( {
4040 config : socketConfig ,
4141 } ) ;
@@ -46,19 +46,23 @@ export function createAgentsModule({
4646 } ;
4747
4848 const getConversations = ( ) => {
49- return axios . get ( `/conversations` ) ;
49+ return axios . get < any , AgentConversation [ ] > ( `/conversations` ) ;
5050 } ;
5151
5252 const getConversation = ( conversationId : string ) => {
53- return axios . get ( `/conversations/${ conversationId } ` ) ;
53+ return axios . get < any , AgentConversation | undefined > (
54+ `/conversations/${ conversationId } `
55+ ) ;
5456 } ;
5557
5658 const listConversations = ( filterParams : any ) => {
57- return axios . get ( `/conversations` , { params : filterParams } ) ;
59+ return axios . get < any , AgentConversation [ ] > ( `/conversations` , {
60+ params : filterParams ,
61+ } ) ;
5862 } ;
5963
6064 const createConversation = ( conversation : any ) => {
61- return axios . post ( `/conversations` , conversation ) ;
65+ return axios . post < any , AgentConversation > ( `/conversations` , conversation ) ;
6266 } ;
6367
6468 const addMessage = ( conversation : any , message : any ) => {
@@ -75,7 +79,10 @@ export function createAgentsModule({
7579 room : `/agent-conversations/${ conversation . id } ` ,
7680 data : JSON . stringify ( conversation ) ,
7781 } ) ;
78- return axios . post ( `/conversations/${ conversation . id } /messages` , message ) ;
82+ return axios . post < any , AgentMessage > (
83+ `/conversations/${ conversation . id } /messages` ,
84+ message
85+ ) ;
7986 } ;
8087
8188 const subscribeToConversation = ( conversationId : string , onUpdate : any ) => {
@@ -115,8 +122,8 @@ function createAgentsAxiosClient({
115122 appId,
116123 serverUrl,
117124 token,
118- interceptResponses : false ,
119- headers : {
125+ interceptResponses : true ,
126+ headers : {
120127 "X-App-Id" : String ( appId ) ,
121128 } ,
122129 } ) ;
0 commit comments